style.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template id="store-search-style">
  2. <div>
  3. <div>
  4. <diy-tabs title="样式"
  5. radio_text='text'
  6. :default_item="defaultForm.tabItem"
  7. @change="colorSelect"
  8. ></diy-tabs>
  9. <diy-color top-name="选择颜色"
  10. :color-infos="colorInfos"
  11. :str-color="defColor"
  12. @chang="updateColor"
  13. ></diy-color>
  14. <diy-align title="文字位置"
  15. :current="defaultForm.alignCurrent"
  16. @change="updataText"
  17. ></diy-align>
  18. <diy-style-contain title="默认文字">
  19. <div flex="cross:center" class="diy-words color-info">
  20. <div class="diy-name">文字</div>
  21. <el-input style="flex: 1" @input="textChange" type="text" placeholder="请输入内容" v-model="defaultForm.name" maxlength="10" size="small" show-word-limit></el-input>
  22. </div>
  23. <!-- <div flex="cross:center main:center" class="diy-word-tips">*手机端随机显示推荐搜索关键字,<el-link type="primary" :underline="false">去创建</el-link></div>-->
  24. </diy-style-contain>
  25. <diy-size-setting top-name="边距"
  26. :size-infos="sizeInfos"
  27. :max-value="50"
  28. @chang="sliderChange($event, 'margin')"
  29. ></diy-size-setting>
  30. <diy-size-setting top-name="圆角设置"
  31. :size-infos="defaultForm.radiusInfos"
  32. :max-value="20"
  33. @chang="RadiusChange($event, 'radius')"
  34. ></diy-size-setting>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. /**
  40. * @descriptions
  41. * 1. 组件名字必须对应模板形式 - 递归组件name
  42. * 2. 样式内容方法尽量内部维护 - 前端方便通用
  43. * 3. 父级组件会传数据/更新方法 - activeItem/$emit('update')
  44. */
  45. Vue.component('store-search-style', {
  46. name: "store-search-style",
  47. props: {
  48. activeItem: {
  49. type: Object,
  50. default () {
  51. return {}
  52. }
  53. }
  54. },
  55. template: '#store-search-style',
  56. mixins: [basicMixins],
  57. data() {
  58. return {
  59. result: {},
  60. defaultForm: {
  61. defColor: 'transparent',
  62. alignCurrent: 'left', // 文字位置
  63. colorInfos: ['底部背景', '组件背景', '图标颜色', '文字颜色'],
  64. name: '',
  65. },
  66. searchIpts: {},
  67. colorInfos: ['底部背景' ,'组件背景', '图标颜色', '文字颜色'],
  68. defColor: ['', '', '', ''],
  69. sizeInfos: ['上边距', '下边距']
  70. }
  71. },
  72. methods: {
  73. init() { // 设置默认值
  74. basicMixins.methods.init.call(this)
  75. // 文字位置
  76. let textArr = ['computedStyle', 'searchIpts', 'justify-content']
  77. this.defaultForm.alignCurrent = getObjValue(this.result, textArr, this.defaultForm.alignCurrent)
  78. // 文字内容
  79. let textCont = ['data', 'name']
  80. this.defaultForm.name = getObjValue(this.result, textCont, this.defaultForm.name)
  81. },
  82. updateColor(e) { // 选择颜色
  83. this.colorInfos = e;
  84. if(this.result.data.colorInfos){
  85. this.colorInfos = this.result.data.colorInfos;
  86. } else {
  87. this.result.data.colorInfos = this.colorInfos;
  88. }
  89. this.result.computedStyle.searchBox = this.colorInfos[0].color
  90. this.result.computedStyle.iptBg = this.colorInfos[1].color
  91. this.result.computedStyle.iconsStyle = this.colorInfos[2].color
  92. this.result.computedStyle.textStyle = this.colorInfos[3].color
  93. this.$emit("update", this.result)
  94. },
  95. updataText(type) { // 文字位置
  96. const style = {
  97. 'justify-content': type == 'left' ? 'flex-start' : type == 'center' ? 'center' : 'flex-end'
  98. }
  99. this.searchIpts = Object.assign(this.searchIpts, style)
  100. this.updataResult(this.searchIpts, 'searchIpts')
  101. },
  102. textChange(e) { // 文字内容
  103. this.result.data.name = e
  104. this.$emit("update", this.result)
  105. },
  106. sliderChange(arr, type) { // 上下边距
  107. this.sizeInfos = arr
  108. if (this.result.data.sizeInfos && this.result.data.sizeInfos.length) {
  109. this.sizeInfos = this.result.data.sizeInfos
  110. } else {
  111. this.result.data.sizeInfos = this.sizeInfos
  112. }
  113. let top = this.sizeInfos[0] && (this.sizeInfos[0].value + this.sizeInfos[0].unit)
  114. let bottom = this.sizeInfos[1] && (this.sizeInfos[1].value + this.sizeInfos[1].unit)
  115. let lr = this.sizeInfos[2] && (this.sizeInfos[2].value + this.sizeInfos[2].unit)
  116. const style = {
  117. marginTop: top,
  118. marginBottom: bottom,
  119. marginLeft: lr,
  120. marginRight: lr
  121. }
  122. this.searchIpts = Object.assign(this.searchIpts, style)
  123. this.updataResult(this.searchIpts, 'searchIpts')
  124. },
  125. }
  126. });
  127. </script>
  128. <style>
  129. .style-title {
  130. font-weight: 700;
  131. color: var(--textGray, #999);
  132. padding-left: 10px;
  133. }
  134. .top-icons {
  135. width: 32px;
  136. height: 20px;
  137. background: var(--primary, #2D8CF0);
  138. border-radius: 10px;
  139. color: #fff;
  140. }
  141. .diy-word-tips {
  142. font-size: 14px;
  143. color: #999999;
  144. font-weight: 700;
  145. padding-top: 19px;
  146. }
  147. .diy-word-link {
  148. cursor: pointer;
  149. color: var(--primary, #2D8CF0);
  150. }
  151. </style>