rate.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. </div>
  66. </template>
  67. <script>
  68. export default {
  69. name: "config-rate",
  70. props: ['data'],
  71. data() {
  72. return {
  73. textVisible: false,
  74. textValue: '',
  75. colorVisible: false,
  76. colorValue: '',
  77. iconVisible: false,
  78. iconValue: ''
  79. }
  80. },
  81. methods: {
  82. handleTextClose(tag) {
  83. this.data.texts.splice(this.data.texts.indexOf(tag), 1);
  84. },
  85. showTextInput() {
  86. this.textVisible = true;
  87. this.$nextTick(() => {
  88. this.$refs.textTag.$refs.input.focus();
  89. });
  90. },
  91. handleTextConfirm() {
  92. if (this.textValue) this.data.texts.push(this.textValue);
  93. this.textVisible = false;
  94. this.textValue = '';
  95. },
  96. handleColorClose(tag) {
  97. this.data.colors.splice(this.data.colors.indexOf(tag), 1);
  98. },
  99. handleColorConfirm() {
  100. if (this.colorValue) this.data.colors.push(this.colorValue);
  101. this.colorValue = '';
  102. },
  103. // handleIconClose(tag) {
  104. // this.data.iconClasses.splice(this.data.iconClasses.indexOf(tag), 1);
  105. // },
  106. // showIconInput() {
  107. // this.iconVisible = true;
  108. // this.$nextTick(() => {
  109. // this.$refs.iconTag.$refs.input.focus();
  110. // });
  111. // },
  112. // handleIconConfirm() {
  113. // if (this.iconValue) this.data.iconClasses.push(this.iconValue);
  114. // this.iconVisible = false;
  115. // this.iconValue = '';
  116. // }
  117. },
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .el-tag {
  122. vertical-align: top;
  123. }
  124. .el-tag + .el-tag {
  125. margin-left: 5px;
  126. }
  127. .input-new-tag {
  128. width: 90px;
  129. margin-left: 5px;
  130. vertical-align: bottom;
  131. }
  132. .color-picker {
  133. left: 10px;
  134. vertical-align: top;
  135. }
  136. </style>