修复跳转问题

This commit is contained in:
kk
2026-07-10 16:20:00 +08:00
parent 3a154198e9
commit 20649c67a9
2 changed files with 71 additions and 6 deletions
+52 -5
View File
@@ -2,6 +2,11 @@
<view class="app-container"> <view class="app-container">
<!-- ========== 首页内容 ========== --> <!-- ========== 首页内容 ========== -->
<view v-if="currentTab === 'home'" class="page-content home-page"> <view v-if="currentTab === 'home'" class="page-content home-page">
<!-- 顶部标题栏 -->
<view class="page-header">
<text class="page-title">智能货柜{{ deviceId ? '-' + deviceId : '' }}</text>
</view>
<scroll-view <scroll-view
class="product-area" class="product-area"
scroll-y scroll-y
@@ -141,7 +146,7 @@
<!-- 底部左右箭头导航条 --> <!-- 底部左右箭头导航条 -->
<page-nav-bar <page-nav-bar
:hasPrev="true" :hasPrev="canGoBack"
:hasNext="false" :hasNext="false"
@prev="handleNavPrev" @prev="handleNavPrev"
@next="handleNavNext" @next="handleNavNext"
@@ -180,6 +185,7 @@ export default {
userInfo: { nickname: '', phone: '', avatar: '' }, userInfo: { nickname: '', phone: '', avatar: '' },
avatarClickCount: 0, avatarClickCount: 0,
avatarClickTimer: null, avatarClickTimer: null,
fromPage: '', // 记录从哪个页面跳转过来的
menuList: [ menuList: [
{ title: '我的订单', action: 'order' }, { title: '我的订单', action: 'order' },
{ title: '常见问题', action: 'faq' }, { title: '常见问题', action: 'faq' },
@@ -193,6 +199,10 @@ export default {
}; };
}, },
computed: { computed: {
canGoBack() {
// 有上一页,或者从 tab 切换过来的,都可以返回
return getCurrentPages().length > 1 || this.fromPage === 'tab';
},
maskedPhone() { maskedPhone() {
const p = this.userInfo.phone; const p = this.userInfo.phone;
return p ? p.substring(0,3) + '****' + p.substring(7) : ''; return p ? p.substring(0,3) + '****' + p.substring(7) : '';
@@ -224,14 +234,20 @@ export default {
// 支持通过 tab 参数切换到"我的"页面 // 支持通过 tab 参数切换到"我的"页面
if (options.tab === 'mine') { if (options.tab === 'mine') {
this.currentTab = 'mine'; this.currentTab = 'mine';
// 记录来源:从其他页面跳转过来的
this.fromPage = 'navigate';
} }
if (options.device_id) { if (options.device_id) {
this.deviceId = options.device_id; this.deviceId = options.device_id;
this.fetchProducts(); this.fetchProducts();
} else if (!options.tab) { } else if (!options.tab) {
// 无设备编号且非 tab 跳转,跳回扫码页 // 无设备编号且非 tab 跳转,提示并跳至扫码页
uni.redirectTo({ url: '/pages/index/scan' }); uni.showToast({ title: '请扫描设备二维码', icon: 'none' });
setTimeout(() => {
uni.redirectTo({ url: '/pages/index/scan' });
}, 1500);
return;
} }
// 加载缓存的用户信息 // 加载缓存的用户信息
@@ -253,6 +269,10 @@ export default {
// 切换到"我的"Tab 时检查登录 // 切换到"我的"Tab 时检查登录
if (tab === 'mine' && !checkLoginWithPrompt('mine')) return; if (tab === 'mine' && !checkLoginWithPrompt('mine')) return;
this.currentTab = tab; this.currentTab = tab;
// 记录来源:从 tab 切换的
if (tab === 'mine') {
this.fromPage = 'tab';
}
}, },
switchCategory(cat) { this.activeCategory = cat; }, switchCategory(cat) { this.activeCategory = cat; },
getDisplayPrice(item) { getDisplayPrice(item) {
@@ -316,7 +336,16 @@ export default {
break; break;
} }
}, },
handleNavPrev() { this.currentTab = 'home'; }, handleNavPrev() {
if (this.fromPage === 'navigate') {
// 从其他页面 navigateTo 过来的,返回上一页
uni.navigateBack();
} else if (this.fromPage === 'tab') {
// 从首页 tab 切换过来的,切换回首页
this.currentTab = 'home';
}
// 其他情况不执行操作
},
handleNavNext() { uni.showToast({ title: '暂无下一页', icon: 'none' }); }, handleNavNext() { uni.showToast({ title: '暂无下一页', icon: 'none' }); },
handleAvatarClick() { handleAvatarClick() {
this.avatarClickCount++; this.avatarClickCount++;
@@ -348,7 +377,11 @@ export default {
uni.clearStorageSync(); uni.clearStorageSync();
uni.showToast({ title: '已退出登录', icon: 'success' }); uni.showToast({ title: '已退出登录', icon: 'success' });
setTimeout(() => { setTimeout(() => {
location.reload(); // 跳转到干净的URL,去掉code/state参数,避免重复使用旧code
const url = new URL(window.location.href);
url.searchParams.delete('code');
url.searchParams.delete('state');
window.location.href = url.toString();
}, 1000); }, 1000);
}, },
onVConsoleChange(e) { onVConsoleChange(e) {
@@ -371,6 +404,20 @@ page { height: 100%; background-color: #fff; }
/* ====== 首页样式 ====== */ /* ====== 首页样式 ====== */
.home-page { display: flex; flex-direction: column; height: 100%; } .home-page { display: flex; flex-direction: column; height: 100%; }
/* 顶部标题栏 */
.page-header {
padding: 24rpx 32rpx;
background-color: #fff;
border-bottom: 1rpx solid #f0f0f0;
}
.page-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.product-area { flex: 1; overflow-y: auto; height: 0; } .product-area { flex: 1; overflow-y: auto; height: 0; }
/* 热销商品标题 + 装饰 */ /* 热销商品标题 + 装饰 */
+19 -1
View File
@@ -101,7 +101,25 @@ export default {
methods: { methods: {
handleScan() { handleScan() {
// #ifdef H5 // #ifdef H5
uni.showToast({ title: 'H5 环境暂不支持扫码', icon: 'none' }); // 检测是否在微信环境
const isWechat = /MicroMessenger/i.test(navigator.userAgent);
if (isWechat) {
// 微信环境:拉起微信扫一扫
// 注意:需要后端配合引入微信 JS-SDK 并完成签名配置
uni.showToast({ title: '请使用微信扫一扫功能', icon: 'none' });
// 如果已配置微信 JS-SDK,可以使用:
// wx.scanQRCode({
// needResult: 1,
// scanType: ['qrCode', 'barCode'],
// success: (res) => {
// const result = res.resultStr;
// this.parseScanResult(result);
// }
// });
} else {
// 非微信环境
uni.showToast({ title: '请使用微信扫码或在小程序中打开', icon: 'none' });
}
// #endif // #endif
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN