Commit 6839c95fc7beaae0f9c06c5edababf4743a20355
1 parent
4ee40502
购好物,首页,热销排行自动无限循环滚动组件,完成~
Showing
7 changed files
with
334 additions
and
7 deletions
src/components/horizList/horizList.vue
| @@ -94,7 +94,7 @@ | @@ -94,7 +94,7 @@ | ||
| 94 | import goodsItem1 from "@/components/goodsItem_1/goodsItem_1"; | 94 | import goodsItem1 from "@/components/goodsItem_1/goodsItem_1"; |
| 95 | import goodsItem2 from "@/components/goodsItem_2/goodsItem_2"; | 95 | import goodsItem2 from "@/components/goodsItem_2/goodsItem_2"; |
| 96 | import goodsItem3 from "@/components/goodsItem_3/goodsItem_3"; | 96 | import goodsItem3 from "@/components/goodsItem_3/goodsItem_3"; |
| 97 | - import goodsItem10 from '@/components/goodsItem_10/goodsItem_10.vue'; | 97 | + import goodsItem10 from '@/components/goodsItem_10/goodsItem_10'; |
| 98 | import swiperItem from "@/components/swiperItem/swiperItem"; | 98 | import swiperItem from "@/components/swiperItem/swiperItem"; |
| 99 | import shopDarenHot from "@/components/shopDarenHot/shopDarenHot"; | 99 | import shopDarenHot from "@/components/shopDarenHot/shopDarenHot"; |
| 100 | import titleSubTitleCom from "@/components/titleSubTitleCom/titleSubTitleCom"; | 100 | import titleSubTitleCom from "@/components/titleSubTitleCom/titleSubTitleCom"; |
| @@ -128,6 +128,7 @@ | @@ -128,6 +128,7 @@ | ||
| 128 | jump(item) { | 128 | jump(item) { |
| 129 | this.$emit("jump", item); | 129 | this.$emit("jump", item); |
| 130 | }, | 130 | }, |
| 131 | + | ||
| 131 | /** | 132 | /** |
| 132 | * 跳转到达人个人中心页面 | 133 | * 跳转到达人个人中心页面 |
| 133 | * @param {object} item [数据对象] | 134 | * @param {object} item [数据对象] |
| @@ -135,6 +136,7 @@ | @@ -135,6 +136,7 @@ | ||
| 135 | userJump(item) { | 136 | userJump(item) { |
| 136 | this.$emit("userJump", item); | 137 | this.$emit("userJump", item); |
| 137 | }, | 138 | }, |
| 139 | + | ||
| 138 | /** | 140 | /** |
| 139 | * 关注 | 141 | * 关注 |
| 140 | * @param {object} item [数据对象] | 142 | * @param {object} item [数据对象] |
| @@ -142,6 +144,7 @@ | @@ -142,6 +144,7 @@ | ||
| 142 | fansShop(item){ | 144 | fansShop(item){ |
| 143 | this.$emit("fansShop", item); | 145 | this.$emit("fansShop", item); |
| 144 | }, | 146 | }, |
| 147 | + | ||
| 145 | /** | 148 | /** |
| 146 | * 加入购物车 | 149 | * 加入购物车 |
| 147 | * @param {object} item [数据对象] | 150 | * @param {object} item [数据对象] |
src/components/marqueeBox/marqueeBox.less
0 → 100644
src/components/marqueeBox/marqueeBox.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="marquee-box" v-if="lists && lists.length"> | ||
| 3 | + | ||
| 4 | + <!-- 标题插槽 --> | ||
| 5 | + <slot name="title-box"></slot> | ||
| 6 | + | ||
| 7 | + <!-- 内容区域 --> | ||
| 8 | + <div class="box"> | ||
| 9 | + | ||
| 10 | + <!-- 无限横向自动滚动组件 --> | ||
| 11 | + <marquee-com @jump="jump" @addCart="addCart" @primary="primary" | ||
| 12 | + :lists="lists" | ||
| 13 | + com="10" | ||
| 14 | + pid="1" | ||
| 15 | + :options="options"> | ||
| 16 | + </marquee-com> | ||
| 17 | + </div> | ||
| 18 | + </div> | ||
| 19 | +</template> | ||
| 20 | + | ||
| 21 | +<script> | ||
| 22 | + | ||
| 23 | + // 引入组件 | ||
| 24 | + import marqueeCom from '@/components/marqueeCom/marqueeCom'; | ||
| 25 | + | ||
| 26 | + export default { | ||
| 27 | + name: "marqueeBox", | ||
| 28 | + data() { | ||
| 29 | + return { | ||
| 30 | + | ||
| 31 | + } | ||
| 32 | + }, | ||
| 33 | + props: ["lists", "options"], | ||
| 34 | + components: { | ||
| 35 | + marqueeCom | ||
| 36 | + }, | ||
| 37 | + methods: { | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 点击跳转 | ||
| 41 | + * @param {object} item [数据对象] | ||
| 42 | + */ | ||
| 43 | + jump(item) { | ||
| 44 | + this.$emit("jump", item); | ||
| 45 | + }, | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 加入购物车 | ||
| 49 | + * @param {object} item [数据对象] | ||
| 50 | + */ | ||
| 51 | + addCart(item) { | ||
| 52 | + this.$emit("addCart", item); | ||
| 53 | + }, | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 主按钮点击事件 | ||
| 57 | + * @param {object} item [数据对象] | ||
| 58 | + */ | ||
| 59 | + primary(item) { | ||
| 60 | + this.$emit("primary", item); | ||
| 61 | + } | ||
| 62 | + }, | ||
| 63 | + watch: { | ||
| 64 | + | ||
| 65 | + }, | ||
| 66 | + mounted() { | ||
| 67 | + | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | +</script> | ||
| 71 | + | ||
| 72 | +<!-- Add "scoped" attribute to limit CSS to this component only --> | ||
| 73 | +<style rel="stylesheet/less" lang="less" scoped> | ||
| 74 | + @import './marqueeBox'; | ||
| 75 | +</style> |
src/components/marqueeCom/marqueeCom.less
0 → 100644
src/components/marqueeCom/marqueeCom.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="marquee-com" v-if="lists && lists.length"> | ||
| 3 | + <div class="box" ref="marqueesBox"> | ||
| 4 | + | ||
| 5 | + <!-- 判断是否有Clone数组 --> | ||
| 6 | + <template v-if="listsClone && listsClone.length"> | ||
| 7 | + | ||
| 8 | + <!-- 循环输出列表 --> | ||
| 9 | + <div class="item" ref="items" v-for="(item, index) in listsClone" :key="index"> | ||
| 10 | + | ||
| 11 | + <!-- | ||
| 12 | + com=1:goodsItem_1组件,pid:1、3,固定不滚动;2、4,滚动 | ||
| 13 | + 事件: | ||
| 14 | + @jump:整个点击跳转事件 | ||
| 15 | + @addCart:右下角加入购物车按钮事件,已阻止事件冒泡 | ||
| 16 | + | ||
| 17 | + com=2:goodsItem_2组件,pid: 1,带标题,不显示附加信息;2、不带标题,显示附加信息 | ||
| 18 | + 事件: | ||
| 19 | + @jump:整个点击跳转事件 | ||
| 20 | + | ||
| 21 | + com=3:goodsItem_3组件,无pid参数 | ||
| 22 | + 事件: | ||
| 23 | + @jump:整个点击跳转事件 | ||
| 24 | + @primary:右下角红色主按钮点击事件,已阻止事件冒泡 | ||
| 25 | + | ||
| 26 | + com=10:goodsItem_10组件,pid: 1,价格,原价;2、积分信息 | ||
| 27 | + 事件: | ||
| 28 | + @jump:整个点击跳转事件 | ||
| 29 | + | ||
| 30 | + --> | ||
| 31 | + | ||
| 32 | + <!-- 商品展示样式 1 --> | ||
| 33 | + <goods-item-1 v-if="com == '1'" @jump="jump" @addCart="addCart" | ||
| 34 | + :item="item" | ||
| 35 | + :pid="pid"> | ||
| 36 | + </goods-item-1> | ||
| 37 | + | ||
| 38 | + <!-- 商品展示样式 2 --> | ||
| 39 | + <goods-item-2 v-if="com == '2'" @jump="jump" | ||
| 40 | + :item="item" | ||
| 41 | + :pid="pid"> | ||
| 42 | + </goods-item-2> | ||
| 43 | + | ||
| 44 | + <!-- 商品展示样式 3 --> | ||
| 45 | + <goods-item-3 v-if="com == '3'" @jump="jump" @primary="primary" | ||
| 46 | + :item="item"> | ||
| 47 | + </goods-item-3> | ||
| 48 | + | ||
| 49 | + <!-- 商品展示样式 10 --> | ||
| 50 | + <goods-item-10 v-if="com == '10'" @jump="jump" | ||
| 51 | + :item="item" | ||
| 52 | + :pid="pid"> | ||
| 53 | + </goods-item-10> | ||
| 54 | + </div> | ||
| 55 | + </template> | ||
| 56 | + </div> | ||
| 57 | + </div> | ||
| 58 | +</template> | ||
| 59 | + | ||
| 60 | +<script> | ||
| 61 | + | ||
| 62 | + // 引入组件 | ||
| 63 | + import goodsItem1 from "@/components/goodsItem_1/goodsItem_1"; | ||
| 64 | + import goodsItem2 from "@/components/goodsItem_2/goodsItem_2"; | ||
| 65 | + import goodsItem3 from "@/components/goodsItem_3/goodsItem_3"; | ||
| 66 | + import goodsItem10 from '@/components/goodsItem_10/goodsItem_10'; | ||
| 67 | + | ||
| 68 | + export default { | ||
| 69 | + name : 'marqueeCom', | ||
| 70 | + props: ['lists', 'com', 'pid', 'options'], | ||
| 71 | + data () { | ||
| 72 | + return { | ||
| 73 | + listsClone: [] // lists深度拷贝对象 | ||
| 74 | + } | ||
| 75 | + }, | ||
| 76 | + components: { | ||
| 77 | + goodsItem1, | ||
| 78 | + goodsItem2, | ||
| 79 | + goodsItem3, | ||
| 80 | + goodsItem10 | ||
| 81 | + }, | ||
| 82 | + methods: { | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 跑马灯无限循环移动函数 | ||
| 86 | + * @param {Object} itemWidth [元素宽度,用户处理添加/删除元素逻辑] | ||
| 87 | + * @param {Object} marqueesBox [列表元素DOM对象] | ||
| 88 | + */ | ||
| 89 | + move(itemWidth, marqueesBox) { | ||
| 90 | + | ||
| 91 | + // 位移量 | ||
| 92 | + let distance = 0; | ||
| 93 | + | ||
| 94 | + // 追加第几个数组数据下标 | ||
| 95 | + let sub = null; | ||
| 96 | + | ||
| 97 | + // 检查配置选项,设置轮训时间 | ||
| 98 | + let timer = (this.options && this.options.timer && this.options.timer > 0) ? this.options.timer : 30; | ||
| 99 | + | ||
| 100 | + // 设置位移 | ||
| 101 | + let interval = setInterval(() => { | ||
| 102 | + | ||
| 103 | + // 计算位移量 | ||
| 104 | + distance = distance - 1; | ||
| 105 | + | ||
| 106 | + // 向左移动 | ||
| 107 | + marqueesBox.style.transform = 'translateX(' + distance + 'px)'; | ||
| 108 | + | ||
| 109 | + // 判断添加/删除元素 | ||
| 110 | + if (!(distance % itemWidth)) { | ||
| 111 | + | ||
| 112 | + // 判断应该追加第几个数组数据下标 | ||
| 113 | + if (!sub) { | ||
| 114 | + sub = 0; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + // 追加数据到listsClone数组 | ||
| 118 | + this.$set(this, 'listsClone', [...this.listsClone, ...[this.lists[sub]]]); | ||
| 119 | + | ||
| 120 | + // 判断数组下标是否越界 | ||
| 121 | + if (sub < this.lists.length - 1) { | ||
| 122 | + sub++; | ||
| 123 | + } else { | ||
| 124 | + sub = 0; | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + }, timer); | ||
| 128 | + }, | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * 点击跳转 | ||
| 132 | + * @param {object} item [数据对象] | ||
| 133 | + */ | ||
| 134 | + jump(item) { | ||
| 135 | + this.$emit("jump", item); | ||
| 136 | + }, | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * 加入购物车 | ||
| 140 | + * @param {object} item [数据对象] | ||
| 141 | + */ | ||
| 142 | + addCart(item) { | ||
| 143 | + this.$emit("addCart", item); | ||
| 144 | + }, | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * 主按钮点击事件 | ||
| 148 | + * @param {object} item [数据对象] | ||
| 149 | + */ | ||
| 150 | + primary(item) { | ||
| 151 | + this.$emit("primary", item); | ||
| 152 | + } | ||
| 153 | + }, | ||
| 154 | + mounted() { | ||
| 155 | + | ||
| 156 | + // 下一周期执行 | ||
| 157 | + this.$nextTick(() => { | ||
| 158 | + | ||
| 159 | + // 深度拷贝数组 | ||
| 160 | + this.$set(this, 'listsClone', this.lists.slice(0)); | ||
| 161 | + | ||
| 162 | + // 检查配置选项 | ||
| 163 | + let minCount = (this.options && this.options.minCount && this.options.minCount > 0) ? this.options.minCount : 5; | ||
| 164 | + | ||
| 165 | + // 判断列表项目是否 >= 5项,如果不足,不全列表项 | ||
| 166 | + while(true) { | ||
| 167 | + | ||
| 168 | + if (this.listsClone && this.listsClone.length >= minCount) { | ||
| 169 | + break; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + // 向尾部追加数据(克隆数据,prop数据不能追加数组) | ||
| 173 | + this.$set(this, 'listsClone', [...this.listsClone, ...this.listsClone]); | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + // 下一周期执行 | ||
| 177 | + this.$nextTick(() => { | ||
| 178 | + | ||
| 179 | + // 获取item宽度 | ||
| 180 | + let itemWidth = this.$refs.items[0].clientWidth; | ||
| 181 | + | ||
| 182 | + // 判断是否获取到item宽度 | ||
| 183 | + if (itemWidth) { | ||
| 184 | + | ||
| 185 | + // 延时2秒再开始滚动 | ||
| 186 | + setTimeout(() => { | ||
| 187 | + | ||
| 188 | + // 跑马灯无限循环移动函数 | ||
| 189 | + this.move(itemWidth, this.$refs.marqueesBox); | ||
| 190 | + }, 2000); | ||
| 191 | + } | ||
| 192 | + }); | ||
| 193 | + }); | ||
| 194 | + } | ||
| 195 | + } | ||
| 196 | +</script> | ||
| 197 | + | ||
| 198 | +<!-- Add "scoped" attribute to limit CSS to this component only --> | ||
| 199 | +<style rel="stylesheet/less" lang='less' scoped> | ||
| 200 | + @import "marqueeCom"; | ||
| 201 | +</style> | ||
| 0 | \ No newline at end of file | 202 | \ No newline at end of file |
src/pages/optimization2/optimization2.less
src/pages/optimization2/optimization2.vue
| @@ -41,8 +41,6 @@ | @@ -41,8 +41,6 @@ | ||
| 41 | </icon-swiper-box> | 41 | </icon-swiper-box> |
| 42 | </div> | 42 | </div> |
| 43 | 43 | ||
| 44 | - <!-- 折扣专区 --> | ||
| 45 | - | ||
| 46 | <!-- 折扣专区/积分商城 --> | 44 | <!-- 折扣专区/积分商城 --> |
| 47 | <div class="section-col-2" v-if="showIntegral && pointsLists && pointsLists.length"> | 45 | <div class="section-col-2" v-if="showIntegral && pointsLists && pointsLists.length"> |
| 48 | 46 | ||
| @@ -150,6 +148,7 @@ | @@ -150,6 +148,7 @@ | ||
| 150 | </div> | 148 | </div> |
| 151 | </div> | 149 | </div> |
| 152 | 150 | ||
| 151 | + <!-- 折扣专区 --> | ||
| 153 | <div class="section shop-list" v-else-if="discountLists && discountLists.length"> | 152 | <div class="section shop-list" v-else-if="discountLists && discountLists.length"> |
| 154 | 153 | ||
| 155 | <!-- 标题 --> | 154 | <!-- 标题 --> |
| @@ -253,10 +252,24 @@ | @@ -253,10 +252,24 @@ | ||
| 253 | <div class="section hot-box" ref="hotBox" v-if="sales && sales.length" @click="toHotSaleList"> | 252 | <div class="section hot-box" ref="hotBox" v-if="sales && sales.length" @click="toHotSaleList"> |
| 254 | 253 | ||
| 255 | <!-- 商品样式 2 滑动 --> | 254 | <!-- 商品样式 2 滑动 --> |
| 256 | - <horiz-list class="components-box" | 255 | + <!-- <horiz-list class="components-box" |
| 257 | :lists="sales" | 256 | :lists="sales" |
| 258 | com="10" | 257 | com="10" |
| 259 | - pid="1"> | 258 | + pid="1"> --> |
| 259 | + | ||
| 260 | + <!-- 标题 --> | ||
| 261 | + <!-- <text-bg-title-com slot="title-box" | ||
| 262 | + :titles="{ | ||
| 263 | + bg: 'static/img/text_bg_title_bg_5.png', | ||
| 264 | + more: true | ||
| 265 | + }"> | ||
| 266 | + </text-bg-title-com> | ||
| 267 | + </horiz-list> --> | ||
| 268 | + | ||
| 269 | + <!-- 热销商品自动滚动 --> | ||
| 270 | + <marquee-box class="marquee-box" | ||
| 271 | + :lists="sales" | ||
| 272 | + :options="marqueeOptions"> | ||
| 260 | 273 | ||
| 261 | <!-- 标题 --> | 274 | <!-- 标题 --> |
| 262 | <text-bg-title-com slot="title-box" | 275 | <text-bg-title-com slot="title-box" |
| @@ -265,7 +278,7 @@ | @@ -265,7 +278,7 @@ | ||
| 265 | more: true | 278 | more: true |
| 266 | }"> | 279 | }"> |
| 267 | </text-bg-title-com> | 280 | </text-bg-title-com> |
| 268 | - </horiz-list> | 281 | + </marquee-box> |
| 269 | </div> | 282 | </div> |
| 270 | 283 | ||
| 271 | <!-- 猜你喜欢 --> | 284 | <!-- 猜你喜欢 --> |
| @@ -335,6 +348,7 @@ | @@ -335,6 +348,7 @@ | ||
| 335 | import iconSwiperBox from "@/components/iconSwiperBox/iconSwiperBox"; | 348 | import iconSwiperBox from "@/components/iconSwiperBox/iconSwiperBox"; |
| 336 | import textBgTitleCom from "@/components/textBgTitleCom/textBgTitleCom"; | 349 | import textBgTitleCom from "@/components/textBgTitleCom/textBgTitleCom"; |
| 337 | import countDownCom from "@/components/countDownCom/countDownCom"; | 350 | import countDownCom from "@/components/countDownCom/countDownCom"; |
| 351 | + import marqueeBox from '@/components/marqueeBox/marqueeBox'; | ||
| 338 | import goodsItem2 from "@/components/goodsItem_2/goodsItem_2"; | 352 | import goodsItem2 from "@/components/goodsItem_2/goodsItem_2"; |
| 339 | import goodsItem10 from "@/components/goodsItem_10/goodsItem_10"; | 353 | import goodsItem10 from "@/components/goodsItem_10/goodsItem_10"; |
| 340 | import iconsCom from "@/components/iconsCom/iconsCom"; | 354 | import iconsCom from "@/components/iconsCom/iconsCom"; |
| @@ -369,6 +383,10 @@ | @@ -369,6 +383,10 @@ | ||
| 369 | quality: null, // 品质优选 | 383 | quality: null, // 品质优选 |
| 370 | salesOptions: null, // 热销排行选项 | 384 | salesOptions: null, // 热销排行选项 |
| 371 | sales: null, // 热销排行数据 | 385 | sales: null, // 热销排行数据 |
| 386 | + marqueeOptions: { // 无限滚动配置选项 | ||
| 387 | + minCount: 5, // 初始化最小项目总数量 | ||
| 388 | + timer: 30 // 轮训时间 | ||
| 389 | + }, | ||
| 372 | showSearch: false, // 是否显示搜索,默认不显示 | 390 | showSearch: false, // 是否显示搜索,默认不显示 |
| 373 | showNavs: false, // 是否显示其它频道跳转,默认不显示 | 391 | showNavs: false, // 是否显示其它频道跳转,默认不显示 |
| 374 | showIntegral: false, // 是否显示积分商城模块,默认不显示 | 392 | showIntegral: false, // 是否显示积分商城模块,默认不显示 |
| @@ -429,6 +447,7 @@ | @@ -429,6 +447,7 @@ | ||
| 429 | iconSwiperBox, | 447 | iconSwiperBox, |
| 430 | textBgTitleCom, | 448 | textBgTitleCom, |
| 431 | countDownCom, | 449 | countDownCom, |
| 450 | + marqueeBox, | ||
| 432 | goodsItem2, | 451 | goodsItem2, |
| 433 | goodsItem10, | 452 | goodsItem10, |
| 434 | iconsCom, | 453 | iconsCom, |
| @@ -437,7 +456,7 @@ | @@ -437,7 +456,7 @@ | ||
| 437 | moreCom, | 456 | moreCom, |
| 438 | textTitleBox, | 457 | textTitleBox, |
| 439 | columnListBox, | 458 | columnListBox, |
| 440 | - gotoTop | 459 | + gotoTop, |
| 441 | }, | 460 | }, |
| 442 | created() { | 461 | created() { |
| 443 | 462 |