- init unibest v4.4.0 base template - tabbar: 4 tabs (打卡/进度/测算/持仓) with carbon icons - pages/checkin: daily checklist, streak counter, monthly rate - pages/progress: asset snapshot, progress bar to 71万 target - pages/calculator, holdings: placeholder pages (stage 2) - store/checkin.ts + store/progress.ts with pinia persist - vite: host 0.0.0.0 for WSL2→Windows browser access Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
60 lines
2.3 KiB
TypeScript
60 lines
2.3 KiB
TypeScript
/**
|
|
* by 菲鸽 on 2025-08-19
|
|
* 路由拦截,通常也是登录拦截
|
|
* 黑、白名单的配置,请看 config.ts 文件, EXCLUDE_LOGIN_PATH_LIST
|
|
*/
|
|
import { tabbarStore } from '@/tabbar/store'
|
|
import { getLastPage, parseUrlToObj } from '@/utils/index'
|
|
|
|
export const FG_LOG_ENABLE = false
|
|
|
|
export const navigateToInterceptor = {
|
|
// 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
|
|
// 增加对相对路径的处理,BY 网友 @ideal
|
|
invoke({ url, query }: { url: string, query?: Record<string, string> }) {
|
|
if (url === undefined) {
|
|
return
|
|
}
|
|
let { path, query: _query } = parseUrlToObj(url)
|
|
|
|
FG_LOG_ENABLE && console.log('\n\n路由拦截器:-------------------------------------')
|
|
FG_LOG_ENABLE && console.log('路由拦截器 1: url->', url, ', query ->', query)
|
|
const myQuery = { ..._query, ...query }
|
|
// /pages/route-interceptor/index?name=feige&age=30
|
|
FG_LOG_ENABLE && console.log('路由拦截器 2: path->', path, ', _query ->', _query)
|
|
FG_LOG_ENABLE && console.log('路由拦截器 3: myQuery ->', myQuery)
|
|
|
|
// 处理相对路径
|
|
if (!path.startsWith('/')) {
|
|
const currentPath = getLastPage()?.route || ''
|
|
const normalizedCurrentPath = currentPath.startsWith('/') ? currentPath : `/${currentPath}`
|
|
const baseDir = normalizedCurrentPath.substring(0, normalizedCurrentPath.lastIndexOf('/'))
|
|
path = `${baseDir}/${path}`
|
|
}
|
|
|
|
// // 处理路由不存在的情况
|
|
// if (path !== '/' && !getAllPages().some(page => page.path === path)) {
|
|
// console.warn('路由不存在:', path)
|
|
// return false // 明确表示阻止原路由继续执行
|
|
// }
|
|
|
|
// // 插件页面
|
|
// if (url.startsWith('plugin://')) {
|
|
// FG_LOG_ENABLE && console.log('路由拦截器 4: plugin:// 路径 ==>', url)
|
|
// path = url
|
|
// }
|
|
|
|
// 处理直接进入路由非首页时,tabbarIndex 不正确的问题
|
|
tabbarStore.setAutoCurIdx(path)
|
|
},
|
|
}
|
|
|
|
export const routeInterceptor = {
|
|
install() {
|
|
uni.addInterceptor('navigateTo', navigateToInterceptor)
|
|
uni.addInterceptor('reLaunch', navigateToInterceptor)
|
|
uni.addInterceptor('redirectTo', navigateToInterceptor)
|
|
uni.addInterceptor('switchTab', navigateToInterceptor)
|
|
},
|
|
}
|