feat: 点底部 tab 的“AI店铺”时没开通就不跳转并提示

This commit is contained in:
2026-06-05 16:30:30 +08:00
parent a1c5dd5514
commit e271764292
3 changed files with 61 additions and 6 deletions
+45 -1
View File
@@ -31,6 +31,7 @@
<script setup>
import { computed, ref, watch } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import * as AiApi from '@/sheep/api/ai/index';
const props = defineProps({
path: {
@@ -120,13 +121,56 @@
return isActive(item) ? item.selectedIconPath : item.iconPath;
};
const onTap = (item) => {
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 AiApi.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 onTap = async (item) => {
if (item.isMid) {
hideNativeTabBar();
uni.navigateTo({ url: item.pagePath });
return;
}
if (isActive(item)) return;
if (normalizePath(item.pagePath) === '/pages/index/aiStore') {
try {
const opened = await ensureAiShopOpened();
if (!opened) {
uni.showToast({
title: '您尚未开通AI店铺,无法查看购物车。请先开通AI店铺后再进行购买。',
icon: 'none',
duration: 2500,
});
return;
}
} catch (e) {
uni.showToast({
title: '系统繁忙,请稍后重试',
icon: 'none',
});
return;
}
}
hideNativeTabBar();
uni.switchTab({
url: item.pagePath,