From 871522ed7e06fd9c62a87c178d7f5c88d7853a20 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期一, 20 四月 2026 18:04:35 +0800
Subject: [PATCH] 初始提交
---
App.vue | 81 ++++++++++++++++++++++++++++++----------
1 files changed, 60 insertions(+), 21 deletions(-)
diff --git a/App.vue b/App.vue
index 30b3f4a..e4ebf7d 100644
--- a/App.vue
+++ b/App.vue
@@ -1,35 +1,74 @@
<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()
+// 瀹氫箟椤甸潰鐧藉悕鍗� - 杩欎簺椤甸潰涓嶉渶瑕乼oken鏍¢獙
+const pageWhiteList = [
+ 'pages/login/Login',
+ 'pages/login/DingTalkLogin'
+]
-onLaunch(() => {
- console.log('App Launch')
- try {
- const currentLang = uni.getStorageSync('language')
- console.log('褰撳墠璇█:', currentLang)
- } catch (error) {
- console.error('璇█閰嶇疆閿欒:', error)
- }
-})
+// 鏀硅繘鐨勭櫧鍚嶅崟妫�鏌ユ柟娉�
+const isPageInWhiteList = (currentPage) => {
+ return pageWhiteList.some(path => currentPage.includes(path))
+}
-onShow(() => {
- console.log('App Show')
-})
-
-onHide(() => {
- console.log('App Hide')
+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
+ }
+
+ // 鏍¢獙token鏈夋晥鎬э細閫氳繃璋冪敤/current/user/current_roles鎺ュ彛
+ const current = await uni.$uapi.get("/getInfo");
+
+ // 濡傛灉鎺ュ彛杩斿洖鎴愬姛锛岃鏄巘oken鏈夋晥锛岀户缁幏鍙栫敤鎴蜂俊鎭�
+ if (current) {
+ // const resuser = await uni.$uapi.get("/system/user/profile");
+ userStore.setUserInfo(current.user);
+ userStore.setroleKey(current.roles);
+
+ // 濡傛灉褰撳墠鏄櫥褰曢〉锛岃烦杞椤�
+ if (isPageInWhiteList(currentPage)) {
+ uni.switchTab({ url: '/pages/index/index' })
+ }
+ } else {
+ // 鎺ュ彛杩斿洖浣嗚鑹蹭俊鎭负绌猴紝瑙嗕负token鏃犳晥
+ console.error('瑙掕壊淇℃伅鑾峰彇澶辫触锛宼oken鍙兘鏃犳晥')
+ userStore.clearUser() // 娓呴櫎鏈湴鐢ㄦ埛淇℃伅
+ uni.redirectTo({ url: '/pages/login/Login' })
+ }
+
+ } catch (error) {
+ console.error('鍒濆鍖栧け璐�:', error)
+ // token鏃犳晥鎴栧叾浠栭敊璇紝娓呴櫎鏈湴鐢ㄦ埛淇℃伅骞惰烦杞櫥褰曢〉
+ userStore.clearUser()
+ 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