Commit bc92f204d61a74fad44b959c851bc9e80d1cf13d
1 parent
2aef2ea0
购好物,首页逻辑强壮性优化~
Showing
1 changed file
with
69 additions
and
61 deletions
src/pages/optimization2/optimization2.vue
| ... | ... | @@ -455,7 +455,7 @@ |
| 455 | 455 | interval: null // 轮训对象,用于判断如果有轮训对象就不再重新设置轮训了 |
| 456 | 456 | }, |
| 457 | 457 | showTVGoods: false, // 是否显示电视购物模块,默认不显示 |
| 458 | - tvGoodsLists: null, // 积分商城数据 | |
| 458 | + tvGoodsLists: null, // 电视购物数据 | |
| 459 | 459 | tvGoodsData: { |
| 460 | 460 | now: [], // 当前电视购物数据(用于动画展示) |
| 461 | 461 | next: 0, // 下一个需要展示的电视购物数组下标(电视购物总数据) |
| ... | ... | @@ -714,9 +714,6 @@ |
| 714 | 714 | // 判断在App内 |
| 715 | 715 | if (this.isCNLive.value) { |
| 716 | 716 | |
| 717 | - // 设置显示电视购物模块 | |
| 718 | - this.$set(this, 'showTVGoods', true); | |
| 719 | - | |
| 720 | 717 | // 判断App版本,判断是否显示积分商城模块 |
| 721 | 718 | if (typeof this.$parent.compareVersion === 'function') { |
| 722 | 719 | |
| ... | ... | @@ -791,41 +788,45 @@ |
| 791 | 788 | // 积分商城数据 |
| 792 | 789 | this.$set(this, 'pointsLists', datas.integral_goods); |
| 793 | 790 | |
| 794 | - // 当前展示的积分商城数据(兼容数据不足 2 个的情况) | |
| 795 | - if (this.pointsLists.length >= 2) { | |
| 796 | - this.$set(this.pointsData, 'now', [this.pointsLists[0], this.pointsLists[1]]); | |
| 797 | - } else { | |
| 798 | - this.$set(this.pointsData, 'now', [this.pointsLists[0]]); | |
| 799 | - } | |
| 791 | + // 判断积分商城是否有数据,有数据再设置 | |
| 792 | + if (this.pointsLists) { | |
| 800 | 793 | |
| 801 | - // 设置积分商城下一条数据数组下标 | |
| 802 | - this.$set(this.pointsData, 'next', this.pointsData.now.length < this.pointsLists.length ? this.pointsData.now.length : 0); | |
| 794 | + // 当前展示的积分商城数据(兼容数据不足 2 个的情况) | |
| 795 | + if (this.pointsLists.length >= 2) { | |
| 796 | + this.$set(this.pointsData, 'now', [this.pointsLists[0], this.pointsLists[1]]); | |
| 797 | + } else if (this.pointsLists.length == 1) { | |
| 798 | + this.$set(this.pointsData, 'now', [this.pointsLists[0], this.pointsLists[0]]); | |
| 799 | + } | |
| 803 | 800 | |
| 804 | - // 设置积分商城计时器,每3秒切换一次数据 | |
| 805 | - this.$nextTick(() => { | |
| 801 | + // 设置积分商城下一条数据数组下标 | |
| 802 | + this.$set(this.pointsData, 'next', this.pointsData.now.length < this.pointsLists.length ? this.pointsData.now.length : 0); | |
| 806 | 803 | |
| 807 | - // 判断是否已有轮训对象 | |
| 808 | - if (!this.pointsData.interval) { | |
| 804 | + // 设置积分商城计时器,每3秒切换一次数据 | |
| 805 | + this.$nextTick(() => { | |
| 809 | 806 | |
| 810 | - // 判断数据数量是否 > 2 ,如果是,执行切换轮训 | |
| 811 | - if (this.pointsData.now.length < this.pointsLists.length) { | |
| 807 | + // 判断是否已有轮训对象 | |
| 808 | + if (!this.pointsData.interval) { | |
| 812 | 809 | |
| 813 | - // 和折扣专区岔开,延时1秒执行 | |
| 814 | - setTimeout(() => { | |
| 815 | - | |
| 816 | - // 随机生成轮训时间 | |
| 817 | - let timer = (parseInt(Math.random() * (500 + 1) + 5000, 10) || 5000); | |
| 810 | + // 判断数据数量是否 > 2 ,如果是,执行切换轮训 | |
| 811 | + if (this.pointsData.now.length < this.pointsLists.length) { | |
| 818 | 812 | |
| 819 | - // 轮训计时器 | |
| 820 | - this.pointsData.interval = setInterval(() => { | |
| 813 | + // 和折扣专区岔开,延时1秒执行 | |
| 814 | + setTimeout(() => { | |
| 821 | 815 | |
| 822 | - // 切换积分商城数据 | |
| 823 | - this.fade(this.pointsData, this.pointsLists); | |
| 824 | - }, timer); | |
| 825 | - }, 1000); | |
| 816 | + // 随机生成轮训时间 | |
| 817 | + let timer = (parseInt(Math.random() * (500 + 1) + 5000, 10) || 5000); | |
| 818 | + | |
| 819 | + // 轮训计时器 | |
| 820 | + this.pointsData.interval = setInterval(() => { | |
| 821 | + | |
| 822 | + // 切换积分商城数据 | |
| 823 | + this.fade(this.pointsData, this.pointsLists); | |
| 824 | + }, timer); | |
| 825 | + }, 1000); | |
| 826 | + } | |
| 826 | 827 | } |
| 827 | - } | |
| 828 | - }); | |
| 828 | + }); | |
| 829 | + } | |
| 829 | 830 | } else { |
| 830 | 831 | |
| 831 | 832 | // 如果不需要展示积分商城/积分商城数据为空,并且折扣专区商品数量大于3,重新设置折扣专区模块商品数量 |
| ... | ... | @@ -854,6 +855,9 @@ |
| 854 | 855 | // 判断是否有电视购物模块 |
| 855 | 856 | if (datas.tv_goods && datas.tv_goods.length) { |
| 856 | 857 | |
| 858 | + // 设置显示电视购物模块 | |
| 859 | + this.$set(this, 'showTVGoods', true); | |
| 860 | + | |
| 857 | 861 | // 判断折扣专区是否有数据 |
| 858 | 862 | if (this.discountLists.length) { |
| 859 | 863 | |
| ... | ... | @@ -893,44 +897,45 @@ |
| 893 | 897 | // 电视购物数据 |
| 894 | 898 | this.$set(this, 'tvGoodsLists', datas.tv_goods); |
| 895 | 899 | |
| 896 | - // 当前展示的电视购物数据(兼容数据不足 2 个的情况) | |
| 897 | - if (this.tvGoodsLists.length >= 2) { | |
| 898 | - this.$set(this.tvGoodsData, 'now', [this.tvGoodsLists[0], this.tvGoodsLists[1]]); | |
| 899 | - } else { | |
| 900 | - this.$set(this.tvGoodsData, 'now', [this.tvGoodsLists[0], this.tvGoodsLists[0]]); | |
| 901 | - } | |
| 900 | + // 判断电视购物是否有数据,有数据再设置 | |
| 901 | + if (this.tvGoodsLists) { | |
| 902 | 902 | |
| 903 | - // 设置电视购物下一条数据数组下标 | |
| 904 | - this.$set(this.tvGoodsData, 'next', this.tvGoodsData.now.length < this.tvGoodsLists.length ? this.tvGoodsData.now.length : 0); | |
| 903 | + // 当前展示的电视购物数据(兼容数据不足 2 个的情况) | |
| 904 | + if (this.tvGoodsLists && this.tvGoodsLists.length >= 2) { | |
| 905 | + this.$set(this.tvGoodsData, 'now', [this.tvGoodsLists[0], this.tvGoodsLists[1]]); | |
| 906 | + } else if (this.tvGoodsLists && this.tvGoodsLists.length == 1) { | |
| 907 | + this.$set(this.tvGoodsData, 'now', [this.tvGoodsLists[0], this.tvGoodsLists[0]]); | |
| 908 | + } | |
| 905 | 909 | |
| 906 | - // 设置电视购物计时器,每3秒切换一次数据 | |
| 907 | - this.$nextTick(() => { | |
| 910 | + // 设置电视购物下一条数据数组下标 | |
| 911 | + this.$set(this.tvGoodsData, 'next', this.tvGoodsData.now.length < this.tvGoodsLists.length ? this.tvGoodsData.now.length : 0); | |
| 908 | 912 | |
| 909 | - // 判断是否已有轮训对象 | |
| 910 | - if (!this.tvGoodsData.interval) { | |
| 913 | + // 设置电视购物计时器,每3秒切换一次数据 | |
| 914 | + this.$nextTick(() => { | |
| 911 | 915 | |
| 912 | - // 判断数据数量是否 > 2 ,如果是,执行切换轮训 | |
| 913 | - if (this.tvGoodsData.now.length < this.tvGoodsLists.length) { | |
| 916 | + // 判断是否已有轮训对象 | |
| 917 | + if (!this.tvGoodsData.interval) { | |
| 914 | 918 | |
| 915 | - // 和折扣专区岔开,延时1秒执行 | |
| 916 | - setTimeout(() => { | |
| 917 | - | |
| 918 | - // 随机生成轮训时间 | |
| 919 | - let timer = (parseInt(Math.random() * (500 + 1) + 5000, 10) || 5000); | |
| 919 | + // 判断数据数量是否 > 2 ,如果是,执行切换轮训 | |
| 920 | + if (this.tvGoodsData.now.length < this.tvGoodsLists.length) { | |
| 920 | 921 | |
| 921 | - // 轮训计时器 | |
| 922 | - this.tvGoodsData.interval = setInterval(() => { | |
| 922 | + // 和折扣专区岔开,延时1秒执行 | |
| 923 | + setTimeout(() => { | |
| 923 | 924 | |
| 924 | - // 切换电视购物数据 | |
| 925 | - this.fade(this.tvGoodsData, this.tvGoodsLists); | |
| 926 | - }, timer); | |
| 927 | - }, 1000); | |
| 925 | + // 随机生成轮训时间 | |
| 926 | + let timer = (parseInt(Math.random() * (500 + 1) + 5000, 10) || 5000); | |
| 927 | + | |
| 928 | + // 轮训计时器 | |
| 929 | + this.tvGoodsData.interval = setInterval(() => { | |
| 930 | + | |
| 931 | + // 切换电视购物数据 | |
| 932 | + this.fade(this.tvGoodsData, this.tvGoodsLists); | |
| 933 | + }, timer); | |
| 934 | + }, 1000); | |
| 935 | + } | |
| 928 | 936 | } |
| 929 | - } | |
| 930 | - }); | |
| 931 | - | |
| 932 | - // 显示推荐商品瀑布流 | |
| 933 | - this.$set(this, 'showGoodsList', true); | |
| 937 | + }); | |
| 938 | + } | |
| 934 | 939 | } else { |
| 935 | 940 | |
| 936 | 941 | // 如果不需要展示电视购物/电视购物数据为空,并且折扣专区商品数量大于3,重新设置折扣专区模块商品数量 |
| ... | ... | @@ -955,6 +960,9 @@ |
| 955 | 960 | |
| 956 | 961 | /* 获取优选库“优选”数据 结束 */ |
| 957 | 962 | |
| 963 | + // 显示推荐商品瀑布流 | |
| 964 | + this.$set(this, 'showGoodsList', true); | |
| 965 | + | |
| 958 | 966 | } else if (res.code == 400) { |
| 959 | 967 | |
| 960 | 968 | // 获取优选失败 | ... | ... |