From b209866cd305fcbd50f2abf21579d733f1dd2452 Mon Sep 17 00:00:00 2001 From: hly <2783385703@qq.com> Date: Tue, 26 Aug 2025 18:01:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=99=BB=E5=BD=95):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=80=BB=E8=BE=91=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=99=BB=E5=BD=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改登录action以支持loading状态和Promise返回 在App.vue中添加token检查自动登录逻辑 修复401错误时调用错误action的问题 移除服务日期未到的打卡限制 --- App.vue | 3 +++ pages/login/index.vue | 2 +- .../myOrdersManage/components/timelineService.vue | 18 ++++++++-------- store/modules/user.js | 24 +++++++++++++++++----- utils/request.js | 2 +- 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/App.vue b/App.vue index 1f54ccc..82f80f9 100644 --- a/App.vue +++ b/App.vue @@ -9,6 +9,9 @@ console.log('App Launch') store.dispatch('fetchConfigList') store.dispatch('getUserInfo') + if(uni.getStorageSync('token')){ + store.dispatch("login") + } }, onShow: function() { console.log('App Show') diff --git a/pages/login/index.vue b/pages/login/index.vue index ad0d663..9a28d62 100644 --- a/pages/login/index.vue +++ b/pages/login/index.vue @@ -82,7 +82,7 @@ icon:'none' }) } - store.dispatch("login") + store.dispatch("login", true) } diff --git a/pages/myOrdersManage/components/timelineService.vue b/pages/myOrdersManage/components/timelineService.vue index 49a867f..dcf4607 100644 --- a/pages/myOrdersManage/components/timelineService.vue +++ b/pages/myOrdersManage/components/timelineService.vue @@ -193,15 +193,15 @@ today.setHours(0, 0, 0, 0); serviceDate.setHours(0, 0, 0, 0); - if (serviceDate > today) { - // 服务日期未到,显示提示 - uni.showToast({ - title: '服务日期未到,无法打卡', - icon: 'none', - duration: 2000 - }); - return; - } + // if (serviceDate > today) { + // // 服务日期未到,显示提示 + // uni.showToast({ + // title: '服务日期未到,无法打卡', + // icon: 'none', + // duration: 2000 + // }); + // return; + // } // 根据订单状态确定跳转路径 const paths = [ diff --git a/store/modules/user.js b/store/modules/user.js index 5b1f890..0e8a1c0 100644 --- a/store/modules/user.js +++ b/store/modules/user.js @@ -42,13 +42,25 @@ const user = { }, actions: { - login(context) { + login(context, loading) { + + let success = function(){} + let error = function(){} + let promise = new Promise((s, e) => { + success = s + error = e + }) + uni.login({ success: (res) => { const code = res.code - uni.showLoading({ - mask : true - }); + + if(loading){ + uni.showLoading({ + mask : true + }); + } + wxLogin({ code }).then(res => { @@ -59,7 +71,7 @@ const user = { context.commit('setUserInfo', res.data.userInfo); setIsLogin(true); uni.hideLoading(); - + success(res) if (!res.data.userInfo.userName || !res.data.userInfo.userImage || ! res.data.userInfo.userTelephone) { uni.navigateTo({ @@ -72,6 +84,8 @@ const user = { }) } }) + + return promise }, // 已登录的情况下调用接口获取用户信息,保证用户信息的实时更新 diff --git a/utils/request.js b/utils/request.js index 985bc50..57e4e1e 100644 --- a/utils/request.js +++ b/utils/request.js @@ -44,7 +44,7 @@ const request = config => { if (code === 401) { showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => { if (res.confirm) { - store.dispatch('LogOut').then(res => { + store.dispatch('login').then(res => { uni.reLaunch({ url: '/pages/index' })