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
+2 -2
View File
@@ -15,7 +15,7 @@ SHOPRO_VERSION=v2.4.1
#SHOPRO_DEV_BASE_URL=http://192.168.101.58:48090
# 服务器
# SHOPRO_DEV_BASE_URL=http://www.qflyqzy.net:48090
SHOPRO_DEV_BASE_URL=http://www.qflyqzy.net:48090
#SHOPRO_DEV_BASE_URL=https://www.qflyqzy.net/yg-api
@@ -23,7 +23,7 @@ SHOPRO_VERSION=v2.4.1
# SHOPRO_DEV_BASE_URL=http://192.168.1.7:48080
# 测试环境
SHOPRO_DEV_BASE_URL=https://yougoutest.api.riananyoumu.com
# SHOPRO_DEV_BASE_URL=https://yougoutest.api.riananyoumu.com
# 本地
# SHOPRO_DEV_BASE_URL=http://8.136.55.200:48090
+28
View File
@@ -40,9 +40,14 @@
type: Array,
default: () => [],
},
defaultTabName: {
type: String,
default: '',
},
});
const hasPurchasedShop = ref(null);
const displayList = ref([]);
const hasAppliedDefaultTab = ref(false);
const computeDisplayList = () => {
const list = Array.isArray(props.list) ? props.list : [];
@@ -67,10 +72,24 @@
onReachBottom,
);
const applyDefaultTabIfNeeded = (list) => {
const target = String(props.defaultTabName || '').trim();
if (!target) return;
if (hasAppliedDefaultTab.value) return;
const index = (Array.isArray(list) ? list : []).findIndex(
(v) => String(v?.name || '').trim() === target,
);
if (index >= 0) {
tabIndex.value = index;
hasAppliedDefaultTab.value = true;
}
};
const refreshDisplay = () => {
const next = computeDisplayList();
displayList.value = next;
syncMescrollItems(next);
applyDefaultTabIfNeeded(next);
if (tabIndex.value >= next.length) tabIndex.value = 0;
};
@@ -96,6 +115,15 @@
},
{ immediate: true, deep: true },
);
watch(
() => props.defaultTabName,
() => {
hasAppliedDefaultTab.value = false;
applyDefaultTabIfNeeded(displayList.value);
},
{ immediate: true },
);
// let tabIndex = ref(0);
const navChange = (i) => {
// scrollToLastY()
+2 -2
View File
@@ -35,12 +35,12 @@
v-if="props.type == 1"
>
<view class="label" v-if="props.data.tagSaleName">{{ props.data.tagSaleName }}</view>
<view class="num">已售{{ props.data.salesCount }}</view>
<view class="num" v-if="!props.memberPreferred">已售{{ props.data.salesCount }}</view>
</view>
<view v-else-if="props.type == 2">
<view class="flex-center ju-between mt10 wrap">
<view class="num size26 m-r-4">{{ props.data.categoryText }}</view>
<view class="num">销量:{{ props.data.salesCount }}</view>
<view class="num" v-if="!props.memberPreferred">销量:{{ props.data.salesCount }}</view>
</view>
<view class="flex-row wrap" v-if="props.data.tagSaleName">
<view
+2 -2
View File
@@ -2,8 +2,8 @@
"name" : "优购商城",
"appid" : "__UNI__8B19741",
"description" : "",
"versionName" : "1.3.8",
"versionCode" : 138,
"versionName" : "1.3.9",
"versionCode" : 139,
"transformPx" : false,
"app-plus" : {
"privacy" : {
+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;
+52 -6
View File
@@ -37,8 +37,9 @@
</uni-swiper-dot>
</template>
<script setup lang="ts">
<script setup>
import { ref } from 'vue';
import * as AiApi from '@/sheep/api/ai/index';
let current = ref(0);
// 轮播图
const props = defineProps({
@@ -62,14 +63,59 @@
current.value = e.detail.current;
};
const go = (url, obj = {}) => {
const HOME_DEFAULT_TAB_STORAGE_KEY = 'home.goods.defaultTabName';
const parsePath = (raw) => {
const s = typeof raw === 'string' ? raw : '';
const [p] = s.split('?');
return p;
};
const go = async (url, obj = {}) => {
if (!url) {
uni.showToast({
title: '功能开发中, 敬请期待',
icon: 'none',
});
// uni.showToast({
// title: '功能开发中, 敬请期待',
// icon: 'none',
// });
return;
}
const path = parsePath(url);
if (path === '/pages/index/aiStore') {
try {
const res = await AiApi.checkShopStatus({});
const opened = res?.code === 0 ? Boolean(res?.data) : false;
if (!opened) {
const message =
'您尚未开通AI店铺,无法查看购物车。请先开通AI店铺后再进行购买。';
uni.setStorageSync(HOME_DEFAULT_TAB_STORAGE_KEY, '会员优选');
uni.showToast({
title: message,
icon: 'none',
duration: 2500,
});
setTimeout(() => {
uni.switchTab({
url: '/pages/index/index',
fail: () => {
uni.reLaunch({ url: '/pages/index/index' });
},
});
}, 1000);
return;
}
} catch (e) {
uni.showToast({
title: '系统繁忙,请稍后重试',
icon: 'none',
});
return;
}
uni.switchTab({ url: '/pages/index/aiStore' });
return;
}
uni.navigateTo({
url: url,
data: obj,