input.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div class="oInput controller" :class="[preview ? '' : 'o-unit']" v-if="widget.type == 'input'">
  3. <van-field
  4. :name="widget.model"
  5. v-model="dataModel"
  6. :label="widget.name || '文本框'"
  7. :type="inputType"
  8. :required="fileCheck ? false : options.required || false"
  9. :disabled="options.disabled || false"
  10. clearable
  11. :placeholder="options.placeholder || '请输入'"
  12. autocomplete="off"
  13. :rules="rule"
  14. v-if="!preview"
  15. />
  16. <van-cell class="preview" :title="widget.name || '文本框'" :value="dataModel" v-else></van-cell>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'oInput',
  22. props: ['widget', 'preview', 'value', 'fileCheck'],
  23. data() {
  24. return {
  25. dataModel: this.widget.options?.defaultValue || null,
  26. inputType: null
  27. }
  28. },
  29. mounted() {
  30. // 初始化参数
  31. let type = null
  32. if(this.options.dataType === 'integer') {
  33. type = 'digit'
  34. } else if(this.options.dataType === 'float' || this.options.dataType.number) {
  35. type = 'number'
  36. }
  37. this.inputType = type
  38. if(this.value) {
  39. const widget = this.widget
  40. const model = widget.originModel || widget.model
  41. for(let v in this.value) {
  42. if(v == model) {
  43. this.dataModel = this.value[v]
  44. }
  45. }
  46. }
  47. },
  48. methods: {
  49. },
  50. computed: {
  51. options() {
  52. return this.widget.options || {}
  53. },
  54. rule() {
  55. let rules = this.widget.rules || []
  56. if(rules && rules.length > 0) {
  57. rules.forEach(item => {
  58. if(item.pattern) {
  59. item.pattern = eval(item.pattern)
  60. }
  61. // 判断是否上传文件
  62. if(this.fileCheck) {
  63. item.required = false
  64. }
  65. });
  66. }
  67. return rules
  68. }
  69. },
  70. watch: {
  71. // dataModel: {
  72. // deep: true,
  73. // handler(newValue) {
  74. // if (newValue !== undefined && newValue !== null) {
  75. // }
  76. // }
  77. // },
  78. }
  79. }
  80. </script>
  81. <style lang='less' scoped>
  82. @import url('./controlCommon.less');
  83. </style>