rate.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div>
  3. <el-form-item label="最大星数">
  4. <el-input-number v-model="data.max"
  5. controls-position="right"
  6. placeholder="最大星数"></el-input-number>
  7. </el-form-item>
  8. <el-form-item label="是否显示文本"
  9. label-width="110px">
  10. <el-switch v-model="data.showText"></el-switch>
  11. </el-form-item>
  12. <el-form-item label="自定义文本"
  13. label-width="110px"
  14. v-if="data.showText">
  15. <el-tag :key="index"
  16. size="small"
  17. v-for="(tag,index) in data.texts"
  18. closable
  19. @close="handleTextClose(tag)">{{tag}}
  20. </el-tag>
  21. <el-input class="input-new-tag"
  22. v-if="textVisible"
  23. v-model="textValue"
  24. size="mini"
  25. ref="textTag"
  26. clearable
  27. @keyup.enter.native="handleTextConfirm"
  28. @blur="handleTextConfirm">
  29. </el-input>
  30. <el-button v-if="!textVisible && data.texts.length < data.max"
  31. @click="showTextInput"
  32. size="mini"
  33. icon="el-icon-plus"
  34. circle
  35. style="margin-left: 5px;"></el-button>
  36. </el-form-item>
  37. <el-form-item label="自定义颜色"
  38. label-width="110px">
  39. <el-tag :key="index"
  40. v-for="(tag,index) in data.colors"
  41. closable
  42. size="small"
  43. @close="handleColorClose(tag)"
  44. :style="{color: tag}">{{tag}}
  45. </el-tag>
  46. <el-color-picker v-model="colorValue"
  47. size="mini"
  48. @change="handleColorConfirm"
  49. class="color-picker"></el-color-picker>
  50. </el-form-item>
  51. <!-- <el-form-item label="自定义图标">-->
  52. <!-- <el-tag :key="index" v-for="(tag,index) in data.iconClasses" closable @close="handleIconClose(tag)">{{tag}}-->
  53. <!-- </el-tag>-->
  54. <!-- <el-input class="input-new-tag"-->
  55. <!-- v-if="iconVisible"-->
  56. <!-- v-model="iconValue"-->
  57. <!-- size="mini"-->
  58. <!-- ref="iconTag"-->
  59. <!-- @keyup.enter.native="handleIconConfirm"-->
  60. <!-- @blur="handleIconConfirm">-->
  61. <!-- </el-input>-->
  62. <!-- <el-button v-else @click="showIconInput" size="mini" icon="el-icon-plus" circle-->
  63. <!-- style="margin-left: 5px;"></el-button>-->
  64. <!-- </el-form-item>-->
  65. <el-form-item label="是否禁用">
  66. <el-switch v-model="data.disabled"></el-switch>
  67. </el-form-item>
  68. <el-form-item label="是否可见">
  69. <el-switch v-model="data.display"></el-switch>
  70. </el-form-item>
  71. <el-form-item label="是否必填">
  72. <el-switch v-model="data.required"></el-switch>
  73. </el-form-item>
  74. </div>
  75. </template>
  76. <script>
  77. export default {
  78. name: "config-rate",
  79. props: ['data'],
  80. data() {
  81. return {
  82. validator: {
  83. type: null,
  84. required: null,
  85. pattern: null,
  86. length: null
  87. },
  88. textVisible: false,
  89. textValue: '',
  90. colorVisible: false,
  91. colorValue: '',
  92. iconVisible: false,
  93. iconValue: ''
  94. }
  95. },
  96. methods: {
  97. generateRule() {
  98. const rules = [];
  99. Object.keys(this.validator).forEach(key => {
  100. if (this.validator[key]) rules.push(this.validator[key])
  101. })
  102. this.data.rules = rules
  103. },
  104. handleTextClose(tag) {
  105. this.data.texts.splice(this.data.texts.indexOf(tag), 1);
  106. },
  107. showTextInput() {
  108. this.textVisible = true;
  109. this.$nextTick(() => {
  110. this.$refs.textTag.$refs.input.focus();
  111. });
  112. },
  113. handleTextConfirm() {
  114. if (this.textValue) this.data.texts.push(this.textValue);
  115. this.textVisible = false;
  116. this.textValue = '';
  117. },
  118. handleColorClose(tag) {
  119. this.data.colors.splice(this.data.colors.indexOf(tag), 1);
  120. },
  121. handleColorConfirm() {
  122. if (this.colorValue) this.data.colors.push(this.colorValue);
  123. this.colorValue = '';
  124. },
  125. // handleIconClose(tag) {
  126. // this.data.iconClasses.splice(this.data.iconClasses.indexOf(tag), 1);
  127. // },
  128. // showIconInput() {
  129. // this.iconVisible = true;
  130. // this.$nextTick(() => {
  131. // this.$refs.iconTag.$refs.input.focus();
  132. // });
  133. // },
  134. // handleIconConfirm() {
  135. // if (this.iconValue) this.data.iconClasses.push(this.iconValue);
  136. // this.iconVisible = false;
  137. // this.iconValue = '';
  138. // }
  139. },
  140. watch: {
  141. 'data.required': function (val) {
  142. if (val) this.validator.required = { required: true, message: `${this.data.label}必须填写` }
  143. else this.validator.required = null
  144. this.generateRule()
  145. },
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .el-tag {
  151. vertical-align: top;
  152. }
  153. .el-tag + .el-tag {
  154. margin-left: 5px;
  155. }
  156. .input-new-tag {
  157. width: 90px;
  158. margin-left: 5px;
  159. vertical-align: bottom;
  160. }
  161. .color-picker {
  162. left: 10px;
  163. vertical-align: top;
  164. }
  165. </style>