feat: banner跳转ai店铺判断

This commit is contained in:
2026-06-08 17:34:23 +08:00
parent 7752c4efa5
commit 5551b08d5a
7 changed files with 186 additions and 17 deletions
+88 -1
View File
@@ -176,6 +176,30 @@
import aistore_tab1 from './components/aistore_tab1.vue';
import aistore_tab2 from './components/aistore_tab2.vue';
const HOME_DEFAULT_TAB_STORAGE_KEY = 'home.goods.defaultTabName';
const aiShopStatus = ref({
value: null,
checkedAt: 0,
});
const ensureAiShopOpened = async () => {
const now = Date.now();
if (aiShopStatus.value.value !== null && now - aiShopStatus.value.checkedAt < 60 * 1000) {
return Boolean(aiShopStatus.value.value);
}
const res = await api.checkShopStatus({});
if (res?.code !== 0) {
throw new Error('checkShopStatus_failed');
}
const opened = Boolean(res?.data);
aiShopStatus.value = {
value: opened ? 1 : 0,
checkedAt: now,
};
return opened;
};
const searchText = ref('');
const search = () => {
@@ -232,7 +256,70 @@
}
});
onShow(() => {
onShow(async () => {
try {
const opened = await ensureAiShopOpened();
if (!opened) {
const message = '您尚未开通AI店铺,无法查看购物车。请先开通AI店铺后再进行购买。';
uni.setStorageSync(HOME_DEFAULT_TAB_STORAGE_KEY, '会员优选');
uni.switchTab({
url: '/pages/index/index',
success: () => {
setTimeout(() => {
uni.showToast({
title: message,
icon: 'none',
duration: 2500,
});
}, 50);
},
fail: () => {
uni.reLaunch({
url: '/pages/index/index',
success: () => {
setTimeout(() => {
uni.showToast({
title: message,
icon: 'none',
duration: 2500,
});
}, 50);
},
});
},
});
return;
}
} catch (e) {
const message = '系统繁忙,请稍后重试';
uni.switchTab({
url: '/pages/index/index',
success: () => {
setTimeout(() => {
uni.showToast({
title: message,
icon: 'none',
duration: 2500,
});
}, 50);
},
fail: () => {
uni.reLaunch({
url: '/pages/index/index',
success: () => {
setTimeout(() => {
uni.showToast({
title: message,
icon: 'none',
duration: 2500,
});
}, 50);
},
});
},
});
return;
}
getSpuTimeList();
getCartList();
getMessageList();
+12 -4
View File
@@ -50,7 +50,7 @@
</view>
</view> -->
<!-- 暂时废弃 -->
<view class="activeList flex-row wrap ju-between" v-if="activeList?.length">
<!-- <view class="activeList flex-row wrap ju-between" v-if="activeList?.length">
<view
class="activeItem"
:style="{
@@ -71,10 +71,10 @@
>
<image :src="sheep.$url.cdn(v.bannerImage)" mode="scaleToFill" />
</view>
</view>
</view> -->
</view>
<view class="goodsIndex">
<goods :list="tagList" v-if="tagList?.length" />
<goods :list="tagList" :defaultTabName="defaultTabName" v-if="tagList?.length" />
</view>
</view>
</view>
@@ -83,11 +83,13 @@
<script setup>
import { ref, computed } from 'vue';
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app';
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',
@@ -235,6 +237,12 @@
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;