diy-tabs.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template id="diy-tabs">
  2. <diy-style-contain :title="title">
  3. <div class="tabs-radios">
  4. <el-radio-group flex v-model="radioType" border @change="radioChange($event)">
  5. <el-radio-button flex="cross:center" class="radio-btn" flex v-for="(item, index) in list" :key="index" :label="item.value">
  6. <span v-if="radio_text == 'text'">{{ item[name] }}</span>
  7. <el-image :style="imgStyle" v-else-if="radio_text == 'image'" class="tabs-img" :src="item[name]"></el-image>
  8. <slot v-else name="icons" :item="item"></slot>
  9. </el-radio-button>
  10. </el-radio-group>
  11. <div class="tabs-stroke" flex="cross:center" v-if="item.is_show">
  12. <span class="storke-title">描边颜色</span>
  13. <div class="storke-picker" flex="cross:center">
  14. <el-color-picker flex="cross:center" v-model="item.color" @change="colorChange" :show-alpha="showAlpha"></el-color-picker>
  15. <el-input class="storke-ipt" size="mini" v-model="item.color" placeholder="选择颜色" @focus="iptSelect($event)"></el-input>
  16. </div>
  17. </div>
  18. </div>
  19. </diy-style-contain>
  20. </template>
  21. <script>
  22. /**
  23. * 样式tab
  24. */
  25. Vue.component('diy-tabs', {
  26. name: "diy-tabs",
  27. props: {
  28. title: { // 头部标题
  29. type: String,
  30. default: '样式'
  31. },
  32. radio_text: { // text: 文字,image: 图片
  33. type: String,
  34. default: ''
  35. },
  36. name: { // 用来替换list的label属性
  37. type: String,
  38. default: 'label'
  39. },
  40. list: { // tabs数组
  41. type: Array,
  42. default: () => {
  43. return [{
  44. label: '默认',
  45. value: 'default',
  46. is_show: false,
  47. color: '#DDDDDD'
  48. },
  49. {
  50. label: '投影',
  51. value: 'shandow',
  52. is_show: false,
  53. color: '#DDDDDD'
  54. },
  55. {
  56. label: '描边',
  57. value: 'border',
  58. is_show: true,
  59. color: '#DDDDDD'
  60. },
  61. ]
  62. }
  63. },
  64. default_item: {
  65. type: Object,
  66. default: () => null
  67. },
  68. showAlpha: {
  69. type: Boolean,
  70. default: false
  71. },
  72. imgStyle: {
  73. type: Object,
  74. default: () => {}
  75. }
  76. },
  77. template: '#diy-tabs',
  78. data() {
  79. return {
  80. radioType: '',
  81. radio_index: 0,
  82. item:{}
  83. }
  84. },
  85. watch: {
  86. },
  87. mounted() {
  88. this.tabInit()
  89. },
  90. methods: {
  91. tabInit() {
  92. if (this.default_item) {
  93. this.item = this.default_item
  94. } else {
  95. this.item = this.list[0]
  96. }
  97. this.radioType = this.item.value
  98. },
  99. onChange(data){
  100. this.$emit('change', data)
  101. },
  102. radioChange(e) { // 切换
  103. let index = this.list.findIndex(it => it.value == e)
  104. this.radioType = e
  105. this.item = this.list[index]
  106. this.onChange({
  107. item: this.item,
  108. index
  109. })
  110. },
  111. colorChange(e) {
  112. let index = this.list.findIndex(it => it.value == this.item.value)
  113. this.onChange({
  114. item: this.item,
  115. index
  116. })
  117. },
  118. iptSelect(e) {
  119. e.currentTarget.select();
  120. }
  121. }
  122. });
  123. </script>
  124. <style>
  125. .tabs-title {
  126. color: var(--textGray, #999999);
  127. padding-bottom: 20px;
  128. font-size: 14px;
  129. font-weight: 700;
  130. }
  131. .tabs-radios .radio-btn {
  132. flex: 1;
  133. }
  134. .tabs-radios .radio-btn .el-radio-button__inner {
  135. display: block;
  136. flex: 1;
  137. }
  138. .tabs-radios .el-radio-button__orig-radio:checked+.el-radio-button__inner {
  139. background-color: transparent;
  140. color: var(--diy-theme);
  141. }
  142. .tabs-img {
  143. width: 30px;
  144. height: 25px;
  145. }
  146. /* 描边颜色 */
  147. .tabs-stroke {
  148. height: 54px;
  149. border: 1px solid rgba(112, 112, 112, 0.2);
  150. padding: 0 10px;
  151. margin-top: 10px;
  152. }
  153. .storke-title {
  154. font-size: 14px;
  155. color: var(--textGray, #999999);
  156. font-weight: 700;
  157. padding-right: 27px;
  158. }
  159. .storke-picker .el-color-picker__trigger {
  160. width: 64px;
  161. height: 30px;
  162. }
  163. .storke-picker .el-color-picker__icon,
  164. .storke-picker .el-color-picker__empty {
  165. display: none;
  166. }
  167. .storke-ipt {
  168. width: 90px;
  169. margin-left: 100px;
  170. }
  171. .storke-picker .el-input__inner {
  172. color: var(--textGray, #999999);
  173. }
  174. </style>