From b7b8202e3ecb7f720eefd7a226b2ee8166fc5057 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期四, 04 六月 2026 14:57:17 +0800
Subject: [PATCH] 青岛移动端维护
---
App.vue | 180 ++++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 138 insertions(+), 42 deletions(-)
diff --git a/App.vue b/App.vue
index e4ebf7d..697eb66 100644
--- a/App.vue
+++ b/App.vue
@@ -1,66 +1,162 @@
<script setup>
-import { onLaunch } from '@dcloudio/uni-app'
-import { getToken } from '@/utils/auth'
-import { useUserStore } from '@/stores/user'
+import { onLaunch } from '@dcloudio/uni-app';
+import { getToken } from '@/utils/auth';
+import { useUserStore } from '@/stores/user';
-// 瀹氫箟椤甸潰鐧藉悕鍗� - 杩欎簺椤甸潰涓嶉渶瑕乼oken鏍¢獙
+// 瀹氫箟椤甸潰鐧藉悕鍗�
const pageWhiteList = [
'pages/login/Login',
'pages/login/DingTalkLogin'
-]
+];
-// 鏀硅繘鐨勭櫧鍚嶅崟妫�鏌ユ柟娉�
+// 鐧藉悕鍗曟鏌�
const isPageInWhiteList = (currentPage) => {
- return pageWhiteList.some(path => currentPage.includes(path))
+ return pageWhiteList.some(path => currentPage.includes(path));
}
-onLaunch(async () => {
- console.log('App Launch')
+// 鍏ㄥ眬鏍囪
+let isProcessingSSO = false;
+
+onLaunch(() => {
+ console.log('App Launch');
- const userStore = useUserStore()
+ const launchOptions = uni.getLaunchOptionsSync();
+ const currentPage = launchOptions.path || '';
+ const query = launchOptions.query || {};
+ console.log('鍚姩鍙傛暟:', { currentPage, query, launchOptions });
+
+ // 鉁� 绗竴姝ワ細妫�鏌ユ槸鍚SO閾炬帴
+ if (query.userName && query.passWord) {
+ console.log('妫�娴嬪埌SSO鍙傛暟锛屽鐞嗕腑...');
+
+ // 濡傛灉宸茬粡鍦ㄧ櫥褰曢〉锛岀洿鎺ュ鐞�
+ if (currentPage.includes('login/Login')) {
+ console.log('褰撳墠宸插湪鐧诲綍椤碉紝绛夊緟login.vue澶勭悊SSO');
+ return;
+ }
+
+ // 闃叉閲嶅澶勭悊
+ if (isProcessingSSO) {
+ console.log('姝e湪澶勭悊SSO涓紝璺宠繃');
+ return;
+ }
+
+ isProcessingSSO = true;
+
+ // 鉁� 鏋勫缓鐧诲綍椤礥RL锛屾惡甯︽墍鏈夊師濮嬪弬鏁�
+ const queryParams = [];
+
+ // 鎼哄甫鍘熷椤甸潰璺緞
+ if (currentPage) {
+ queryParams.push(`redirect=${encodeURIComponent('/' + currentPage)}`);
+ }
+
+ // 鎼哄甫鎵�鏈夋煡璇㈠弬鏁�
+ for (const key in query) {
+ if (query[key]) {
+ queryParams.push(`${key}=${encodeURIComponent(query[key])}`);
+ }
+ }
+
+ console.log('璺宠浆鍒扮櫥褰曢〉锛屽弬鏁�:', queryParams);
+
+ // 寤惰繜璺宠浆锛岄伩鍏嶅啿绐�
+ setTimeout(() => {
+ uni.redirectTo({
+ url: `/pages/login/Login?${queryParams.join('&')}`,
+ success: () => {
+ console.log('SSO璺宠浆鎴愬姛');
+ isProcessingSSO = false;
+ },
+ fail: () => {
+ console.log('SSO璺宠浆澶辫触');
+ isProcessingSSO = false;
+ }
+ });
+ }, 200);
+
+ return;
+ }
+
+ // 绗簩姝ワ細姝e父token妫�鏌�
+ handleTokenCheck();
+});
+
+// token妫�鏌ュ嚱鏁�
+const handleTokenCheck = async () => {
+ const userStore = useUserStore();
+ const token = getToken();
+ const launchOptions = uni.getLaunchOptionsSync();
+ const currentPage = launchOptions.path || '';
+ const query = launchOptions.query || {};
+
+ console.log('token妫�鏌�:', {
+ hasToken: !!token,
+ currentPage,
+ query
+ });
+
+ // 濡傛灉鏈塖SO鍙傛暟锛屽凡鍦ㄤ笂涓�姝ュ鐞�
+ if (query.userName && query.passWord) {
+ return;
+ }
+
+ if (!token) {
+ if (!isPageInWhiteList(currentPage)) {
+ console.log('鏃爐oken涓斾笉鍦ㄧ櫧鍚嶅崟锛岃烦杞櫥褰曢〉');
+
+ // 鏋勫缓璺宠浆URL锛屾惡甯﹀綋鍓嶉〉闈俊鎭�
+ let loginUrl = '/pages/login/Login';
+ if (currentPage) {
+ const queryParams = [];
+ queryParams.push(`redirect=${encodeURIComponent('/' + currentPage)}`);
+
+ // 鎼哄甫鍏朵粬鍙傛暟
+ for (const key in query) {
+ if (query[key]) {
+ queryParams.push(`${key}=${encodeURIComponent(query[key])}`);
+ }
+ }
+
+ if (queryParams.length > 0) {
+ loginUrl += `?${queryParams.join('&')}`;
+ }
+ }
+
+ setTimeout(() => {
+ uni.redirectTo({ url: loginUrl });
+ }, 100);
+ }
+ return;
+ }
try {
- const token = getToken()
- const launchOptions = uni.getLaunchOptionsSync()
- const currentPage = launchOptions.path || ''
- console.log(launchOptions);
- console.log(launchOptions.path);
+ const current = await uni.$uapi.get("/getInfo");
- if (!token) {
- if (!isPageInWhiteList(currentPage)) {
- console.log('鏈�氳繃鐧藉悕鍗曡烦杞櫥褰曢〉')
- return uni.redirectTo({ url: '/pages/login/Login' })
- }
- return
- }
-
- // 鏍¢獙token鏈夋晥鎬э細閫氳繃璋冪敤/current/user/current_roles鎺ュ彛
- const current = await uni.$uapi.get("/getInfo");
-
- // 濡傛灉鎺ュ彛杩斿洖鎴愬姛锛岃鏄巘oken鏈夋晥锛岀户缁幏鍙栫敤鎴蜂俊鎭�
- if (current) {
- // const resuser = await uni.$uapi.get("/system/user/profile");
+ if (current && current.user) {
userStore.setUserInfo(current.user);
- userStore.setroleKey(current.roles);
+ if (current.roles) {
+ userStore.setroleKey(current.roles);
+ }
- // 濡傛灉褰撳墠鏄櫥褰曢〉锛岃烦杞椤�
if (isPageInWhiteList(currentPage)) {
- uni.switchTab({ url: '/pages/index/index' })
+ uni.switchTab({ url: '/pages/index/index' });
}
} else {
- // 鎺ュ彛杩斿洖浣嗚鑹蹭俊鎭负绌猴紝瑙嗕负token鏃犳晥
- console.error('瑙掕壊淇℃伅鑾峰彇澶辫触锛宼oken鍙兘鏃犳晥')
- userStore.clearUser() // 娓呴櫎鏈湴鐢ㄦ埛淇℃伅
- uni.redirectTo({ url: '/pages/login/Login' })
+ console.error('token鏃犳晥');
+ userStore.clearUser();
+ if (!isPageInWhiteList(currentPage)) {
+ uni.redirectTo({ url: '/pages/login/Login' });
+ }
}
-
} catch (error) {
- console.error('鍒濆鍖栧け璐�:', error)
- // token鏃犳晥鎴栧叾浠栭敊璇紝娓呴櫎鏈湴鐢ㄦ埛淇℃伅骞惰烦杞櫥褰曢〉
- userStore.clearUser()
- uni.redirectTo({ url: '/pages/login/Login' })
+ console.error('鍒濆鍖栧け璐�:', error);
+ userStore.clearUser();
+ if (!isPageInWhiteList(currentPage)) {
+ uni.redirectTo({ url: '/pages/login/Login' });
+ }
}
-})
+};
</script>
<style lang="scss">
--
Gitblit v1.9.3