diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 740637f..b626e9c 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -2,6 +2,11 @@ + + + 智能货柜{{ deviceId ? '-' + deviceId : '' }} + + 1 || this.fromPage === 'tab'; + }, maskedPhone() { const p = this.userInfo.phone; return p ? p.substring(0,3) + '****' + p.substring(7) : ''; @@ -224,14 +234,20 @@ export default { // 支持通过 tab 参数切换到"我的"页面 if (options.tab === 'mine') { this.currentTab = 'mine'; + // 记录来源:从其他页面跳转过来的 + this.fromPage = 'navigate'; } if (options.device_id) { this.deviceId = options.device_id; this.fetchProducts(); } else if (!options.tab) { - // 无设备编号且非 tab 跳转,跳回扫码页 - uni.redirectTo({ url: '/pages/index/scan' }); + // 无设备编号且非 tab 跳转,提示并跳至扫码页 + uni.showToast({ title: '请扫描设备二维码', icon: 'none' }); + setTimeout(() => { + uni.redirectTo({ url: '/pages/index/scan' }); + }, 1500); + return; } // 加载缓存的用户信息 @@ -253,6 +269,10 @@ export default { // 切换到"我的"Tab 时检查登录 if (tab === 'mine' && !checkLoginWithPrompt('mine')) return; this.currentTab = tab; + // 记录来源:从 tab 切换的 + if (tab === 'mine') { + this.fromPage = 'tab'; + } }, switchCategory(cat) { this.activeCategory = cat; }, getDisplayPrice(item) { @@ -316,7 +336,16 @@ export default { 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' }); }, handleAvatarClick() { this.avatarClickCount++; @@ -348,7 +377,11 @@ export default { uni.clearStorageSync(); uni.showToast({ title: '已退出登录', icon: 'success' }); 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); }, onVConsoleChange(e) { @@ -371,6 +404,20 @@ page { height: 100%; background-color: #fff; } /* ====== 首页样式 ====== */ .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; } /* 热销商品标题 + 装饰 */ diff --git a/src/pages/index/scan.vue b/src/pages/index/scan.vue index 30dc544..55208e0 100644 --- a/src/pages/index/scan.vue +++ b/src/pages/index/scan.vue @@ -101,7 +101,25 @@ export default { methods: { handleScan() { // #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 // #ifdef MP-WEIXIN