index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div class="option-change-container">
  3. <a-row v-if="type === 'option' || type === 'tab'" :gutter="8">
  4. <div class="option-change-box" v-for="(val, index) in value" :key="index">
  5. <a-col :span="9"
  6. ><a-input v-model="val.label" placeholder="名称"
  7. /></a-col>
  8. <a-col :span="9"><a-input v-model="val.value" placeholder="值"/></a-col>
  9. <a-col :span="6"
  10. ><div @click="handleDelete(index)" class="option-delete-box">
  11. <a-icon type="delete" /></div
  12. ></a-col>
  13. </div>
  14. <a-col :span="24"><a @click="handleAdd">添加</a></a-col>
  15. </a-row>
  16. <a-row v-if="type === 'rules'" :gutter="8">
  17. <span v-for="(val, index) in value" :key="index">
  18. <div class="option-change-box" v-if="index !== 0">
  19. <a-col :span="18"
  20. ><a-input v-model="val.message" placeholder="提示信息"
  21. /></a-col>
  22. <a-col :span="18"
  23. ><a-input v-model="val.pattern" placeholder="正则表达式pattern"
  24. /></a-col>
  25. <a-col :span="6"
  26. ><div @click="handleDelete(index)" class="option-delete-box">
  27. <a-icon type="delete" /></div
  28. ></a-col>
  29. </div>
  30. </span>
  31. <a-col :span="24"><a @click="handleAddRules">增加校验</a></a-col>
  32. </a-row>
  33. <a-row v-else-if="type === 'colspan'" :gutter="8">
  34. <div class="option-change-box" v-for="(val, index) in value" :key="index">
  35. <a-col :span="18"
  36. ><a-input-number
  37. style="width:100%"
  38. :max="24"
  39. v-model="val.span"
  40. placeholder="名称"
  41. /></a-col>
  42. <a-col :span="6"
  43. ><div @click="handleDelete(index)" class="option-delete-box">
  44. <a-icon type="delete" /></div
  45. ></a-col>
  46. </div>
  47. <a-col :span="24"><a @click="handleAddCol">添加</a></a-col>
  48. </a-row>
  49. </div>
  50. </template>
  51. <script>
  52. /*
  53. * author kcz
  54. * date 2019-11-20
  55. * description 修改多选、下拉、单选等控件options的组件,添加移除校验规制的组件
  56. */
  57. export default {
  58. name: "KChangeOption",
  59. props: {
  60. value: {
  61. type: Array,
  62. required: true
  63. },
  64. type: {
  65. type: String,
  66. default: "option"
  67. }
  68. },
  69. methods: {
  70. handleAdd() {
  71. // 添加
  72. const addData = [
  73. ...this.value,
  74. {
  75. value: `${this.value.length + 1}`,
  76. label: "选项" + (this.value.length + 1),
  77. list: this.type === "tab" ? [] : undefined
  78. }
  79. ];
  80. this.$emit("input", addData);
  81. },
  82. handleAddCol() {
  83. // 添加栅格Col
  84. const addData = [
  85. ...this.value,
  86. {
  87. span: 12,
  88. list: []
  89. }
  90. ];
  91. this.$emit("input", addData);
  92. },
  93. handleAddRules() {
  94. const addData = [
  95. ...this.value,
  96. {
  97. pattern: "",
  98. message: ""
  99. }
  100. ];
  101. this.$emit("input", addData);
  102. },
  103. handleDelete(deleteIndex) {
  104. // 删除
  105. this.$emit(
  106. "input",
  107. this.value.filter((val, index) => index !== deleteIndex)
  108. );
  109. }
  110. }
  111. };
  112. </script>
  113. <style lang="less" scoped>
  114. .option-change-container {
  115. width: calc(100% - 8px);
  116. }
  117. .option-change-box {
  118. height: 38px;
  119. padding-bottom: 6px;
  120. .option-delete-box {
  121. margin-top: 3px;
  122. background: #ffe9e9;
  123. color: #f22;
  124. width: 32px;
  125. height: 32px;
  126. line-height: 32px;
  127. text-align: center;
  128. border-radius: 50%;
  129. overflow: hidden;
  130. transition: all 0.3s;
  131. &:hover {
  132. background: #f22;
  133. color: #fff;
  134. }
  135. }
  136. }
  137. </style>