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 | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 156 insertions(+), 21 deletions(-)
diff --git a/App.vue b/App.vue
index 30b3f4a..697eb66 100644
--- a/App.vue
+++ b/App.vue
@@ -1,35 +1,170 @@
<script setup>
-import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
-import { useI18n } from 'vue-i18n'
+import { onLaunch } from '@dcloudio/uni-app';
+import { getToken } from '@/utils/auth';
+import { useUserStore } from '@/stores/user';
-const { t } = useI18n()
+// 瀹氫箟椤甸潰鐧藉悕鍗�
+const pageWhiteList = [
+ 'pages/login/Login',
+ 'pages/login/DingTalkLogin'
+];
+
+// 鐧藉悕鍗曟鏌�
+const isPageInWhiteList = (currentPage) => {
+ return pageWhiteList.some(path => currentPage.includes(path));
+}
+
+// 鍏ㄥ眬鏍囪
+let isProcessingSSO = false;
onLaunch(() => {
- console.log('App Launch')
- try {
- const currentLang = uni.getStorageSync('language')
- console.log('褰撳墠璇█:', currentLang)
- } catch (error) {
- console.error('璇█閰嶇疆閿欒:', error)
- }
-})
+ console.log('App Launch');
+
+ 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();
+});
-onShow(() => {
- console.log('App Show')
-})
-
-onHide(() => {
- console.log('App Hide')
-})
+// 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 current = await uni.$uapi.get("/getInfo");
+
+ if (current && current.user) {
+ userStore.setUserInfo(current.user);
+ if (current.roles) {
+ userStore.setroleKey(current.roles);
+ }
+
+ if (isPageInWhiteList(currentPage)) {
+ uni.switchTab({ url: '/pages/index/index' });
+ }
+ } else {
+ console.error('token鏃犳晥');
+ userStore.clearUser();
+ if (!isPageInWhiteList(currentPage)) {
+ uni.redirectTo({ url: '/pages/login/Login' });
+ }
+ }
+ } catch (error) {
+ console.error('鍒濆鍖栧け璐�:', error);
+ userStore.clearUser();
+ if (!isPageInWhiteList(currentPage)) {
+ uni.redirectTo({ url: '/pages/login/Login' });
+ }
+ }
+};
</script>
<style lang="scss">
@import "@/uni_modules/uview-plus/index.scss";
-
// 涓婚棰滆壊
-$primary-color: #0f95b0;
+$primary-color: #67AFAB;
$primary-light: rgba($primary-color, 0.1);
-$primary-gradient: linear-gradient(135deg, #0f95b0, #89C4C1);
+$primary-gradient: linear-gradient(135deg, #67AFAB, #89C4C1);
// 鏂囧瓧棰滆壊
$text-primary: #333333;
--
Gitblit v1.9.3