488 lines
12 KiB
Vue
488 lines
12 KiB
Vue
<!-- 首页,支持店铺装修 -->
|
||
<template>
|
||
<s-layout title="首页" :showLeftButton="false" tabbar="/pages/index/index" navPreset="light">
|
||
<view class="pagesIndex">
|
||
<view class="index-header">
|
||
<view class="index-header__left">
|
||
<view class="index-header__title">优购商城</view>
|
||
<view class="index-header__subtitle">AI店铺 · 一人店铺 · 共建共享</view>
|
||
</view>
|
||
<view class="index-notice-btn" @click="goNotice"></view>
|
||
</view>
|
||
<view class="pageContent">
|
||
<view class="floating-search-wrap">
|
||
<view class="floating-search" @click="goSearch">
|
||
<view class="floating-search-left">
|
||
<image
|
||
class="floating-search-icon_333"
|
||
src="/static/icon/search1.png"
|
||
mode="scaleToFill"
|
||
/>
|
||
<view class="floating-search-placeholder">搜索想要的商品</view>
|
||
</view>
|
||
<view class="floating-search-btn">
|
||
<image
|
||
class="floating-search-icon_fff"
|
||
src="/static/icon/search1.png"
|
||
mode="scaleToFill"
|
||
/>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view class="pages">
|
||
<!-- <s-custom-navbarIndex /> -->
|
||
<s-banner
|
||
v-if="template?.components[0]?.property.items?.length"
|
||
:data="template.components[0].property"
|
||
:styles="template.components[0].property.style"
|
||
/>
|
||
<!-- 文字滚动 -->
|
||
<!-- <view class="noticeBar flex-center bg24 m-b-22" v-if="informText">
|
||
<image class="noticeImg shrink" src="/static/index/notice.png" mode="scaleToFill" />
|
||
<uni-notice-bar class="flex1" scrollable background-color="#ffffff" :text="informText"
|
||
color="#333333" :speed="100" />
|
||
</view> -->
|
||
<!-- <view class="ai-store-entry bg24" @click="goAiStore">ai店铺</view> -->
|
||
<!-- <view class="navList flex-center ju-between">
|
||
<view v-for="(v, i) in nav" :key="i" class="navItem flex-center flex-column" @click="go(v.url)">
|
||
<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: `${
|
||
activeList?.length === 1
|
||
? '100%'
|
||
: activeList?.length === 2
|
||
? 'calc((100% - 16rpx) / 2)'
|
||
: i === 0
|
||
? '100%'
|
||
: 'calc((100% - 16rpx) / 2)'
|
||
}`,
|
||
}"
|
||
v-for="(v, i) in activeList"
|
||
:key="i"
|
||
@click="go(v)"
|
||
>
|
||
<image :src="sheep.$url.cdn(v.bannerImage)" mode="scaleToFill" />
|
||
</view>
|
||
</view> -->
|
||
</view>
|
||
<view class="goodsIndex">
|
||
<goods :list="tagList" :defaultTabName="defaultTabName" v-if="tagList?.length" />
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</s-layout>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, computed } from 'vue';
|
||
import { onLoad, onShow, onPullDownRefresh } from '@dcloudio/uni-app';
|
||
import goods from '@/components/goods/goods.vue';
|
||
import sheep from '@/sheep';
|
||
import $share from '@/sheep/platform/share';
|
||
import * as api from '@/sheep/api/index/index';
|
||
const HOME_DEFAULT_TAB_STORAGE_KEY = 'home.goods.defaultTabName';
|
||
const defaultTabName = ref('');
|
||
let template = ref({
|
||
page: {
|
||
backgroundColor: '#F2F4F7',
|
||
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;
|
||
});
|
||
};
|
||
// 消息通知
|
||
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));
|
||
}
|
||
});
|
||
|
||
onShow(() => {
|
||
const next = uni.getStorageSync(HOME_DEFAULT_TAB_STORAGE_KEY);
|
||
defaultTabName.value = next ? String(next) : '';
|
||
if (next) uni.removeStorageSync(HOME_DEFAULT_TAB_STORAGE_KEY);
|
||
});
|
||
//跳转浏览器
|
||
const openExternal = (url) => {
|
||
if (!url) return;
|
||
if (typeof plus !== 'undefined' && plus.runtime && typeof plus.runtime.openURL === 'function') {
|
||
plus.runtime.openURL(url);
|
||
return;
|
||
}
|
||
if (typeof window !== 'undefined' && typeof window.open === 'function') {
|
||
window.open(url, '_blank');
|
||
return;
|
||
}
|
||
};
|
||
const go = (e) => {
|
||
// console.log(e);
|
||
if (!e.linkUrl) {
|
||
uni.showToast({
|
||
title: '功能开发中, 敬请期待',
|
||
icon: 'none',
|
||
});
|
||
return;
|
||
} else if (e.title === '华贸专区') {
|
||
openExternal(e.linkUrl);
|
||
} else {
|
||
uni.navigateTo({
|
||
url: e.linkUrl,
|
||
});
|
||
}
|
||
};
|
||
|
||
const goAiStore = () => {
|
||
uni.navigateTo({
|
||
url: '/pages/index/aiStore',
|
||
});
|
||
};
|
||
|
||
const goSearch = () => {
|
||
sheep.$router.go('/pages/public/search');
|
||
};
|
||
const goNotice = () => {
|
||
uni.showToast({
|
||
title: '功能开发中, 敬请期待',
|
||
icon: 'none',
|
||
});
|
||
};
|
||
|
||
// 下拉刷新
|
||
onPullDownRefresh(() => {
|
||
// sheep.$store('app').init();
|
||
getData();
|
||
setTimeout(function () {
|
||
uni.stopPullDownRefresh();
|
||
}, 1000);
|
||
});
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.pages {
|
||
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;
|
||
}
|
||
|
||
.ai-store-entry {
|
||
padding: 24rpx 28rpx;
|
||
margin-bottom: 22rpx;
|
||
border-radius: 24rpx;
|
||
font-size: 28rpx;
|
||
font-weight: 600;
|
||
color: #333333;
|
||
}
|
||
|
||
: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%;
|
||
}
|
||
}
|
||
}
|
||
.pagesIndex {
|
||
position: relative;
|
||
padding-top: 480rpx;
|
||
// background: linear-gradient(135deg, #2c8cfa 0%, #3d5efb 100%);
|
||
background-image: url('../../static/index/index_bg.jpeg');
|
||
background-size: 100% auto;
|
||
background-repeat: no-repeat;
|
||
background-position: center -20rpx;
|
||
.pageContent {
|
||
border-radius: 20rpx 20rpx 0 0;
|
||
position: relative;
|
||
padding-top: 50rpx;
|
||
background: #fff;
|
||
}
|
||
}
|
||
|
||
.index-header {
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
right: 0;
|
||
z-index: 20;
|
||
padding: calc(env(safe-area-inset-top) + 60rpx) 52rpx 0 52rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.index-header__left {
|
||
min-width: 0;
|
||
}
|
||
|
||
.index-header__title {
|
||
font-size: 44rpx;
|
||
line-height: 52rpx;
|
||
font-weight: 700;
|
||
color: #fff;
|
||
}
|
||
|
||
.index-header__subtitle {
|
||
margin-top: 10rpx;
|
||
font-size: 26rpx;
|
||
line-height: 34rpx;
|
||
color: rgba(255, 255, 255, 0.88);
|
||
}
|
||
|
||
.index-notice-btn {
|
||
position: relative;
|
||
width: 44rpx;
|
||
height: 44rpx;
|
||
background-image: url('/static/icon/ notice.png');
|
||
background-size: 100% 100%;
|
||
background-repeat: no-repeat;
|
||
background-position: center;
|
||
flex: 0 0 auto;
|
||
}
|
||
|
||
.floating-search-wrap {
|
||
position: absolute;
|
||
top: -50rpx;
|
||
left: 0;
|
||
width: 100%;
|
||
padding: 0 32rpx;
|
||
box-sizing: border-box;
|
||
z-index: 10;
|
||
}
|
||
.floating-search {
|
||
height: 88rpx;
|
||
width: 100%;
|
||
background: #ffffff;
|
||
border-radius: 88rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 0 14rpx 0 22rpx;
|
||
box-sizing: border-box;
|
||
box-shadow: 0 8rpx 22rpx rgba(38, 107, 246, 0.55);
|
||
}
|
||
.floating-search-left {
|
||
display: flex;
|
||
align-items: center;
|
||
min-width: 0;
|
||
}
|
||
.floating-search-dot {
|
||
width: 28rpx;
|
||
height: 28rpx;
|
||
border-radius: 28rpx;
|
||
border: 4rpx solid #ffffff;
|
||
background: #ffffff;
|
||
box-sizing: border-box;
|
||
flex-shrink: 0;
|
||
}
|
||
.floating-search-placeholder {
|
||
margin-left: 16rpx;
|
||
color: #b8bcc6;
|
||
font-size: 28rpx;
|
||
white-space: nowrap;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
}
|
||
.floating-search-btn {
|
||
width: 64rpx;
|
||
height: 64rpx;
|
||
border-radius: 64rpx;
|
||
padding: 0 20rpx;
|
||
background: linear-gradient(135deg, var(--primary-grad-start) 0%, var(--primary-grad-end) 100%);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
}
|
||
.floating-search-icon_fff {
|
||
width: 42rpx;
|
||
height: 42rpx;
|
||
filter: brightness(0) invert(1);
|
||
}
|
||
.floating-search-icon_333 {
|
||
width: 32rpx;
|
||
height: 32rpx;
|
||
}
|
||
</style>
|