diy-operation-list.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template id="diy-operation-list">
  2. <div>
  3. <div v-for="(item,index) in value" :key="index" class="diy-operation-item">
  4. <!-- 动态插槽 -->
  5. <div :style="gutterStyle">
  6. <div v-if="item.slot">
  7. <slot :name="item.slot" :item="item" :index="index"></slot>
  8. </div>
  9. <!-- 默认类型start -->
  10. <!-- input -->
  11. <div v-else-if="item.type === 'textarea'" class="item-row ">
  12. <div class="diy-operation-name" :style="labelStyle(item)" v-if="item.isShowLabel !== false">{{ item.label }}</div>
  13. <el-input class="flex-1" type="textarea" v-model="item.value" @input="colorInput($event,index)" :placeholder="item.placeholder" :maxlength="item.max" :show-word-limit="item.showLimit"></el-input>
  14. </div>
  15. <!-- input -->
  16. <div v-else-if="item.type === 'input'" class="item-row diy-operation-input">
  17. <div class="diy-operation-name" :style="labelStyle(item)" v-if="item.isShowLabel !== false">{{ item.label }}</div>
  18. <el-input class="diy-input" v-model="item.value" @input="colorInput($event,index)" :placeholder="item.placeholder" :maxlength="item.max" :show-word-limit="item.showLimit"></el-input>
  19. </div>
  20. <!-- color -->
  21. <div v-else-if="item.type === 'color'" class="item-row diy-operation-color">
  22. <div class="diy-operation-name" :style="labelStyle(item)" v-if="item.isShowLabel !== false">{{ item.label }}</div>
  23. <el-color-picker color-format="colorFormat" :show-alpha="item.showAlpha" v-model="item.value" @change="updateColor($event,index)" :predefine="item.predefineColors || []"></el-color-picker>
  24. <el-input class="diy-color-input" v-model="item.value" @input="colorInput($event,index)" maxlength="10"></el-input>
  25. </div>
  26. <!-- 尺寸大小 -->
  27. <div v-else-if="item.type === 'size'" class="item-row diy-operation-size">
  28. <div class="diy-operation-name" :style="labelStyle(item)" v-if="item.isShowLabel !== false">{{ item.label }}</div>
  29. <div style="padding-left: 2px;">
  30. <el-slider :min="getRange(item,'minValue')" :max="getRange(item,'maxValue')" :disabled="item.disabled" v-model="item.value" @change="updateSize"></el-slider>
  31. </div>
  32. <div class="diy-text-btn">{{ getSizeText(item) }}</div>
  33. </div>
  34. <!-- 单选 -->
  35. <div v-else-if="item.type === 'radio'" class="item-row diy-operation-radio">
  36. <div class="diy-operation-name" :style="labelStyle(item)" v-if="item.isShowLabel !== false">{{ item.label }}</div>
  37. <el-radio-group class="flex-1" v-model="item.value" @change="onChange">
  38. <el-radio :label="childItem.label" v-for="(childItem, j) in item.list" :key="j"> {{ childItem.value }}</el-radio>
  39. </el-radio-group>
  40. </div>
  41. <!-- 多选 -->
  42. <div v-else-if="item.type === 'checkbox'" class="item-row diy-operation-checkbox">
  43. <div class="diy-operation-name" :style="labelStyle(item)" v-if="item.isShowLabel !== false">{{ item.label }}</div>
  44. <el-checkbox-group class="flex-1" v-model="item.value" @change="onChange">
  45. <el-checkbox :label="childItem.label" v-for="(childItem, j) in item.list" :key="j"> {{ childItem.value }}</el-checkbox>
  46. </el-checkbox-group>
  47. </div>
  48. <!-- 上传图片 - 只能单个 - 待优化 -->
  49. <div v-else-if="item.type === 'image'" class="diy-operation-image">
  50. <div class="diy-operation-name" :style="labelStyle(item)" v-if="item.isShowLabel !== false">{{ item.label }}</div>
  51. <div>
  52. <com-attachment :multiple="false" :max="1" @selected="selecImg($event, item)">
  53. <div class="card-upload img-upload-bor" :style="videoComputed" v-if="!item.value">
  54. <i class="el-icon-plus icon-plugs-center"></i>
  55. </div>
  56. <div class="diy-sty-img" v-else @mouseover="mouseOverImg(item)" @mouseleave="mouseLeaveImg(item)" :style="videoComputed">
  57. <el-image :style="videoComputed" :src="item.value"></el-image>
  58. <div class="diy-upd-img" v-show="item.showIcon">替换</div>
  59. <i class="el-icon-close diy-upd-icon" @click.stop="delImg(item)" v-show="item.showIcon"></i>
  60. </div>
  61. <slot name="tips"></slot>
  62. </com-attachment>
  63. </div>
  64. </div>
  65. <!-- 默认类型end -->
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. Vue.component('diy-operation-list', {
  72. template: '#diy-operation-list',
  73. name: 'diy-operation-list',
  74. props: {
  75. value: {
  76. type: Array,
  77. default () {
  78. return []
  79. }
  80. },
  81. // 提示文字width
  82. labelWidth: {
  83. type: String | Number,
  84. default () {
  85. return 70
  86. }
  87. },
  88. // 提示文字
  89. labelAlign: {
  90. type: String,
  91. default: 'end'
  92. },
  93. // 总的size最小值
  94. minValue: {
  95. type: String | Number,
  96. default () {
  97. return 0
  98. }
  99. },
  100. // 总的size最大值
  101. maxValue: {
  102. type: String | Number,
  103. default () {
  104. return 100
  105. }
  106. },
  107. gutter: {
  108. type: String | Number,
  109. default () {
  110. return 0
  111. }
  112. },
  113. },
  114. data() {
  115. return {}
  116. },
  117. computed: {
  118. videoComputed() {
  119. return {
  120. width: `60px`,
  121. height: `60px`
  122. }
  123. },
  124. gutterStyle() {
  125. return {
  126. margin: `${this.gutter}px ${0}`
  127. }
  128. }
  129. },
  130. methods: {
  131. onChange() {
  132. this.$nextTick(() => {
  133. var list = deepClone(this.value)
  134. this.$emit("on-change", list);
  135. })
  136. },
  137. // 颜色
  138. updateColor() {
  139. this.onChange()
  140. },
  141. colorInput() {
  142. console.log('颜色',this.value)
  143. this.onChange()
  144. },
  145. // size
  146. getSizeText(item) {
  147. var unit = item.unit ? item.unit : "px";
  148. return `${item.value}${unit}`
  149. },
  150. getRange(item, type) {
  151. if (item[type]) {
  152. return item[type]
  153. } else {
  154. this[type]
  155. }
  156. },
  157. updateSize() {
  158. this.onChange()
  159. },
  160. // 图片
  161. selecImg(event, item) {
  162. item.value = event[0].url
  163. this.onChange()
  164. },
  165. mouseOverImg(item) {
  166. this.$set(item, "showIcon", true)
  167. },
  168. mouseLeaveImg(item) {
  169. this.$set(item, "showIcon", false)
  170. },
  171. delImg(item) {
  172. item.value = "";
  173. this.onChange()
  174. },
  175. // label样式
  176. labelStyle(item) {
  177. var labelWidth = item.labelWidth ? item.labelWidth : this.labelWidth
  178. var labelAlign = item.labelAlign ? item.labelAlign : this.labelAlign
  179. return {
  180. width: `${labelWidth}px`,
  181. 'text-align': labelAlign
  182. }
  183. },
  184. }
  185. });
  186. </script>
  187. <style scoped>
  188. .item-row {
  189. min-height: 40px;
  190. display: flex;
  191. align-items: center;
  192. }
  193. .diy-operation-image {
  194. display: flex;
  195. align-items: center;
  196. }
  197. .diy-operation-input .diy-input {
  198. flex: 1;
  199. height: 30px;
  200. }
  201. .diy-operation-input .el-input__inner {
  202. height: 100%;
  203. }
  204. .flex-1 {
  205. flex: 1;
  206. }
  207. /* .diy-operation-color,
  208. .diy-operation-size,
  209. .diy-operation-radio,
  210. .diy-operation-checkbox {} */
  211. .diy-operation-name {
  212. margin-right: 15px;
  213. text-align: end;
  214. color: #999999;
  215. }
  216. .diy-color-input {
  217. width: 74px;
  218. background: #F4F3F7;
  219. border-radius: 3px;
  220. font-size: 14px;
  221. color: #666666;
  222. text-align: center;
  223. margin-left: 15px;
  224. height: 28px;
  225. }
  226. .diy-color-input .el-input__inner {
  227. height: 100%;
  228. padding: 0 6px;
  229. }
  230. .diy-operation-color .el-color-picker {
  231. height: 30px;
  232. }
  233. .diy-operation-size .el-slider {
  234. width: 153px;
  235. margin-right: 15px;
  236. }
  237. </style>