您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

fieldEditor.vue 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div>
  3. <div v-if="!edit" class="input-group-prepend">
  4. <input class="form-control" v-model="myDisplay" disabled />
  5. <span
  6. v-if="mayEdit"
  7. @click="EditClick()"
  8. class="input-group-text spanCursor"
  9. style="color: #60CBEB"
  10. >
  11. <eva-icon name="edit-outline" fill="#60CBEB"></eva-icon>
  12. </span>
  13. </div>
  14. <div v-if="edit" class="input-group-prepend">
  15. <input v-if="type === 'text'" class="form-control" v-model="value" />
  16. <input v-if="type === 'number'" type="number" class="form-control" v-model="value" />
  17. <input v-if="type === 'date'" type="date" class="form-control" v-model="value" />
  18. <select v-if="type === 'select'" class="form-control" @change="selectionClick">
  19. <option>Please select</option>
  20. <option
  21. v-for="option in selectOptions"
  22. :value="option[selectValue]"
  23. :key="option[selectValue]"
  24. >{{ option[selectText] }}</option>
  25. </select>
  26. <select v-if="type === 'selectlist'" class="form-control" v-model="value">
  27. <option v-for="item in selectOptions" :value="item" :key="item">{{ item }}</option>
  28. </select>
  29. <!-- <Datetime class="form-control" v-if="type === 'datetime'" v-model="value" /> -->
  30. <span
  31. v-if="edit"
  32. @click="UpdateValue()"
  33. class="input-group-text spanCursor"
  34. style="color: #60CBEB"
  35. >
  36. <eva-icon name="checkmark-outline" fill="#60CBEB"></eva-icon>
  37. </span>
  38. <span v-if="edit" @click="Close()" class="input-group-text spanCursor" style="color: #60CBEB">
  39. <eva-icon name="close-outline" fill="#60CBEB"></eva-icon>
  40. </span>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. export default {
  46. props: [
  47. 'value',
  48. 'type',
  49. 'mayEdit',
  50. 'selectOptions',
  51. 'selectValue',
  52. 'selectText',
  53. 'display',
  54. ],
  55. data() {
  56. return {
  57. edit: false,
  58. myDisplay: '',
  59. };
  60. },
  61. methods: {
  62. UpdateValue() {
  63. this.edit = false;
  64. if (this.type !== 'select' && this.value) {
  65. this.$emit('input', this.value);
  66. this.$emit('change', this.value);
  67. }
  68. },
  69. EditClick() {
  70. this.edit = true;
  71. },
  72. Close() {
  73. this.edit = false;
  74. },
  75. selectionClick(item) {
  76. if (item.target.options.selectedIndex > 0) {
  77. if (!this.value) {
  78. this.myDisplay = this.selectOptions[
  79. item.target.options.selectedIndex - 1
  80. ][this.selectText];
  81. }
  82. if (this.selectOptions[item.target.options.selectedIndex - 1]) {
  83. this.$emit(
  84. 'input',
  85. this.selectOptions[item.target.options.selectedIndex - 1],
  86. );
  87. this.$emit(
  88. 'change',
  89. this.selectOptions[item.target.options.selectedIndex - 1],
  90. );
  91. }
  92. }
  93. },
  94. },
  95. mounted() {
  96. if (this.value) {
  97. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  98. this.myDisplay = this.value;
  99. }
  100. if (this.value && this.selectText) {
  101. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  102. this.myDisplay = this.value[this.selectText];
  103. }
  104. if (this.display) {
  105. this.myDisplay = this.display;
  106. }
  107. if (this.type === 'date') {
  108. this.myDisplay = this.$options.filters.toDate(this.value);
  109. }
  110. },
  111. computed: {
  112. // eslint-disable-next-line vue/return-in-computed-property
  113. checkValue() {
  114. if (this.value) {
  115. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  116. this.myDisplay = this.value;
  117. }
  118. if (this.value && this.selectText) {
  119. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  120. this.myDisplay = this.value[this.selectText];
  121. }
  122. if (this.display) {
  123. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  124. this.myDisplay = this.display;
  125. }
  126. },
  127. },
  128. watch: {
  129. checkValue() {
  130. return null;
  131. },
  132. },
  133. };
  134. </script>