diy-size-setting.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template id="diy-size-setting">
  2. <diy-style-contain :title="topName" :show-title="containObj.showTitle">
  3. <div class="color-info" v-for="(item,index) in newsizeInfos" :key="index" v-show="!item.hidden">
  4. <div class="diy-name">{{item.name}}</div>
  5. <div class="sel-size">
  6. <el-slider :min="minValue" :max="item.maxValue" :disabled="item.disabled" v-model="item.value" @change="updateSize"></el-slider>
  7. </div>
  8. <div class="diy-text-btn">{{item.value + item.unit}}</div>
  9. </div>
  10. </diy-style-contain>
  11. </template>
  12. <script>
  13. /**
  14. * 颜色组件
  15. *
  16. */
  17. Vue.component('diy-size-setting', {
  18. template: '#diy-size-setting',
  19. name: 'diy-size-setting',
  20. props: {
  21. containObj: {
  22. type: Object,
  23. default: () => ({
  24. showTitle: true
  25. })
  26. },
  27. topName: { //头部标题
  28. type: String,
  29. default: "大小设置",
  30. },
  31. minValue: { //最小值
  32. type: [String,Number],
  33. default: 0,
  34. },
  35. maxValue: { //最大值
  36. type: [String,Number],
  37. default: 100,
  38. },
  39. defUnit: {
  40. type: String,
  41. default: "px",
  42. },
  43. disabledArr: { //禁用的下标
  44. type: Array,
  45. default: () => []
  46. },
  47. strMaxSizeVal: { //如果sizeInfos刚开始是字符串,可以给改对象添加最大值,优先级比maxValue高
  48. type: Array,
  49. default: () => {
  50. return []
  51. }
  52. },
  53. /**
  54. 值可以是字符串或者对象
  55. 对象格式:{
  56. name: "", //名字
  57. value: 0, //值
  58. unit: "px", //单位
  59. disabled: false,//是否禁用
  60. maxValue: maxValue, //最大值
  61. hidden: false, //是否隐藏
  62. }
  63. 字符串:传个名字
  64. 注:返回出去是一个对象数组
  65. */
  66. sizeInfos: {
  67. type: Array,
  68. default: () => []
  69. },
  70. /**
  71. 给sizeInfos值为字符串添加值
  72. */
  73. sizeInfosValue: {
  74. type: Array,
  75. default: () => []
  76. },
  77. sizeInfosMax: {
  78. type: Array,
  79. default: () => []
  80. }
  81. },
  82. data() {
  83. return {
  84. newsizeInfos: [],
  85. }
  86. },
  87. created() {
  88. },
  89. watch: {
  90. sizeInfos: {
  91. deep:true,
  92. immediate: true,
  93. handler(val) {
  94. let that = this;
  95. this.newsizeInfos = [];
  96. if(this.sizeInfos.length > 0 && typeof this.sizeInfos[0] == 'string'){
  97. that.sizeInfos.forEach((v,index) => {
  98. let boo = that.disabledArr.indexOf(index) != -1?true:false;
  99. let defValue = that.sizeInfosValue.length > 0 && that.sizeInfosValue[index]? that.sizeInfosValue[index]:this.minValue;
  100. let max = that.sizeInfosMax.length > 0 && that.sizeInfosMax[index]? that.sizeInfosMax[index]:that.maxValue;
  101. if(that.strMaxSizeVal.length > 0 && that.strMaxSizeVal[index]){
  102. max = that.strMaxSizeVal[index];
  103. }
  104. let obj = {
  105. name: v,
  106. value: defValue,
  107. unit: that.defUnit,
  108. disabled: boo,
  109. maxValue:max,
  110. hidden: false,
  111. }
  112. that.newsizeInfos.push(obj);
  113. })
  114. this.updateSize();
  115. } else {
  116. this.newsizeInfos = val;
  117. }
  118. }
  119. }
  120. },
  121. methods:{
  122. updateSize(){
  123. this.$emit("chang",this.newsizeInfos);
  124. },
  125. }
  126. });
  127. </script>
  128. <style scoped>
  129. .color-info{
  130. margin-top: 20px;
  131. font-size: 14px;
  132. font-weight: bold;
  133. color: #999999;
  134. display: flex;
  135. align-items: center;
  136. }
  137. .sel-size{
  138. margin-right: 12px;
  139. width: 153px;
  140. height: 30px;
  141. }
  142. .el-color-picker .el-color-picker__trigger{
  143. width: 65px;
  144. height: 30px;
  145. }
  146. .diy-text-btn{
  147. text-align: center;
  148. }
  149. </style>