banner.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <div class="mobile-page" :style="{ marginTop: `${mTOP}px` }">
  3. <div
  4. class="bg"
  5. :style="{
  6. background: `linear-gradient(90deg,${bgColor[0].item} 0%,${bgColor[1].item} 100%)`,
  7. }"
  8. v-if="bgColor.length > 0 && isShow"
  9. ></div>
  10. <div v-if="!isShow" class="bgset"></div>
  11. <div
  12. class="banner"
  13. :style="{
  14. paddingLeft: edge + 'px',
  15. paddingRight: edge + 'px',
  16. }"
  17. >
  18. <img :class="{ doc: imgStyle }" :src="imgSrc" alt="" v-if="imgSrc" />
  19. <div class="empty-box" :class="{ on: imgStyle }" v-else>
  20. <span class="iconfont-diy icontupian"></span>
  21. </div>
  22. </div>
  23. <div>
  24. <div
  25. class="dot"
  26. :style="{
  27. paddingLeft: edge + 10 + 'px',
  28. paddingRight: edge + 10 + 'px',
  29. justifyContent: dotPosition === 1 ? 'center' : dotPosition === 2 ? 'flex-end' : 'flex-start',
  30. }"
  31. v-if="docStyle == 0"
  32. >
  33. <div class="dot-item" :style="{ background: `${dotColor}` }"></div>
  34. <div class="dot-item"></div>
  35. <div class="dot-item"></div>
  36. </div>
  37. <div
  38. class="dot line-dot"
  39. :style="{
  40. paddingLeft: edge + 10 + 'px',
  41. paddingRight: edge + 10 + 'px',
  42. justifyContent: dotPosition === 1 ? 'center' : dotPosition === 2 ? 'flex-end' : 'flex-start',
  43. }"
  44. v-if="docStyle == 1"
  45. >
  46. <div class="line_dot-item" :style="{ background: `${dotColor}` }"></div>
  47. <div class="line_dot-item"></div>
  48. <div class="line_dot-item"></div>
  49. </div>
  50. <div
  51. class="dot number"
  52. :style="{
  53. paddingLeft: edge + 10 + 'px',
  54. paddingRight: edge + 10 + 'px',
  55. justifyContent: dotPosition === 1 ? 'center' : dotPosition === 2 ? 'flex-end' : 'flex-start',
  56. }"
  57. v-if="docStyle == 2"
  58. >
  59. <div class="num">1/3</div>
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import { mapState } from 'vuex';
  66. export default {
  67. name: 'banner', // 组件名称
  68. cname: '轮播图', // 标题名称
  69. icon: 'icontupianguanggao1',
  70. defaultName: 'swiperBg', // 外面匹配名称
  71. configName: 'c_banner', // 右侧配置名称
  72. type: 0, // 0 基础组件 1 营销组件 2工具组件
  73. props: {
  74. index: {
  75. type: null,
  76. },
  77. num: {
  78. type: null,
  79. },
  80. },
  81. computed: {
  82. ...mapState('mobildConfig', ['defaultArray']),
  83. },
  84. watch: {
  85. pageData: {
  86. handler(nVal, oVal) {
  87. this.setConfig(nVal);
  88. },
  89. deep: true,
  90. },
  91. num: {
  92. handler(nVal, oVal) {
  93. let data = this.$store.state.mobildConfig.defaultArray[nVal];
  94. this.setConfig(data);
  95. },
  96. deep: true,
  97. },
  98. defaultArray: {
  99. handler(nVal, oVal) {
  100. let data = this.$store.state.mobildConfig.defaultArray[this.num];
  101. this.setConfig(data);
  102. },
  103. deep: true,
  104. },
  105. },
  106. data() {
  107. return {
  108. // 默认初始化数据禁止修改
  109. defaultConfig: {
  110. name: 'swiperBg',
  111. timestamp: this.num,
  112. setUp: {
  113. tabVal: 0,
  114. },
  115. // 模板选择
  116. // tabConfig: {
  117. // tabVal: 0,
  118. // type: 1,
  119. // tabList: [
  120. // {
  121. // name: "单图模板",
  122. // icon: "iconbanner_1",
  123. // },
  124. // {
  125. // name: "多图模板1",
  126. // icon: "iconbanner_2",
  127. // },
  128. // {
  129. // name: "多图模板2",
  130. // icon: "iconbanner_3",
  131. // },
  132. // ],
  133. // },
  134. // 图片列表
  135. swiperConfig: {
  136. title: '最多可添加10张图片,建议宽度750px;鼠标拖拽左侧圆点可调整图片 顺序',
  137. maxList: 10,
  138. list: [
  139. {
  140. img: '',
  141. info: [
  142. {
  143. title: '标题',
  144. value: '今日推荐',
  145. tips: '选填,不超过4个字',
  146. max: 4,
  147. },
  148. {
  149. title: '链接',
  150. value: '',
  151. tips: '请输入链接',
  152. max: 100,
  153. },
  154. ],
  155. },
  156. ],
  157. },
  158. isShow: {
  159. title: '是否显示背景色',
  160. val: true,
  161. },
  162. // 背景颜色
  163. bgColor: {
  164. title: '背景颜色(渐变)',
  165. default: [
  166. {
  167. item: '#F62C2C',
  168. },
  169. {
  170. item: '#F96E29',
  171. },
  172. ],
  173. color: [
  174. {
  175. item: '#F62C2C',
  176. },
  177. {
  178. item: '#F96E29',
  179. },
  180. ],
  181. },
  182. dotColor: {
  183. title: '指示器颜色',
  184. default: [
  185. {
  186. item: '#fff',
  187. },
  188. ],
  189. color: [
  190. {
  191. item: '#fff',
  192. },
  193. ],
  194. },
  195. // 左右间距
  196. lrConfig: {
  197. title: '左右边距',
  198. val: 10,
  199. min: 0,
  200. },
  201. // 页面间距
  202. mbConfig: {
  203. title: '页面间距',
  204. val: 0,
  205. min: 0,
  206. },
  207. // 轮播图点样式
  208. docConfig: {
  209. cname: 'swiper',
  210. title: '指示器样式',
  211. type: 0,
  212. list: [
  213. {
  214. val: '圆形',
  215. icon: 'iconDot',
  216. },
  217. {
  218. val: '直线',
  219. icon: 'iconSquarepoint',
  220. },
  221. {
  222. val: '数字',
  223. icon: 'iconshuzi',
  224. },
  225. {
  226. val: '无指示器',
  227. icon: 'iconjinyong',
  228. },
  229. ],
  230. },
  231. txtStyle: {
  232. title: '指示器位置',
  233. type: 0,
  234. list: [
  235. {
  236. val: '居左',
  237. icon: 'icondoc_left',
  238. },
  239. {
  240. val: '居中',
  241. icon: 'icondoc_center',
  242. },
  243. {
  244. val: '居右',
  245. icon: 'icondoc_right',
  246. },
  247. ],
  248. },
  249. // 图片样式
  250. imgConfig: {
  251. cname: 'docStyle',
  252. title: '轮播图样式',
  253. type: 0,
  254. list: [
  255. {
  256. val: '圆角',
  257. icon: 'iconPic_fillet',
  258. },
  259. {
  260. val: '直角',
  261. icon: 'iconPic_square',
  262. },
  263. ],
  264. },
  265. },
  266. pageData: {},
  267. bgColor: [],
  268. mTOP: 0,
  269. edge: 0,
  270. imgStyle: 0,
  271. imgSrc: '',
  272. docStyle: 0,
  273. dotPosition: 0,
  274. dotColor: '',
  275. isShow: true,
  276. };
  277. },
  278. mounted() {
  279. this.$nextTick(() => {
  280. this.pageData = this.$store.state.mobildConfig.defaultArray[this.num];
  281. this.setConfig(this.pageData);
  282. });
  283. },
  284. methods: {
  285. setConfig(data) {
  286. if (!data) return;
  287. if (data.mbConfig) {
  288. this.isShow = data.isShow.val;
  289. this.bgColor = data.bgColor.color;
  290. this.mTOP = data.mbConfig.val;
  291. this.edge = data.lrConfig.val;
  292. this.imgStyle = data.imgConfig.type;
  293. this.imgSrc = data.swiperConfig.list.length ? data.swiperConfig.list[0].img : '';
  294. this.docStyle = data.docConfig.type;
  295. this.dotPosition = data.txtStyle.type;
  296. this.dotColor = data.dotColor.color[0].item;
  297. }
  298. },
  299. },
  300. };
  301. </script>
  302. <style scoped lang="stylus">
  303. .empty-box {
  304. height: 170px;
  305. }
  306. .mobile-page {
  307. position: relative;
  308. width: auto;
  309. /* height: 140px; */
  310. .banner {
  311. /* position: absolute; */
  312. /* left: 0; */
  313. /* top: 0; */
  314. width: 100%;
  315. margin-top: -48px;
  316. img {
  317. width: 100%;
  318. height: 100%;
  319. border-radius: 6px;
  320. &.doc {
  321. border-radius: 0;
  322. }
  323. }
  324. }
  325. .bg {
  326. width: 100%;
  327. height: 50px;
  328. background: linear-gradient(90deg, #F62C2C 0%, #F96E29 100%);
  329. }
  330. .bgset {
  331. width: 100%;
  332. height: 50px;
  333. }
  334. }
  335. .dot {
  336. position: absolute;
  337. left: 0;
  338. bottom: 20px;
  339. width: 100%;
  340. display: flex;
  341. align-items: center;
  342. &.number {
  343. bottom: 4px;
  344. }
  345. .num {
  346. width: 25px;
  347. height: 18px;
  348. line-height: 18px;
  349. background-color: #000;
  350. color: #fff;
  351. opacity: 0.3;
  352. border-radius: 8px;
  353. font-size: 12px;
  354. text-align: center;
  355. }
  356. .dot-item {
  357. width: 5px;
  358. height: 5px;
  359. background: #AAAAAA;
  360. border-radius: 50%;
  361. margin: 0 3px;
  362. }
  363. &.line-dot {
  364. bottom: 20px;
  365. .line_dot-item {
  366. width: 8px;
  367. height: 2px;
  368. background: #AAAAAA;
  369. margin: 0 3px;
  370. }
  371. }
  372. }
  373. </style>