From 53f27a1917037de5760c79662945a0f92eabf826 Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Thu, 6 Nov 2025 16:18:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E4=BB=A3=E7=A0=81=E5=92=8C=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 清理未使用的页面、组件、路由配置和主题相关代码 移除登录拦截和分包配置相关逻辑 简化首页和个人中心页面 --- package.json | 1 - pnpm-lock.yaml | 13 -- src/App.ku.vue | 19 +- src/App.vue | 4 +- src/layouts/default.vue | 7 - src/pages-fg/404/README.md | 3 - src/pages-fg/404/index.vue | 30 --- src/pages-fg/REAME.md | 3 - src/pages-fg/login/README.md | 20 -- src/pages-fg/login/login.vue | 87 -------- src/pages-fg/login/register.vue | 34 --- src/pages-sub/about/about.vue | 134 ------------ src/pages-sub/about/alova.vue | 53 ----- src/pages-sub/about/components/Upload.vue | 25 --- src/pages-sub/about/components/VBindCss.vue | 28 --- .../about/components/request-openapi.vue | 64 ------ src/pages-sub/about/components/request.vue | 75 ------- src/pages-sub/demo/components/request.vue | 48 ---- src/pages-sub/demo/index.vue | 44 ---- src/pages-sub/demo/scroll.vue | 72 ------ src/pages/index/index.vue | 63 +----- src/pages/me/me.vue | 205 +----------------- src/router/config.ts | 31 --- src/router/interceptor.ts | 79 +------ src/store/index.ts | 1 - src/store/theme.ts | 42 ---- src/tabbar/index.vue | 2 +- src/tabbar/store.ts | 12 +- src/utils/toLoginPage.ts | 4 +- tsconfig.json | 1 - vite.config.ts | 7 +- 31 files changed, 20 insertions(+), 1191 deletions(-) delete mode 100644 src/pages-fg/404/README.md delete mode 100644 src/pages-fg/404/index.vue delete mode 100644 src/pages-fg/REAME.md delete mode 100644 src/pages-fg/login/README.md delete mode 100644 src/pages-fg/login/login.vue delete mode 100644 src/pages-fg/login/register.vue delete mode 100644 src/pages-sub/about/about.vue delete mode 100644 src/pages-sub/about/alova.vue delete mode 100644 src/pages-sub/about/components/Upload.vue delete mode 100644 src/pages-sub/about/components/VBindCss.vue delete mode 100644 src/pages-sub/about/components/request-openapi.vue delete mode 100644 src/pages-sub/about/components/request.vue delete mode 100644 src/pages-sub/demo/components/request.vue delete mode 100644 src/pages-sub/demo/index.vue delete mode 100644 src/pages-sub/demo/scroll.vue delete mode 100644 src/router/config.ts delete mode 100644 src/store/theme.ts diff --git a/package.json b/package.json index 84a1298..3d1e8aa 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,6 @@ "pinia-plugin-persistedstate": "3.2.1", "vue": "^3.4.21", "vue-router": "4.5.1", - "wot-design-uni": "^1.12.4", "z-paging": "2.8.7" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a6022c6..503c42e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -90,9 +90,6 @@ importers: vue-router: specifier: 4.5.1 version: 4.5.1(vue@3.4.21(typescript@5.8.3)) - wot-design-uni: - specifier: ^1.12.4 - version: 1.12.4(vue@3.4.21(typescript@5.8.3)) z-paging: specifier: 2.8.7 version: 2.8.7 @@ -6143,12 +6140,6 @@ packages: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} - wot-design-uni@1.12.4: - resolution: {integrity: sha512-GE7hfJ+RKRCiWtEkhoQ5gz3fbwNB69EzLcXiIUPK2gawk9+hp7KescjplcxdxGfeuCJUlhF6wW9VUEe86h/63g==} - engines: {HBuilderX: ^3.8.7} - peerDependencies: - vue: '>=3.2.47' - wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} @@ -13874,10 +13865,6 @@ snapshots: word-wrap@1.2.5: {} - wot-design-uni@1.12.4(vue@3.4.21(typescript@5.8.3)): - dependencies: - vue: 3.4.21(typescript@5.8.3) - wrap-ansi@7.0.0: dependencies: ansi-styles: 4.3.0 diff --git a/src/App.ku.vue b/src/App.ku.vue index 8aab489..8d4ee68 100644 --- a/src/App.ku.vue +++ b/src/App.ku.vue @@ -1,12 +1,9 @@ diff --git a/src/App.vue b/src/App.vue index 9c47bc2..e2179ee 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,10 +3,10 @@ import { onHide, onLaunch, onShow } from '@dcloudio/uni-app' import { navigateToInterceptor } from '@/router/interceptor' onLaunch((options) => { - console.log('App Launch', options) + console.log('App.vue onLaunch', options) }) onShow((options) => { - console.log('App Show', options) + console.log('App.vue onShow', options) // 处理直接进入页面路由的情况:如h5直接输入路由、微信小程序分享后进入等 // https://github.com/unibest-tech/unibest/issues/192 if (options?.path) { diff --git a/src/layouts/default.vue b/src/layouts/default.vue index 88a55d4..ba4672f 100644 --- a/src/layouts/default.vue +++ b/src/layouts/default.vue @@ -1,10 +1,3 @@ - - diff --git a/src/pages-fg/404/README.md b/src/pages-fg/404/README.md deleted file mode 100644 index ecc8aa4..0000000 --- a/src/pages-fg/404/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# 404 页面 - -`404页面` 只有在路由不存在时才会显示,如果您不需要可以删除该页面。但是建议保留。 \ No newline at end of file diff --git a/src/pages-fg/404/index.vue b/src/pages-fg/404/index.vue deleted file mode 100644 index 533e259..0000000 --- a/src/pages-fg/404/index.vue +++ /dev/null @@ -1,30 +0,0 @@ - - - - - diff --git a/src/pages-fg/REAME.md b/src/pages-fg/REAME.md deleted file mode 100644 index 55479de..0000000 --- a/src/pages-fg/REAME.md +++ /dev/null @@ -1,3 +0,0 @@ -# pages-fg 说明 - -为了尽量减少主包的大小,一些无关紧要但经常需要的页面(如登录页、注册页、404页等)放在了 `pages-fg` 目录下。 diff --git a/src/pages-fg/login/README.md b/src/pages-fg/login/README.md deleted file mode 100644 index c851a76..0000000 --- a/src/pages-fg/login/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# 登录页 -需要输入账号、密码/验证码的登录页。 - -## 适用性 - -本页面主要用于 `h5` 和 `APP`。 - -小程序通常有平台的登录方式 `uni.login` 通常用不到登录页,所以不适用于 `小程序`。(即默认情况下,小程序环境是不会走登录拦截逻辑的。) - -但是如果您的小程序也需要现实的 `登录页` 那也是可以使用的。 - -在 `src/router/config.ts` 中有一个变量 `LOGIN_PAGE_ENABLE_IN_MP` 来控制是否在小程序中使用 `H5的登录页`。 - -更多信息请看 `src/router` 文件夹的内容。 - -## 登录跳转 - -目前登录的跳转逻辑主要在 `src/router/interceptor.ts` 和 `src/pages/login/login.vue` 里面,默认会在登录后自动重定向到来源/配置的页面。 - -如果与您的业务不符,您可以自行修改。 diff --git a/src/pages-fg/login/login.vue b/src/pages-fg/login/login.vue deleted file mode 100644 index 0fa5e95..0000000 --- a/src/pages-fg/login/login.vue +++ /dev/null @@ -1,87 +0,0 @@ - - - - - diff --git a/src/pages-fg/login/register.vue b/src/pages-fg/login/register.vue deleted file mode 100644 index e9809f0..0000000 --- a/src/pages-fg/login/register.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - - - diff --git a/src/pages-sub/about/about.vue b/src/pages-sub/about/about.vue deleted file mode 100644 index b4bf1e6..0000000 --- a/src/pages-sub/about/about.vue +++ /dev/null @@ -1,134 +0,0 @@ - - - diff --git a/src/pages-sub/about/alova.vue b/src/pages-sub/about/alova.vue deleted file mode 100644 index 4b0c43f..0000000 --- a/src/pages-sub/about/alova.vue +++ /dev/null @@ -1,53 +0,0 @@ - - - - - diff --git a/src/pages-sub/about/components/Upload.vue b/src/pages-sub/about/components/Upload.vue deleted file mode 100644 index 09547f5..0000000 --- a/src/pages-sub/about/components/Upload.vue +++ /dev/null @@ -1,25 +0,0 @@ - - - diff --git a/src/pages-sub/about/components/VBindCss.vue b/src/pages-sub/about/components/VBindCss.vue deleted file mode 100644 index bc5a048..0000000 --- a/src/pages-sub/about/components/VBindCss.vue +++ /dev/null @@ -1,28 +0,0 @@ - - - - - diff --git a/src/pages-sub/about/components/request-openapi.vue b/src/pages-sub/about/components/request-openapi.vue deleted file mode 100644 index 53f78ad..0000000 --- a/src/pages-sub/about/components/request-openapi.vue +++ /dev/null @@ -1,64 +0,0 @@ - - - diff --git a/src/pages-sub/about/components/request.vue b/src/pages-sub/about/components/request.vue deleted file mode 100644 index 73db16b..0000000 --- a/src/pages-sub/about/components/request.vue +++ /dev/null @@ -1,75 +0,0 @@ - - - diff --git a/src/pages-sub/demo/components/request.vue b/src/pages-sub/demo/components/request.vue deleted file mode 100644 index 7d7bff1..0000000 --- a/src/pages-sub/demo/components/request.vue +++ /dev/null @@ -1,48 +0,0 @@ - - - diff --git a/src/pages-sub/demo/index.vue b/src/pages-sub/demo/index.vue deleted file mode 100644 index 3831b5f..0000000 --- a/src/pages-sub/demo/index.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - - - diff --git a/src/pages-sub/demo/scroll.vue b/src/pages-sub/demo/scroll.vue deleted file mode 100644 index 2599163..0000000 --- a/src/pages-sub/demo/scroll.vue +++ /dev/null @@ -1,72 +0,0 @@ - - - diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 687d096..27b81b8 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -1,7 +1,4 @@ diff --git a/src/pages/me/me.vue b/src/pages/me/me.vue index c43a47c..5df9e2e 100644 --- a/src/pages/me/me.vue +++ b/src/pages/me/me.vue @@ -1,214 +1,13 @@ - - diff --git a/src/router/config.ts b/src/router/config.ts deleted file mode 100644 index 2d0e52d..0000000 --- a/src/router/config.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { getAllPages } from '@/utils' - -export const LOGIN_STRATEGY_MAP = { - DEFAULT_NO_NEED_LOGIN: 0, // 黑名单策略,默认可以进入APP - DEFAULT_NEED_LOGIN: 1, // 白名单策略,默认不可以进入APP,需要强制登录 -} -// TODO: 1/3 登录策略,默认使用`无需登录策略`,即默认不需要登录就可以访问 -export const LOGIN_STRATEGY = LOGIN_STRATEGY_MAP.DEFAULT_NO_NEED_LOGIN -export const isNeedLoginMode = LOGIN_STRATEGY === LOGIN_STRATEGY_MAP.DEFAULT_NEED_LOGIN - -export const LOGIN_PAGE = '/pages-fg/login/login' -export const REGISTER_PAGE = '/pages-fg/login/register' -export const NOT_FOUND_PAGE = '/pages-fg/404/index' - -export const LOGIN_PAGE_LIST = [LOGIN_PAGE, REGISTER_PAGE] - -// 在 definePage 里面配置了 excludeLoginPath 的页面,功能与 EXCLUDE_LOGIN_PATH_LIST 相同 -export const excludeLoginPathList = getAllPages('excludeLoginPath').map(page => page.path) - -// 排除在外的列表,白名单策略指白名单列表,黑名单策略指黑名单列表 -// TODO: 2/3 在 definePage 配置 excludeLoginPath,或者在下面配置 EXCLUDE_LOGIN_PATH_LIST -export const EXCLUDE_LOGIN_PATH_LIST = [ - '/pages/xxx/index', // 示例值 - '/pages-sub/xxx/index', // 示例值 - ...excludeLoginPathList, // 都是以 / 开头的 path -] - -// 在小程序里面是否使用H5的登录页,默认为 false -// 如果为 true 则复用 h5 的登录逻辑 -// TODO: 3/3 确定自己的登录页是否需要在小程序里面使用 -export const LOGIN_PAGE_ENABLE_IN_MP = false diff --git a/src/router/interceptor.ts b/src/router/interceptor.ts index 2b7b1ab..e5b6046 100644 --- a/src/router/interceptor.ts +++ b/src/router/interceptor.ts @@ -1,24 +1,12 @@ -import { isMp } from '@uni-helper/uni-env' /** * by 菲鸽 on 2025-08-19 * 路由拦截,通常也是登录拦截 * 黑、白名单的配置,请看 config.ts 文件, EXCLUDE_LOGIN_PATH_LIST */ -import { useTokenStore } from '@/store/token' -import { isPageTabbar, tabbarStore } from '@/tabbar/store' -import { getAllPages, getLastPage, HOME_PAGE, parseUrlToObj } from '@/utils/index' -import { toLoginPage } from '@/utils/toLoginPage' -import { EXCLUDE_LOGIN_PATH_LIST, isNeedLoginMode, LOGIN_PAGE, LOGIN_PAGE_ENABLE_IN_MP, NOT_FOUND_PAGE } from './config' +import { tabbarStore } from '@/tabbar/store' +import { getAllPages, getLastPage, parseUrlToObj } from '@/utils/index' export const FG_LOG_ENABLE = false -export function judgeIsExcludePath(path: string) { - const isDev = import.meta.env.DEV - if (!isDev) { - return EXCLUDE_LOGIN_PATH_LIST.includes(path) - } - const allExcludeLoginPages = getAllPages('excludeLoginPath') // dev 环境下,需要每次都重新获取,否则新配置就不会生效 - return EXCLUDE_LOGIN_PATH_LIST.includes(path) || (isDev && allExcludeLoginPages.some(page => page.path === path)) -} export const navigateToInterceptor = { // 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同 @@ -47,74 +35,11 @@ export const navigateToInterceptor = { // 处理路由不存在的情况 if (path !== '/' && !getAllPages().some(page => page.path !== path)) { console.warn('路由不存在:', path) - uni.navigateTo({ url: NOT_FOUND_PAGE }) return false // 明确表示阻止原路由继续执行 } // 处理直接进入路由非首页时,tabbarIndex 不正确的问题 tabbarStore.setAutoCurIdx(path) - - // 小程序里面使用平台自带的登录,则不走下面的逻辑 - if (isMp && !LOGIN_PAGE_ENABLE_IN_MP) { - return true // 明确表示允许路由继续执行 - } - - const tokenStore = useTokenStore() - FG_LOG_ENABLE && console.log('tokenStore.hasLogin:', tokenStore.hasLogin) - - // 不管黑白名单,登录了就直接去吧(但是当前不能是登录页) - if (tokenStore.hasLogin) { - if (path !== LOGIN_PAGE) { - return true // 明确表示允许路由继续执行 - } - else { - console.log('已经登录,但是还在登录页', myQuery.redirect) - const url = myQuery.redirect || HOME_PAGE - if (isPageTabbar(url)) { - uni.switchTab({ url }) - } - else { - uni.navigateTo({ url }) - } - return false // 明确表示阻止原路由继续执行 - } - } - let fullPath = path - - if (Object.keys(myQuery).length) { - fullPath += `?${Object.keys(myQuery).map(key => `${key}=${myQuery[key]}`).join('&')}` - } - const redirectQuery = `?redirect=${encodeURIComponent(fullPath)}` - - // #region 1/2 默认需要登录的情况(白名单策略) --------------------------- - if (isNeedLoginMode) { - // 需要登录里面的 EXCLUDE_LOGIN_PATH_LIST 表示白名单,可以直接通过 - if (judgeIsExcludePath(path)) { - return true // 明确表示允许路由继续执行 - } - // 否则需要重定向到登录页 - else { - if (path === LOGIN_PAGE) { - return true // 明确表示允许路由继续执行 - } - FG_LOG_ENABLE && console.log('1 isNeedLogin(白名单策略) url:', fullPath) - toLoginPage({ queryString: redirectQuery }) - return false // 明确表示阻止原路由继续执行 - } - } - // #endregion 1/2 默认需要登录的情况(白名单策略) --------------------------- - - // #region 2/2 默认不需要登录的情况(黑名单策略) --------------------------- - else { - // 不需要登录里面的 EXCLUDE_LOGIN_PATH_LIST 表示黑名单,需要重定向到登录页 - if (judgeIsExcludePath(path)) { - FG_LOG_ENABLE && console.log('2 isNeedLogin(黑名单策略) url:', fullPath) - toLoginPage({ queryString: redirectQuery }) - return false // 修改为false,阻止原路由继续执行 - } - return true // 明确表示允许路由继续执行 - } - // #endregion 2/2 默认不需要登录的情况(黑名单策略) --------------------------- }, } diff --git a/src/store/index.ts b/src/store/index.ts index 2f5a7c3..fe2ead1 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -16,6 +16,5 @@ setActivePinia(store) export default store // 模块统一导出 -export * from './theme' export * from './token' export * from './user' diff --git a/src/store/theme.ts b/src/store/theme.ts deleted file mode 100644 index c3f1c55..0000000 --- a/src/store/theme.ts +++ /dev/null @@ -1,42 +0,0 @@ -import type { ConfigProviderThemeVars } from 'wot-design-uni' - -import { defineStore } from 'pinia' - -export const useThemeStore = defineStore( - 'theme-store', - () => { - /** 主题 */ - const theme = ref<'light' | 'dark'>('light') - - /** 主题变量 */ - const themeVars = ref({ - // colorTheme: 'red', - // buttonPrimaryBgColor: '#07c160', - // buttonPrimaryColor: '#07c160', - }) - - /** 设置主题变量 */ - const setThemeVars = (partialVars: Partial) => { - themeVars.value = { ...themeVars.value, ...partialVars } - } - - /** 切换主题 */ - const toggleTheme = () => { - theme.value = theme.value === 'light' ? 'dark' : 'light' - } - - return { - /** 设置主题变量 */ - setThemeVars, - /** 切换主题 */ - toggleTheme, - /** 主题变量 */ - themeVars, - /** 主题 */ - theme, - } - }, - { - persist: true, - }, -) diff --git a/src/tabbar/index.vue b/src/tabbar/index.vue index a18816f..e66de29 100644 --- a/src/tabbar/index.vue +++ b/src/tabbar/index.vue @@ -108,7 +108,7 @@ function getImageByIndex(index: number, item: CustomTabBarItem) { - +