From 2b3715f1610b4176d7abe33e34542389cef61853 Mon Sep 17 00:00:00 2001 From: zhuguifei <zhuguifei@zhuguifeideiMac.local> Date: 星期六, 12 四月 2025 17:12:22 +0800 Subject: [PATCH] Merge branch 'main' of http://lanpucloud.cn:1111/r/eims-master --- eims-ui-mobile/src/interceptors/route.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) diff --git a/eims-ui-mobile/src/interceptors/route.ts b/eims-ui-mobile/src/interceptors/route.ts new file mode 100644 index 0000000..ddd6c98 --- /dev/null +++ b/eims-ui-mobile/src/interceptors/route.ts @@ -0,0 +1,54 @@ +/** + * by 鑿查附 on 2024-03-06 + * 璺敱鎷︽埅锛岄�氬父涔熸槸鐧诲綍鎷︽埅 + * 鍙互璁剧疆璺敱鐧藉悕鍗曪紝鎴栬�呴粦鍚嶅崟锛岀湅涓氬姟闇�瑕侀�夊摢涓�涓� + * 鎴戣繖閲屽簲涓哄ぇ閮ㄥ垎閮藉彲浠ラ殢渚胯繘鍏ワ紝鎵�浠ヤ娇鐢ㄩ粦鍚嶅崟 + */ +import { useUserStore } from '@/store' +import { needLoginPages as _needLoginPages, getNeedLoginPages } from '@/utils' + +// TODO Check +const loginRoute = '/pages/login/index' + +const isLogined = () => { + const userStore = useUserStore() + return userStore.isLogined +} + +const isDev = import.meta.env.DEV + +// 榛戝悕鍗曠櫥褰曟嫤鎴櫒 - 锛堥�傜敤浜庡ぇ閮ㄥ垎椤甸潰涓嶉渶瑕佺櫥褰曪紝灏戦儴鍒嗛〉闈㈤渶瑕佺櫥褰曪級 +const navigateToInterceptor = { + // 娉ㄦ剰锛岃繖閲岀殑url鏄� '/' 寮�澶寸殑锛屽 '/pages/index/index'锛岃窡 'pages.json' 閲岄潰鐨� path 涓嶅悓 + invoke({ url }: { url: string }) { + // console.log(url) // /pages/route-interceptor/index?name=feige&age=30 + const path = url.split('?')[0] + let needLoginPages: string[] = [] + // 涓轰簡闃叉寮�鍙戞椂鍑虹幇BUG锛岃繖閲屾瘡娆¢兘鑾峰彇涓�涓嬨�傜敓浜х幆澧冨彲浠ョЩ鍒板嚱鏁板锛屾�ц兘鏇村ソ + if (isDev) { + needLoginPages = getNeedLoginPages() + } else { + needLoginPages = _needLoginPages + } + const isNeedLogin = needLoginPages.includes(path) + if (!isNeedLogin) { + return true + } + const hasLogin = isLogined() + if (hasLogin) { + return true + } + const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}` + uni.navigateTo({ url: redirectRoute }) + return false + }, +} + +export const routeInterceptor = { + install() { + uni.addInterceptor('navigateTo', navigateToInterceptor) + uni.addInterceptor('reLaunch', navigateToInterceptor) + uni.addInterceptor('redirectTo', navigateToInterceptor) + uni.addInterceptor('switchTab', navigateToInterceptor) + }, +} -- Gitblit v1.9.3