文件
xionggeshop/xgsc.gynhc.com_wx/pages/index/index.vue
2026-09-14 17:24:53 +08:00

306 行
9.1 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<!-- 首页 -->
<template>
<view class="home-wrap u-m-b-20">
<view class="home-content-layer">
<!-- 空白页 -->
<!-- #ifdef APP-PLUS -->
<u-no-network @retry="init"></u-no-network>
<!-- #endif -->
<shopro-empty v-if="!hasTemplate" :image="$IMG_URL + '/imgs/empty/empty_goods_null.png'"
tipText="暂未找到模板,请前往装修~">
</shopro-empty>
<view v-else-if="isConnected && isRefresh" class="content-box">
<!-- 顶部:品牌 + 搜索 + 轮播 -->
<home-head :list="headSwiperList || []" :navTitle="initShop.name"></home-head>
<!-- 快捷入口 + 自定义模块 -->
<view class="template-box">
<block v-for="item in sortedHomeModules" :key="item.id">
<sh-banner v-if="item.type === 'banner'" :Px="item.content.x"
:Py="item.content.y" :borderRadius="item.content.radius" :height="item.content.height"
:list="item.content.list">
</sh-banner>
<sh-search v-if="item.type === 'search'"></sh-search>
<sh-grid-swiper v-if="item.type === 'menu'" :list="filterNavList(item.content.list)"
:oneRowNum="item.content.style" :colorful="true"></sh-grid-swiper>
<sh-image-goods v-if="item.type === 'image-goods'" :goods="item.content.goods"
:image="item.content.image"></sh-image-goods>
<sh-pic-ads v-if="item.type === 'pic-ads'" :image="item.content.image"
:list="item.content.hotsPotList"></sh-pic-ads>
<sh-coupon v-if="item.type === 'coupons'" :detail="item.content"></sh-coupon>
<sh-seckill v-if="item.type === 'seckill'" :detail="item.content"></sh-seckill>
<sh-groupon v-if="false && item.type === 'groupon'" :detail="item.content"></sh-groupon>
<sh-richtext v-if="item.type === 'rich-text'" :richId="item.content.id"></sh-richtext>
<!-- #ifdef MP-WEIXIN -->
<sh-live v-if="item.type === 'live' && HAS_LIVE" :detail="item.content"></sh-live>
<!-- #endif -->
</block>
</view>
<!-- 1+3 业务专区 -->
<home-zone-grid :list="zoneGridList"></home-zone-grid>
<sh-title-card
v-if="homeSectionTitle"
variant="section"
:title="homeSectionTitle.name || '精选好酒'"
:showMore="false"
></sh-title-card>
<sh-hot-goods
v-if="homeGoodsDetail"
:detail="homeGoodsDetail"
:compactMode="true"
></sh-hot-goods>
<!-- 悬浮按钮 -->
<shopro-float-btn></shopro-float-btn>
<!-- 连续弹窗提醒 -->
<shopro-notice-modal v-if="!showPrivacy && isLogin"></shopro-notice-modal>
<!-- 隐私协议 -->
<!-- #ifdef APP-PLUS -->
<privacy-modal v-if="initShop && initShop.name" v-model="showPrivacy"></privacy-modal>
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="tabbar-hack" style="height: 120rpx; width:100%;"></view>
<!-- #endif -->
</view>
</view>
<!-- <shopro-protocol :show="true"></shopro-protocol> -->
<shopro-tabbar></shopro-tabbar>
<!-- 登录弹窗放在页面根节点,避免真机 fixed 定位异常 -->
<shopro-auth-modal></shopro-auth-modal>
</view>
</template>
<script>
import shBanner from './components/sh-banner.vue';
import shGridSwiper from './components/sh-grid-swiper.vue';
import shHotGoods from './components/sh-hot-goods.vue';
import shPicAds from './components/sh-pic-ads.vue';
import shImageGoods from './components/sh-image-goods.vue';
import shCoupon from './components/sh-coupon.vue';
import shSeckill from './components/sh-seckill.vue';
import shGroupon from './components/sh-groupon.vue';
import shRichtext from './components/sh-richtext.vue';
import shTitleCard from './components/sh-title-card.vue';
import shSearch from './components/sh-search.vue';
import privacyModal from './index/privacy-modal.vue';
import homeHead from './index/home-head.vue';
import homeZoneGrid from './index/home-zone-grid.vue';
import ShoproProtocol from '@/components/shopro-protocol/shopro-protocol.vue'
import checkVersion from '@/pages/lq-upgrade/checkVersion.js'
// #ifdef MP-WEIXIN
import {
HAS_LIVE
} from '@/env';
import shLive from './components/sh-live.vue';
// #endif
import {
mapMutations,
mapActions,
mapState,
mapGetters
} from 'vuex';
import { filterHiddenTools } from '@/shopro/utils/hidden-tools';
export default {
components: {
shBanner,
shGridSwiper,
shGroupon,
shHotGoods,
shPicAds,
shCoupon,
shSeckill,
shRichtext,
shTitleCard,
shSearch,
shImageGoods,
privacyModal,
homeHead,
homeZoneGrid,
ShoproProtocol,
// #ifdef MP-WEIXIN
shLive
// #endif
},
data() {
return {
// #ifdef MP-WEIXIN
HAS_LIVE: HAS_LIVE,
// #endif
isRefresh: true,
enable: false, //是否开启吸顶。
isConnected: true, //是否有网
showPrivacy: false, //协议
isScorll: false
};
},
computed: {
...mapGetters(['initShop', 'homeTemplate', 'hasTemplate', 'isLogin']),
// 头部模块数据
headSwiperList() {
if (this.homeTemplate?.length) {
return this.homeTemplate[0]?.content?.list;
}
},
// 分类选项卡数据
categoryTabsData() {
if (this.homeTemplate?.length) {
return this.homeTemplate[this.homeTemplate.length - 1]?.content;
}
},
homeSectionTitle() {
const mod = (this.homeTemplate || []).find(item => item.type === 'title-block');
return mod ? mod.content : { name: '精选好酒' };
},
homeGoodsDetail() {
const template = this.homeTemplate || [];
const goodsMod = template.find(item => item.type === 'goods-list' || item.type === 'goods-group');
if (goodsMod?.content) {
return goodsMod.content;
}
const tabsMod = template.find(item => item.type === 'category-tabs' || item.content?.category_arr?.length);
if (tabsMod?.content?.category_arr?.length) {
return {
id: tabsMod.content.category_arr[0].id,
style: tabsMod.content.style || 1
};
}
const last = template[template.length - 1];
if (last?.content?.category_arr?.length) {
return {
id: last.content.category_arr[0].id,
style: last.content.style || 1
};
}
return { style: 1 };
},
sortedHomeModules() {
if (!this.homeTemplate?.length) return [];
const lastIndex = this.homeTemplate.length - 1;
const modules = this.homeTemplate.filter((item, index) => {
if (index === 0 && item.type === 'banner') return false;
if (index === lastIndex) return false;
if (item.type === 'title-block') return false;
if (item.type === 'goods-list' || item.type === 'goods-group') return false;
if (item.type === 'category-tabs') return false;
if (item.type === 'search') return false;
if (item.type === 'adv') return false;
return true;
});
const menus = modules.filter(item => item.type === 'menu');
const others = modules.filter(item => item.type !== 'menu');
return [...menus, ...others];
},
zoneGridList() {
const advMod = (this.homeTemplate || []).find(item => item.type === 'adv');
const advList = advMod?.content?.list;
if (advList && advList.length >= 4) {
return advList.map(item => ({
title: item.name || item.title,
path: item.path,
image: item.image
}));
}
return [];
}
},
onPullDownRefresh() {
this.init();
},
onPageScroll(e) {
this.isScorll = e.scrollTop > 100 ? true : false;
},
onShow() {
uni.hideTabBar();
let that = this;
this.enable = true;
this.isLogin && this.getCartList();
// 网络变化检测
uni.onNetworkStatusChange(res => {
this.isConnected = res.isConnected;
res.isConnected && this.init();
});
},
onHide() {
this.enable = false;
},
onLoad() {
// #ifdef APP-VUE
// app自动更新
this.upgrade();
// app隐私协议弹窗
if (!plus.runtime.isAgreePrivacy()) {
this.showPrivacy = true;
this.showNoticeModal = false;
}
// #endif
},
methods: {
...mapActions(['appInit', 'getTemplate', 'getCartList']),
filterNavList(list) {
return filterHiddenTools(list);
},
// 初始化
init() {
this.isRefresh = false;
return Promise.all([this.getTemplate()]).then(() => {
uni.stopPullDownRefresh();
this.isRefresh = true;
});
},
// app版本更新
upgrade() {
setTimeout(() => {
this.$http('common.upgrade', {}).then(res => {
let data = res.data;
if (data.code) {
let name = data.name; // 新版本名称
let code = parseInt(data.code); // 新版本号(数字)
let content = ``; // 更新内容
let url = data.url; // app下载链接,(演示请换成真正在下载链接)
let forceUpdate = false; // 是否强制更新
for (let item of data.content) {
content += `${item.content}<br>`;
}
// 检查是否需要更新
checkVersion({
name, // 最新版本名称
code, // 最新版本号
content, // 更新内容
url, // 下载链接
forceUpdate // 是否强制升级
})
}
});
}, 1000)
}
}
};
</script>
<style lang="scss">
.home-wrap {
background: $brand-page-bg;
min-height: 100vh;
}
.content-box {
position: relative;
padding-bottom: 24rpx;
}
.home-content-layer {
position: relative;
}
.template-box {
padding-top: 0;
}
</style>