preview.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template id="button-group-preview">
  2. <div class="diy-button-group" :style="{background: computedStyle.searchBox}">
  3. <div class="diy-button-boxs" :style="{...inputStyle}">
  4. <!-- 按钮位置 -->
  5. <div flex="cross:center" :class="'diy-button-' + pattern">
  6. <div class="btn-group-list"
  7. :class="'col-' + (btn_data.buttonData && btn_data.buttonData.single_line)"
  8. flex="dir:top main:center cross:center"
  9. v-for="(item, index) in (pattern == 'swiper' ? swiperList : iconList)" :key="index"
  10. >
  11. <div class="btn-group-image"
  12. flex="main:center cross:center"
  13. :style="{borderRadius: borderRadius, backgroundImage: 'url('+ (item.img || default_bg) +')'}"
  14. v-if="btn_data.buttonData && btn_data.buttonData.style != 3"
  15. >
  16. <!-- 展示图标 btn_data.buttonData && btn_data.buttonData.type == 1 ? 'url('+ (item.img || default_bg) +')' : '' -->
  17. <!-- <i v-if="btn_data.buttonData && btn_data.buttonData.type == 2" class="iconfont btn-icon-type" :class="item.icon"></i> -->
  18. </div>
  19. <div class="btn-group-text"
  20. v-if="btn_data.buttonData && btn_data.buttonData.style != 2"
  21. :style="{color: computedStyle.textStyle}"
  22. >{{ item.btnText }}</div>
  23. <div class="btn-group-tags"
  24. v-if="is_show_tags && item.is_show_tag"
  25. :style="{background: item.tagsBgColor, color: item.tagsTextColor}"
  26. >{{ item.tags }}</div>
  27. </div>
  28. </div>
  29. <!-- 左右箭头 -->
  30. <!-- :class="{'showArrow': is_show_arrow}" -->
  31. <div class="swiper-arrow left" @click.stop="toggleHandle('left')" v-if="pattern == 'swiper'">
  32. <i class="el-icon-arrow-left"></i>
  33. </div>
  34. <div class="swiper-arrow right" @click.stop="toggleHandle('right')" v-if="pattern == 'swiper'">
  35. <i class="el-icon-arrow-right"></i>
  36. </div>
  37. <!-- 轮播点 -->
  38. <div class="swiper-dots" v-if="pattern == 'swiper'">
  39. <div class="dot-item" v-for="(it, i) in list" :class="i == current ? 'active' : ''" @click.stop="dotClick(i)"></div>
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. /**
  46. * @descriptions
  47. * 1. 组件名字必须对应模板形式 - 递归组件name
  48. * 2. 样式内容方法尽量内部维护 - 前端方便通用
  49. * 3. 父级组件会传预览数据 - activeItem
  50. */
  51. Vue.component('button-group-preview', {
  52. name: "button-group-preview",
  53. props: {
  54. activeItem: {
  55. type: Object,
  56. default () {
  57. return {}
  58. }
  59. }
  60. },
  61. template: '#button-group-preview',
  62. computed: {
  63. btn_data() {
  64. return this.activeItem.data
  65. },
  66. computedStyle() {
  67. return this.activeItem.computedStyle
  68. },
  69. borderRadius() {
  70. let data = this.btn_data.buttonData.shape
  71. return data == 'square' ? '0px' : data == 'round' ? '8px' : '50%'
  72. },
  73. inputStyle() {
  74. let tabItem = this.computedStyle.tabItem
  75. let style = {
  76. 'background': this.computedStyle.iptBg,
  77. ...this.activeItem.computedStyle.searchIpts
  78. }
  79. if (tabItem && tabItem.value == 'border') style.border = '1px solid ' + (tabItem ? tabItem.color : 'transparent')
  80. if (tabItem && tabItem.value == 'shandow') style.boxShadow = tabItem ? '0 0 10px ' + tabItem.color : '0 0 10px rgba(226, 231, 244, 0.7)'
  81. return style
  82. },
  83. is_show_tags() {
  84. return this.btn_data.buttonData && (this.btn_data.buttonData.style != 3 && this.btn_data.buttonData.type == 1)
  85. },
  86. pattern() {
  87. return this.btn_data.buttonData && this.btn_data.buttonData.pattern
  88. }
  89. },
  90. watch: {
  91. activeItem: {
  92. deep:true,
  93. immediate: true,
  94. handler(val) {
  95. let pattern = val.data.buttonData && val.data.buttonData.pattern
  96. this.iconList = val.data.iconList
  97. if (pattern == 'swiper') {
  98. this.toggleHandle()
  99. }
  100. }
  101. }
  102. },
  103. data() {
  104. return {
  105. default_bg: 'resources/img/decorate/default_picture.png',
  106. iconList: [],
  107. swiperList: [],
  108. current: 0,
  109. list: [],
  110. }
  111. },
  112. mounted() {
  113. },
  114. methods: {
  115. toggleHandle(name) {
  116. let n = this.current
  117. // 每页行数
  118. let line_num = this.btn_data.buttonData && this.btn_data.buttonData.line_num
  119. // 单行数量
  120. let single_line = this.btn_data.buttonData && this.btn_data.buttonData.single_line
  121. this.list = this.swiperHandle(line_num, single_line)
  122. let arr = []
  123. if (name == 'right' && n < this.list.length - 1) {
  124. n++
  125. } else if (name == 'left' && n > 0) {
  126. n--
  127. }
  128. this.current = n
  129. this.swiperList = this.iconList.slice(single_line * line_num * n, single_line* line_num * (n + 1))
  130. },
  131. dotClick(i) {
  132. this.current = i
  133. this.toggleHandle()
  134. },
  135. swiperHandle(line_num, single_line) {
  136. const arr = deepClone(this.iconList)
  137. let len = Math.ceil((arr && arr.length) / (line_num * single_line))
  138. let newArr = []
  139. for(var i = 0; i < len; i++) {
  140. newArr[i] = arr.splice(0, line_num * single_line)
  141. }
  142. return newArr
  143. },
  144. }
  145. });
  146. </script>
  147. <style>
  148. .diy-button-group {
  149. position: relative;
  150. overflow: hidden;
  151. }
  152. .diy-button-boxs {
  153. position: relative;
  154. padding: 4px 0;
  155. overflow: hidden;
  156. }
  157. .diy-button-scroll {
  158. overflow-x: auto;
  159. width: 100%;
  160. box-sizing: border-box;
  161. padding: 0 8px;
  162. }
  163. .diy-button-scroll::-webkit-scrollbar {
  164. height: 5px;
  165. }
  166. .diy-button-fixed {
  167. flex-wrap: wrap;
  168. }
  169. .diy-button-swiper {
  170. overflow: hidden;
  171. padding-bottom: 20px;
  172. flex-wrap: wrap;
  173. }
  174. .btn-group-list {
  175. position: relative;
  176. padding: 8px 0;
  177. flex-shrink: 0;
  178. }
  179. .btn-group-tags {
  180. position: absolute;
  181. top: -7px;
  182. left: 50%;
  183. width: 53px;
  184. height: 26px;
  185. transform: scale(.5);
  186. color: #fff;
  187. margin-left: -6px;
  188. background: #f83287;
  189. border-radius: 12px 12px 12px 0;
  190. border: 1px solid #fff;
  191. text-align: center;
  192. font-size: 14px;
  193. }
  194. .btn-group-image {
  195. width: 44px;
  196. height: 44px;
  197. background-size: cover;
  198. background-repeat: no-repeat;
  199. background-position: 50%;
  200. }
  201. .btn-group-text {
  202. font-size: 12px;
  203. margin-top: 4px;
  204. }
  205. .col-3 {
  206. width: 33.3%;
  207. }
  208. .col-4 {
  209. width: 25%;
  210. }
  211. .col-5 {
  212. width: 20%;
  213. }
  214. .diy-button-scroll .col-3 {
  215. width: 30%;
  216. }
  217. .diy-button-scroll .col-4 {
  218. width: 22%;
  219. }
  220. .btn-icon-type {
  221. font-size: 24px;
  222. color: #999;
  223. }
  224. /* 轮播图 */
  225. .swiper-arrow {
  226. position: absolute;
  227. width: 32px;
  228. height: 32px;
  229. border-radius: 50%;
  230. background: rgba(0,0,0,.4);
  231. top: 50%;
  232. z-index: 10;
  233. left: 10px;
  234. text-align: center;
  235. line-height: 32px;
  236. font-size: 20px;
  237. cursor: pointer;
  238. margin-top: -16px;
  239. color: #fff;
  240. display: none;
  241. }
  242. .diy-button-boxs:hover .swiper-arrow {
  243. display: block;
  244. }
  245. .swiper-arrow.right {
  246. left: auto;
  247. right: 10px;
  248. }
  249. .swiper-dots {
  250. position: absolute;
  251. left: 0;
  252. bottom: 0;
  253. right: 0;
  254. height: 30px;
  255. line-height: 30px;
  256. text-align: center;
  257. }
  258. .swiper-dots .dot-item {
  259. display: inline-block;
  260. width: 5px;
  261. height: 5px;
  262. border-radius: 50%;
  263. margin: 0 4px;
  264. background: rgba(0,0,0,.2);
  265. cursor: pointer;
  266. }
  267. .swiper-dots .dot-item.active {
  268. background: #000;
  269. }
  270. </style>