fix(login): streamline badge login flow and router exit handling
This commit is contained in:
parent
992d556083
commit
8ec1cf70b5
@ -19,8 +19,6 @@ const router = createRouter({
|
|||||||
}) => {
|
}) => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 3: // APP退出应用
|
case 3: // APP退出应用
|
||||||
|
|
||||||
case 2:
|
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
router.$lockStatus = false;
|
router.$lockStatus = false;
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
@ -34,6 +32,9 @@ const router = createRouter({
|
|||||||
});
|
});
|
||||||
// #endif
|
// #endif
|
||||||
break;
|
break;
|
||||||
|
case 2:
|
||||||
|
router.$lockStatus = false;
|
||||||
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
router.$lockStatus = false;
|
router.$lockStatus = false;
|
||||||
break;
|
break;
|
||||||
@ -88,14 +89,13 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("没有用户信息");
|
console.log("没有用户信息");
|
||||||
await store.dispatch('getUserInfo');
|
|
||||||
console.log("获取完成,去哪里",to)
|
|
||||||
try {
|
try {
|
||||||
|
await store.dispatch('getUserInfo');
|
||||||
|
console.log("获取完成,去哪里",to)
|
||||||
await store.dispatch('floatWindowManager/is_visible');
|
await store.dispatch('floatWindowManager/is_visible');
|
||||||
// 关键修改:等待获取用户信息
|
if (to.path === '/pages/index/index') {
|
||||||
if (to.path === '/pages/index/index'){
|
|
||||||
next();
|
next();
|
||||||
}else{
|
} else {
|
||||||
next({
|
next({
|
||||||
path: to.fullPath,
|
path: to.fullPath,
|
||||||
NAVTYPE: 'SwitchTab'
|
NAVTYPE: 'SwitchTab'
|
||||||
@ -103,6 +103,10 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await store.dispatch('logout');
|
await store.dispatch('logout');
|
||||||
|
next({
|
||||||
|
path: '/pages/login/index',
|
||||||
|
replace: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,8 @@ const actions = {
|
|||||||
});
|
});
|
||||||
dispatch('logout');
|
dispatch('logout');
|
||||||
console.log("无权登录");
|
console.log("无权登录");
|
||||||
return false;
|
reject({ msg: '无权登录' });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = data
|
const user = data
|
||||||
@ -188,8 +189,8 @@ const actions = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
loginByCode({
|
loginByCode({
|
||||||
commit,
|
state,
|
||||||
state
|
dispatch
|
||||||
}, payload) {
|
}, payload) {
|
||||||
const code = String(payload?.code || payload?.uuid || '').trim();
|
const code = String(payload?.code || payload?.uuid || '').trim();
|
||||||
|
|
||||||
@ -203,7 +204,7 @@ const actions = {
|
|||||||
code,
|
code,
|
||||||
device: state.app.device,
|
device: state.app.device,
|
||||||
project: state.app.project
|
project: state.app.project
|
||||||
}).then(response => {
|
}).then(async response => {
|
||||||
if (response && response.flag === 'failure') {
|
if (response && response.flag === 'failure') {
|
||||||
reject({ msg: response.message || '工牌登录失败' });
|
reject({ msg: response.message || '工牌登录失败' });
|
||||||
return;
|
return;
|
||||||
@ -217,12 +218,24 @@ const actions = {
|
|||||||
response?.data?.accessToken ||
|
response?.data?.accessToken ||
|
||||||
response?.accessToken;
|
response?.accessToken;
|
||||||
|
|
||||||
if (!token) {
|
const authToken = token || getToken();
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
reject({ msg: response?.message || '登录成功但未返回token' });
|
reject({ msg: response?.message || '登录成功但未返回token' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setToken(token);
|
if (token) {
|
||||||
|
setToken(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await dispatch('getUserInfo', authToken);
|
||||||
|
} catch (e) {
|
||||||
|
reject({ msg: e?.msg || e?.message || '用户信息加载失败' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
resolve(response);
|
resolve(response);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject({ msg: error?.msg || error?.message || error?.data?.message || '工牌登录失败' });
|
reject({ msg: error?.msg || error?.message || error?.data?.message || '工牌登录失败' });
|
||||||
|
|||||||
@ -33,21 +33,6 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 设备状态显示 -->
|
|
||||||
<view class="device-status" v-if="currentDevice">
|
|
||||||
<view class="status-card">
|
|
||||||
<view class="device-info">
|
|
||||||
<text class="device-name">{{ currentDevice.deviceName }}</text>
|
|
||||||
<text class="device-id">设备ID: {{ currentDevice.deviceId }}</text>
|
|
||||||
</view>
|
|
||||||
<u-button
|
|
||||||
type="primary"
|
|
||||||
text="确认登录"
|
|
||||||
size="small"
|
|
||||||
@click="confirmLogin"
|
|
||||||
></u-button>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 二维码登录弹窗 -->
|
<!-- 二维码登录弹窗 -->
|
||||||
@ -98,7 +83,6 @@ import {
|
|||||||
setToken,
|
setToken,
|
||||||
getToken
|
getToken
|
||||||
} from '@/core/utils/auth'
|
} from '@/core/utils/auth'
|
||||||
import { goHome } from '@/core/utils/auth-guard'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -128,6 +112,7 @@ export default {
|
|||||||
const storageBg = uni.getStorageSync("bg");
|
const storageBg = uni.getStorageSync("bg");
|
||||||
const bgUrl = storageBg || "/static/loginbg.jpg";
|
const bgUrl = storageBg || "/static/loginbg.jpg";
|
||||||
this.bgStyle = `--bg-url: url(${bgUrl})`;
|
this.bgStyle = `--bg-url: url(${bgUrl})`;
|
||||||
|
this.scanning = true;
|
||||||
uni.hideTabBar();
|
uni.hideTabBar();
|
||||||
this.$store.dispatch('broadcast/setCallbacks', {
|
this.$store.dispatch('broadcast/setCallbacks', {
|
||||||
onResult: this.handleBroadcastResult
|
onResult: this.handleBroadcastResult
|
||||||
@ -135,6 +120,7 @@ export default {
|
|||||||
this.$store.dispatch('broadcast/start');
|
this.$store.dispatch('broadcast/start');
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
|
this.scanning = true;
|
||||||
this.$store.dispatch('broadcast/resume');
|
this.$store.dispatch('broadcast/resume');
|
||||||
},
|
},
|
||||||
onHide() {
|
onHide() {
|
||||||
@ -276,8 +262,11 @@ export default {
|
|||||||
throw new Error('请先扫描有效工牌')
|
throw new Error('请先扫描有效工牌')
|
||||||
}
|
}
|
||||||
await this.$store.dispatch('loginByCode', { code })
|
await this.$store.dispatch('loginByCode', { code })
|
||||||
await goHome()
|
uni.switchTab({ url: '/pages/index/index' })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
this.scanning = true;
|
||||||
|
this.currentDevice = null;
|
||||||
|
this.$store.dispatch('broadcast/resume');
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: error?.msg || error?.message || '工牌认证登录失败',
|
title: error?.msg || error?.message || '工牌认证登录失败',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@ -304,9 +293,11 @@ export default {
|
|||||||
// 自动登录
|
// 自动登录
|
||||||
this.confirmLogin();
|
this.confirmLogin();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.scanning = true;
|
||||||
this.deviceCode = '';
|
this.deviceCode = '';
|
||||||
this.scanUuid = '';
|
this.scanUuid = '';
|
||||||
this.currentDevice = null;
|
this.currentDevice = null;
|
||||||
|
this.$store.dispatch('broadcast/resume');
|
||||||
uni.showToast({ title: e?.message || '扫码数据不合法', icon: 'none' });
|
uni.showToast({ title: e?.message || '扫码数据不合法', icon: 'none' });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user