From 05c363fdd7ab04e3bd9a753e2c5d5bfff04d681c Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期二, 09 六月 2026 10:21:35 +0800
Subject: [PATCH] 备份上传
---
App.vue | 196 ++++++++++++++++++++++++++++--------------------
1 files changed, 115 insertions(+), 81 deletions(-)
diff --git a/App.vue b/App.vue
index b4187e8..de31839 100644
--- a/App.vue
+++ b/App.vue
@@ -1,102 +1,144 @@
<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 pageWhiteList = ["pages/login/Login", "pages/login/DingTalkLogin"];
+const isPageInWhiteList = (currentPage) =>
+ pageWhiteList.some((path) => currentPage.includes(path));
-// 鏀硅繘鐨勭櫧鍚嶅崟妫�鏌ユ柟娉�
-const isPageInWhiteList = (currentPage) => {
- return pageWhiteList.some(path => currentPage.includes(path))
-}
+let isProcessingSSO = false;
-onLaunch(async () => {
- console.log('App Launch')
-
- const userStore = useUserStore()
-
- try {
- const token = getToken()
- const launchOptions = uni.getLaunchOptionsSync()
- const currentPage = launchOptions.path || ''
- console.log(launchOptions);
- console.log(launchOptions.path);
-
- if (!token) {
- if (!isPageInWhiteList(currentPage)) {
- console.log('鏈�氳繃鐧藉悕鍗曡烦杞櫥褰曢〉')
- return uni.redirectTo({ url: '/pages/login/Login' })
- }
- return
+onLaunch(() => {
+ console.log("App Launch");
+ const launchOptions = uni.getLaunchOptionsSync();
+ const currentPage = launchOptions.path || "";
+ const query = launchOptions.query || {};
+ console.log("鍚姩鍙傛暟:", { currentPage, query });
+
+ // 鉁� 鏀逛负妫�娴� code 鍙傛暟
+ if (query.code) {
+ console.log('妫�娴嬪埌鍏嶇櫥鐮�(code)锛屽噯澶囪烦杞櫥褰曢〉');
+ if (currentPage.includes('login/Login')) {
+ console.log('褰撳墠宸插湪鐧诲綍椤碉紝绛夊緟login.vue澶勭悊');
+ return;
}
-
- // 鏍¢獙token鏈夋晥鎬э細閫氳繃璋冪敤/current/user/current_roles鎺ュ彛
- const current = await uni.$uapi.get("/system/user/profile");
-
- // 濡傛灉鎺ュ彛杩斿洖鎴愬姛锛岃鏄巘oken鏈夋晥锛岀户缁幏鍙栫敤鎴蜂俊鎭�
- if (current ) {
- // const resuser = await uni.$uapi.get("/system/user/profile");
- userStore.setUserInfo(current);
- // userStore.setroleKey(current[0].roleKey);
-
- // 濡傛灉褰撳墠鏄櫥褰曢〉锛岃烦杞椤�
+ if (isProcessingSSO) return;
+ isProcessingSSO = true;
+ uni.__isSSOHandling = true;
+
+ const queryParams = [];
+ if (currentPage) {
+ queryParams.push(`redirect=${encodeURIComponent('/' + currentPage)}`);
+ }
+ // 鎼哄甫 code 鍙傛暟
+ queryParams.push(`code=${encodeURIComponent(query.code)}`);
+ // 娉ㄦ剰锛氬叾浠栦笟鍔″弬鏁帮紙濡� fcid锛夊凡涓嶅湪 URL 涓婏紝涓嶉渶瑕佹惡甯�
+
+ console.log('璺宠浆鍒扮櫥褰曢〉锛屽弬鏁�:', queryParams);
+ setTimeout(() => {
+ uni.redirectTo({
+ url: `/pages/login/Login?${queryParams.join('&')}`,
+ success: () => {
+ setTimeout(() => {
+ uni.__isSSOHandling = false;
+ isProcessingSSO = false;
+ }, 500);
+ },
+ fail: () => {
+ uni.__isSSOHandling = false;
+ isProcessingSSO = false;
+ }
+ });
+ }, 200);
+ return;
+ }
+
+ // 鍘熸湁 token 妫�鏌ラ�昏緫涓嶅彉锛堜絾娉ㄦ剰鍘绘帀 SSO 鍙傛暟鍒ゆ柇锛�
+ handleTokenCheck();
+});
+
+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 });
+
+
+ if (!token) {
+ if (!isPageInWhiteList(currentPage)) {
+ console.log("鏃爐oken涓斾笉鍦ㄧ櫧鍚嶅崟锛岃烦杞櫥褰曢〉");
+ 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' })
+ 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">
@import "@/uni_modules/uview-plus/index.scss";
-// 涓婚棰滆壊
-$primary-color: #67AFAB;
-$primary-light: rgba($primary-color, 0.1);
-$primary-gradient: linear-gradient(135deg, #67AFAB, #89C4C1);
-// 鏂囧瓧棰滆壊
+$primary-color: #67afab;
+$primary-light: rgba($primary-color, 0.1);
+$primary-gradient: linear-gradient(135deg, #67afab, #89c4c1);
$text-primary: #333333;
$text-regular: #666666;
$text-secondary: #999999;
-
-// 鑳屾櫙棰滆壊
-$bg-color: #F5F6FA;
-$card-bg: #FFFFFF;
-
-// 鍔熻兘鑹�
-$success: #67C23A;
-$warning: #E6A23C;
-$danger: #F56C6C;
+$bg-color: #f5f6fa;
+$card-bg: #ffffff;
+$success: #67c23a;
+$warning: #e6a23c;
+$danger: #f56c6c;
$info: #909399;
-
-// 鍦嗚
$radius-sm: 4rpx;
$radius-md: 12rpx;
$radius-lg: 24rpx;
$radius-xl: 36rpx;
-
-// 闃村奖
$shadow-sm: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
$shadow-md: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
$shadow-lg: 0 8rpx 24rpx rgba(0, 0, 0, 0.12);
-// 娣峰叆
@mixin flex-center {
display: flex;
align-items: center;
@@ -116,7 +158,6 @@
overflow: hidden;
}
-// 閫氱敤鏍峰紡绫�
.primary-btn {
background: $primary-gradient;
color: #fff;
@@ -126,11 +167,9 @@
line-height: 80rpx;
text-align: center;
box-shadow: 0 4rpx 12rpx rgba($primary-color, 0.3);
-
&[disabled] {
opacity: 0.6;
}
-
&:active {
transform: scale(0.95);
}
@@ -161,9 +200,8 @@
position: relative;
padding-left: 20rpx;
margin-bottom: 30rpx;
-
&::before {
- content: '';
+ content: "";
position: absolute;
left: 0;
top: 50%;
@@ -179,11 +217,9 @@
font-size: 32rpx;
color: $danger;
font-weight: bold;
-
&.free {
color: $success;
}
-
&.original {
font-size: 24rpx;
color: $text-secondary;
@@ -199,14 +235,12 @@
border-radius: $radius-xl;
padding: 0 30rpx;
box-shadow: $shadow-md;
-
.icon-search {
width: 32rpx;
height: 32rpx;
margin-right: 20rpx;
color: $primary-color;
}
-
input {
flex: 1;
font-size: 28rpx;
@@ -217,7 +251,7 @@
}
}
-@import '@/static/style/iconfont.scss';
+// @import "@/static/style/iconfont.scss";
page {
background-color: $bg-color;
--
Gitblit v1.9.3