Browse Source

fix(登录): 修复登录逻辑并优化自动登录流程

修改登录action以支持loading状态和Promise返回
在App.vue中添加token检查自动登录逻辑
修复401错误时调用错误action的问题
移除服务日期未到的打卡限制
master
前端-胡立永 2 weeks ago
parent
commit
b209866cd3
5 changed files with 33 additions and 16 deletions
  1. +3
    -0
      App.vue
  2. +1
    -1
      pages/login/index.vue
  3. +9
    -9
      pages/myOrdersManage/components/timelineService.vue
  4. +19
    -5
      store/modules/user.js
  5. +1
    -1
      utils/request.js

+ 3
- 0
App.vue View File

@ -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')


+ 1
- 1
pages/login/index.vue View File

@ -82,7 +82,7 @@
icon:'none'
})
}
store.dispatch("login")
store.dispatch("login", true)
}


+ 9
- 9
pages/myOrdersManage/components/timelineService.vue View File

@ -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 = [


+ 19
- 5
store/modules/user.js View File

@ -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
},
// 已登录的情况下调用接口获取用户信息,保证用户信息的实时更新


+ 1
- 1
utils/request.js View File

@ -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'
})


Loading…
Cancel
Save