From c809b1e0cd36186c36c0edda026a5899428dc125 Mon Sep 17 00:00:00 2001 From: davy Date: Tue, 8 Apr 2025 14:58:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=88=91=E7=9A=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=89=AB=E7=A0=81=E7=BB=9F=E8=AE=A1=E5=8D=A1?= =?UTF-8?q?=E7=89=87=201.=E8=B0=83=E6=95=B4=E6=A0=87=E9=A2=98=E5=92=8C?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E4=BD=8D=E7=BD=AE=202.=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E5=92=8C=E5=8D=95=E4=BD=8D=E5=B8=83=E5=B1=80?= =?UTF-8?q?=203.=E8=B0=83=E6=95=B4=E5=90=8C=E6=AF=94=E5=A2=9E=E9=95=BF?= =?UTF-8?q?=E6=96=87=E5=AD=97=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/my.vue | 321 ++++++++++++++++++++++++++++----------------- 1 file changed, 202 insertions(+), 119 deletions(-) diff --git a/pages/index/my.vue b/pages/index/my.vue index b2fdff3..d337794 100644 --- a/pages/index/my.vue +++ b/pages/index/my.vue @@ -47,11 +47,27 @@ - 本月累计扫码酒款数量 - - {{scanCount}} - - *击败全国0%认证门店 + + + + 本周累计扫码 + + + 20 + + + + + + 同比增长13.2% + + + + + + 欢迎加入啤啤猩球 + + @@ -164,15 +181,19 @@ }, data() { return { - userInfo: null, - loading: true, barInfo: null, myScanData: null, - statusBaeHeight: 40, + statusBaeHeight: 0, isLoggedIn: false, currentBrandIndex: 0, sortedBrandCoins: [], - scanCount: 0 + scanCount: 0, + userInfo: null, + // 扫码统计数据 + weekScanStats: { + total: 20, + weekGrowth: 13.2 + } }; }, computed: { @@ -204,65 +225,28 @@ }, methods: { // 检查登录状态 - async checkLoginStatus() { + checkLoginStatus() { try { - const token = uni.getStorageSync('token'); - const userInfo = uni.getStorageSync('userInfo'); + const token = getToken(); + const userInfo = getUserInfoFromAuth(); - // 检查token和userInfo是否有效 - if (!token || token.startsWith('temp_') || !userInfo) { + if (!token || !userInfo) { this.isLoggedIn = false; this.userInfo = null; - this.barInfo = null; - this.myScanData = null; - return false; + return; } this.isLoggedIn = true; this.userInfo = userInfo; - // 先获取酒吧信息 - await getBarInfo().then(res => { - if (res && res.data) { - this.barInfo = res.data; - // 如果是认证中状态,设置默认的扫码数据 - if (this.barInfo.authState === 2) { - this.myScanData = { scanCount: 0, percent: 0 }; - } - } - }).catch(err => { - console.error('获取酒吧信息失败:', err); - if (err.code === 500 && err.msg.includes('门店未认证')) { - this.barInfo = { - authState: 2, - barName: '', - barNumber: '', - barContactPhone: '' - }; - this.myScanData = { scanCount: 0, percent: 0 }; - } else { - this.barInfo = null; - } - }); + // 获取门店信息和扫码数据 + this.getBarInfo(); + this.getMyScanData(); - // 如果不是认证中状态,获取扫码数据 - if (this.barInfo && this.barInfo.authState !== 2) { - await getMyScanData().then(res => { - if (res.code === 200) { - this.myScanData = res.data; - } - }).catch(err => { - console.error('获取扫码数据失败:', err); - this.myScanData = { scanCount: 0, percent: 0 }; - }); - } - - return true; } catch (error) { console.error('检查登录状态失败:', error); - return false; - } finally { - this.loading = false; + this.isLoggedIn = false; + this.userInfo = null; } }, loginSuccess() { @@ -271,14 +255,23 @@ this.userInfo = getUserInfoFromAuth(); this.isLoggedIn = true; + // 显示加载提示 + uni.showLoading({ + title: '加载中...', + mask: true + }); + // 使用 Promise.all 同时获取所有需要的数据 Promise.all([ - this.getBarInfoFun(), - this.getMyScanDataFun() + this.getBarInfo(), + this.getMyScanData(), + this.getStoreCoinBalanceFun() ]).then(() => { console.log('所有数据更新完成'); // 强制更新视图 this.$forceUpdate(); + // 隐藏加载提示 + uni.hideLoading(); // 显示登录成功提示 uni.showToast({ title: '登录成功', @@ -287,6 +280,7 @@ }); }).catch(err => { console.error('数据更新失败:', err); + uni.hideLoading(); uni.showToast({ title: '数据更新失败', icon: 'none' @@ -294,51 +288,26 @@ }); }, // 获取酒吧信息 - getBarInfoFun() { - if (!this.isLoggedIn) { - console.log('用户未登录,不获取酒吧信息'); - return Promise.reject('未登录'); - } - - return getBarInfo().then(res => { - console.log('获取酒吧信息成功:', res); - if (res && res.data) { + async getBarInfo() { + try { + const res = await getBarInfo(); + if (res.code === 200) { this.barInfo = res.data; - // 强制更新视图 - this.$forceUpdate(); - return this.barInfo; - } else { - console.log('获取酒吧信息成功,但数据为空'); - this.barInfo = null; - return Promise.reject('数据为空'); } - }).catch(err => { - console.error('获取酒吧信息失败:', err); - this.barInfo = null; - return Promise.reject(err); - }); + } catch (error) { + console.error('获取门店信息失败:', error); + } }, // 获取我的扫码数据 - getMyScanDataFun() { - if (!this.isLoggedIn) { - return Promise.reject('未登录'); - } - - return getMyScanData().then(res => { + async getMyScanData() { + try { + const res = await getMyScanData(); if (res.code === 200) { this.myScanData = res.data; - return this.myScanData; - } else { - return Promise.reject(res); } - }).catch(err => { - console.error('获取扫码数据失败:', err); - uni.showToast({ - title: '获取扫码数据失败', - icon: 'none' - }); - return Promise.reject(err); - }); + } catch (error) { + console.error('获取扫码数据失败:', error); + } }, // 处理用户信息区域点击 handleUserBoxClick() { @@ -443,17 +412,31 @@ content: '确定要退出登录吗?', success: (res) => { if (res.confirm) { - // 清除本地存储的用户信息 clearLoginStatus(); - - // 跳转到首页 - uni.reLaunch({ - url: '/pages/index/index' + // 重置所有数据 + this.resetData(); + // 刷新页面状态 + this.checkLoginStatus(); + // 显示退出成功提示 + uni.showToast({ + title: '已退出登录', + icon: 'success', + duration: 1500 }); } } }); }, + // 重置数据方法 + resetData() { + this.barInfo = null; + this.myScanData = null; + this.isLoggedIn = false; + this.currentBrandIndex = 0; + this.sortedBrandCoins = []; + this.scanCount = 0; + this.userInfo = null; + }, // 关闭登录弹窗 closeLoginPopup() { this.$refs.loginRef.close(); @@ -466,11 +449,9 @@ }, // 跳转到设置页面 toSettings() { - if (this.userStatus === 'verified') { - uni.navigateTo({ - url: '/pagesMy/setting' - }) - } + uni.navigateTo({ + url: '/pagesMy/settings' + }); }, // 显示修改头像提示 @@ -615,8 +596,8 @@ // 获取啤酒币余额 async getStoreCoinBalanceFun() { try { - const token = uni.getStorageSync('token'); - const userInfo = uni.getStorageSync('userInfo'); + const token = getToken(); + const userInfo = getUserInfoFromAuth(); if (!token || !userInfo) { this.sortedBrandCoins = []; @@ -648,9 +629,15 @@ this.sortedBrandCoins = []; } } catch (error) { - console.error('获取啤酒币余额失败', error); + console.error('获取啤酒币余额失败:', error); this.sortedBrandCoins = []; } + }, + // 跳转到啤酒币页面 + toBeerCoin() { + uni.navigateTo({ + url: '/pagesCoin/beerCoin' + }); } } } @@ -659,7 +646,7 @@