This commit is contained in:
HongRun Liu
2026-05-26 15:52:30 +08:00
commit b0744c8ab6
849 changed files with 130587 additions and 0 deletions
+384
View File
@@ -0,0 +1,384 @@
<!-- 首页,支持店铺装修 -->
<template>
<s-layout
title="首页"
:bgStyle="template.page"
:navbarStyle="template.navigationBar"
onShareAppMessage
>
<mescroll-body
:sticky="true"
@init="mescrollInit"
@down="downCallback"
@up="upCallback"
@scroll="scroll"
>
<s-custom-navbarIndex></s-custom-navbarIndex>
<view class="pages">
<view class="pages_top">
<s-banner
v-if="template.components[0].property.items.length"
:data="template.components[0].property"
:styles="template.components[0].property.style"
></s-banner>
<!-- 文字滚动 -->
<view class="noticeBar flex-center" v-if="informText">
<image class="noticeImg shrink" src="/static/index/notice.png" mode="scaleToFill" />
<uni-notice-bar
class="flex1"
scrollable
background-color="#fff"
:text="informText"
color="#535353"
:speed="100"
/>
</view>
<view class="navList flex-center ju-between">
<view v-for="(v, i) in nav" :key="i" class="navItem flex-center flex-column">
<image class="navImg shrink" :src="`/static/index/${v.icon}`" mode="scaleToFill" />
<view class="size26 f500">{{ v.title }}</view>
</view>
</view>
<view class="activeList flex-row wrap ju-between" v-if="activeList?.length">
<view
class="activeItem"
:style="{
height: 160 + 'rpx',
width: `calc((100% - 10rpx) / ${activeCol} - 10rpx)`,
}"
v-for="(v, i) in activeList"
:key="i"
>
<image :src="sheep.$url.cdn(v.bannerImage)" mode="aspectFill" />
</view>
</view>
</view>
<!-- 商品列表 -->
<view
class="sticky-tabs"
:style="{
top: '44px',
}"
>
<view class="navs flex-center ju-flex-start">
<view
class="navItem flex-center flex-column"
:class="{ tabIndex: i == tabIndex }"
v-for="(v, i) in tagList"
:key="i"
@click="navChange(i)"
>
<view class="navText">
{{ v.name }}
</view>
<image src="/static/index/active.png" mode="scaleToFill" />
</view>
</view>
</view>
<view>
<view class="cardItem" v-for="(v, i) in goods" :key="i">
<card_goods :data="v"></card_goods>
</view>
</view>
</view>
</mescroll-body>
</s-layout>
</template>
<script setup>
import { ref, computed } from 'vue';
import { onLoad, onPageScroll, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
import sheep from '@/sheep';
import $share from '@/sheep/platform/share';
import * as api from '@/sheep/api/index/index';
import useMescroll from '@/uni_modules/mescroll-uni/hooks/useMescroll.js';
import SpuApi from '@/sheep/api/product/spu';
import card_goods from '@/components/goodsItem/card_goods.vue';
const { mescrollInit, downCallback, getMescroll } = useMescroll(onPageScroll, onReachBottom); // 调用mescroll的hook
// 隐藏原生tabBar
// uni.hideTabBar({
// fail: () => {},
// });
// let template = computed(() => sheep.$store('app').template?.home);
let template = ref({
page: {
backgroundColor: '#f5f5f5',
padding: '0 32rpx',
boxSiziong: 'border-box',
},
navigationBar: {},
components: [
{
id: 'Banner',
property: {
autoplay: true,
indicator: 'number',
interval: 3000,
circular: true,
indicatorDots: false,
indicatorColor: '#D6D6D6', //点颜色
indicatorActiveColor: '#FE4246', //当前点颜色
items: [],
style: {
bgType: 'color',
bgColor: '#fff',
margin: '12rpx 0rpx',
marginBottom: '42rpx',
borderRadius: '24rpx',
height: '240rpx',
},
bgColor: '',
bgType: 'color',
marginBottom: 8,
type: 'default',
},
},
],
});
let nav = ref([
{
icon: 'i1.png',
title: '大健康',
url: '',
},
{
icon: 'i2.png',
title: '大农业',
url: '',
},
{
icon: 'i3.png',
title: '大文旅',
url: '',
},
{
icon: 'i4.png',
title: '本地生活',
url: '',
},
{
icon: 'i5.png',
title: '数据处理',
url: '',
},
{
icon: 'i6.png',
title: '跨境电商',
url: '',
},
]);
const getBanner = () => {
api
.getbannerlist({
position: 1,
})
.then((res) => {
let data = res.data;
template.value.components[0].property.items = data;
});
};
// 商品标签列表
let tagList = ref([]);
const getproducttaglist = () => {
api
.getproducttaglist({
categoryId: 1,
})
.then((res) => {
tagList.value = res.data;
navChange(0);
});
};
// 消息通知
let informText = ref('');
const getnotification = () => {
api.getnotification({}).then((res) => {
if (res?.code != 0) {
let data = res.data;
if (!data?.length) return;
// 拼接文案content
informText.value = data.map((item) => item.content).join(' ');
}
});
};
// 活动banner
let activeList = ref([]);
// 列数
let activeCol = ref(2);
const getappbanner = () => {
api.getappbanner({}).then((res) => {
if (res.data) {
activeList.value = res.data.list;
activeCol.value = res.data.bannerDisplayNum;
}
});
};
const getData = () => {
// banner
getBanner();
// 标签列表
getproducttaglist();
getnotification();
getappbanner();
};
onLoad((options) => {
getData();
// #ifdef MP
// 小程序识别二维码
if (options.scene) {
const sceneParams = decodeURIComponent(options.scene).split('=');
options[sceneParams[0]] = sceneParams[1];
}
// #endif
// 预览模板
if (options.templateId) {
sheep.$store('app').init(options.templateId);
}
// 解析分享信息
if (options.spm) {
$share.decryptSpm(options.spm);
}
// 进入指定页面(完整页面路径)
if (options.page) {
sheep.$router.go(decodeURIComponent(options.page));
}
});
// 下拉刷新
onPullDownRefresh(() => {
// sheep.$store('app').init();
getData();
setTimeout(function () {
uni.stopPullDownRefresh();
}, 1000);
});
onPageScroll(() => {});
/**
* 底部商品管理
*/
const tabIndex = ref(0);
let navId = ref(null);
let goods = ref([]);
const navChange = (i) => {
tabIndex.value = i;
navId.value = tagList.value[i].id;
};
const scroll = (e) => {
//console.log(e);
};
const upCallback = (mescroll) => {
if (navId.value)
SpuApi.getSpuPage({
pageNo: mescroll.num,
pageSize: mescroll.size,
tagTypeId: navId.value,
})
.then((res) => {
const list = res.data.list || []; // 当前页数据
// if(list.length){
// list.forEach(e=>{
// e.hide = true
// })
// }
if (mescroll.num == 1) goods.value = []; //如果是第一页需手动制空列表
goods.value = goods.value.concat(list); //追加新数据
mescroll.endSuccess(list.length); // 请求成功, 结束加载
})
.catch(() => {
mescroll.endErr(); // 请求失败, 结束加载
});
mescroll.endErr(); // 请求失败, 结束加载
};
</script>
<style scoped lang="scss">
.pages {
}
.pages_top {
padding: 0 32rpx;
box-sizing: border-box;
}
.noticeBar {
background-color: #fff;
border-radius: 12rpx;
overflow: hidden;
padding-left: 12rpx;
box-sizing: border-box;
}
.noticeImg {
width: 52rpx;
height: 52rpx;
}
:deep(.uni-noticebar) {
height: 92rpx;
border-radius: 12rpx;
overflow: hidden;
margin: 0;
font-weight: 500;
}
.navList {
margin-top: 40rpx;
margin-bottom: 52rpx;
.navItem {
width: 120rpx;
}
.navImg {
width: 84rpx;
height: 84rpx;
margin-bottom: 12rpx;
}
}
/* .noticeBar{
border-radius: 12rpx;
overflow: hidden;
} */
.activeList {
.activeItem {
// width: calc((100% - 10rpx) / 2 - 10rpx);
margin-bottom: 16rpx;
image {
width: 100%;
height: 100%;
}
}
}
.sticky-tabs {
z-index: 990;
position: sticky;
}
.navs {
padding: 0 32rpx;
box-sizing: border-box;
.navItem {
color: #777777;
font-size: 24rpx;
width: 20%;
// text-align: center;
image {
width: 40rpx;
height: 12rpx;
opacity: 0;
margin-top: 12rpx;
}
}
.tabIndex {
color: #333333;
font-size: 32rpx;
font-weight: 500;
image {
opacity: 1;
}
}
}
</style>