一体机的登录修复

This commit is contained in:
francis-fh
2026-06-04 14:45:22 +08:00
parent bdd42bd790
commit 087c686d81
3 changed files with 65 additions and 32 deletions

View File

@@ -5,6 +5,9 @@
import useUserStore from '@/stores/useUserStore';
/** 一体机 H5 首页地址 */
export const MACHINE_HOME_URL = 'https://www.xjksly.cn/mechine-single-vue/';
/**
* 检查当前平台类型
* @returns {string} 平台类型:'mp-weixin' | 'h5' | 'app'
@@ -88,21 +91,64 @@ export function navigateToLoginPage(options = {}) {
}
}
/**
* 检查用户是否已登录
* @returns {boolean}
*/
export function isUserLoggedIn() {
const userStore = useUserStore();
const tokenValue = uni.getStorageSync('token') || '';
return !!(tokenValue && userStore.hasLogin);
}
/**
* H5 一体机端:弹窗提示登录,点击确定跳转一体机首页
* @param {Object} options
* @param {string} options.content 提示文案
* @returns {Promise<boolean>} 用户是否点击确定
*/
export function promptH5MachineLogin(options = {}) {
const { content = '您还未登录,请先登录' } = options;
return new Promise((resolve) => {
uni.showModal({
title: '提示',
content,
showCancel: true,
cancelText: '取消',
confirmText: '确定',
success: (res) => {
if (res.confirm) {
// #ifdef H5
window.location.href = MACHINE_HOME_URL;
// #endif
resolve(true);
} else {
resolve(false);
}
},
fail: () => resolve(false),
});
});
}
/**
* 检查登录状态,如果未登录则跳转到对应登录页面
* @param {Object} options 选项
* @param {string} options.redirectUrl 登录成功后跳转的URL
* @param {string} options.loginType 登录类型
* @param {string} options.content H5 一体机端登录提示文案
* @returns {boolean} 是否已登录
*/
export function checkLoginAndNavigate(options = {}) {
const userStore = useUserStore();
if (userStore.hasLogin) {
if (isUserLoggedIn()) {
return true;
}
// 未登录,跳转到对应登录页面
if (getPlatformType() === 'h5') {
promptH5MachineLogin(options);
return false;
}
navigateToLoginPage(options);
return false;
}
@@ -202,6 +248,9 @@ export default {
getPlatformType,
navigateToLoginPage,
checkLoginAndNavigate,
isUserLoggedIn,
promptH5MachineLogin,
MACHINE_HOME_URL,
parseIdCardLoginParams,
decodeIdCardBase64,
refreshWxLoginCode,