wip: 临时提交

This commit is contained in:
Ray.Hao
2025-07-23 21:44:48 +08:00
parent 088ff87ea3
commit 8bda7dd0b1
11 changed files with 136 additions and 60 deletions

View File

@@ -134,6 +134,7 @@
"stylelint-prettier": "^5.0.2",
"typescript": "^4.9.4",
"typescript-eslint": "^8.6.0",
"uni-mini-router": "^0.1.6",
"unocss": "^0.62.4",
"unocss-preset-weapp": "^0.62.2",
"unplugin-auto-import": "^0.18.3",

View File

@@ -1,12 +1,3 @@
/*
* @Author: weisheng
* @Date: 2024-10-29 22:12:54
* @LastEditTime: 2025-06-25 13:33:39
* @LastEditors: weisheng
* @Description:
* @FilePath: /wot-demo/src/composables/useTabbar.ts
* 记得注释
*/
export interface TabbarItem {
name: string;
value: number | null;

View File

@@ -13,7 +13,7 @@
v-for="(item, index) in tabbarList"
:key="index"
:name="item.name"
:value="item.value"
:value="getTabbarItemValue(item.name)"
:title="item.title"
:icon="item.icon"
/>
@@ -25,20 +25,24 @@
</template>
<script setup lang="ts">
const { theme, themeVars } = useTheme();
const router = useRouter();
const route = useRoute();
const { themeVars, theme } = useTheme();
const { activeTabbar, getTabbarItemValue, setTabbarItemActive, tabbarList } = useTabbar();
// 生命周期
function handleTabbarChange({ value }: { value: string }) {
setTabbarItemActive(value);
router.pushTab({ name: value });
}
onMounted(() => {
// #ifdef APP-PLUS
uni.hideTabBar();
// #endif
nextTick(() => {
const pages = getCurrentPages();
if (!pages.length) return;
const route = pages[pages.length - 1].route;
if (route.name && route.name !== activeTabbar.value.name) {
setTabbarItemActive(route.name);
}

View File

@@ -5,10 +5,13 @@ import "uno.css";
import "@/styles/index.scss";
import { setupStore } from "@/store";
import router from "./router";
export function createApp() {
const app = createSSRApp(App);
setupStore(app);
app.use(router);
return {
app,

View File

@@ -20,6 +20,11 @@
{
"path": "pages/work/index",
"type": "page",
"name": "work",
"meta": {
"requireAuth": true,
"title": "需要登录的页面"
},
"style": {}
},
{

View File

@@ -6,6 +6,16 @@
</view>
</template>
<route lang="json">
{
"name": "work",
"meta": {
"requireAuth": true,
"title": "需要登录的页面"
}
}
</route>
<script setup lang="ts">
const handleBack = () => {
uni.navigateBack();

66
src/router/index.ts Normal file
View File

@@ -0,0 +1,66 @@
import { createRouter } from "uni-mini-router";
import { pages, subPackages } from "virtual:uni-pages";
import { isLoggedIn } from "@/utils/auth";
// 生成路由配置
function generateRoutes() {
const routes = pages.map((page: { path: string; [key: string]: any }) => {
const newPath = `/${page.path}`;
return { ...page, path: newPath };
});
// 处理分包路由
if (subPackages && subPackages.length > 0) {
subPackages.forEach((subPackage: { root: string; pages: any[] }) => {
const subRoutes = subPackage.pages.map((page: any) => {
const newPath = `/${subPackage.root}/${page.path}`;
return { ...page, path: newPath };
});
routes.push(...subRoutes);
});
}
return routes;
}
// 创建路由实例
const router = createRouter({
routes: generateRoutes(),
});
// 全局前置守卫
router.beforeEach((to, from, next) => {
// 检查页面是否需要登录
if (to.meta && to.meta.requireAuth) {
if (!isLoggedIn) {
// 显示登录提示
uni.showModal({
title: "提示",
content: "该功能需要登录后使用",
confirmText: "去登录",
cancelText: "返回",
success: (res) => {
if (res.confirm) {
// 记住原来要去的页面
uni.setStorageSync("redirect", to.fullPath);
next("/pages/login/index");
} else {
// 取消则返回首页
next("/pages/index/index");
}
},
});
return;
}
}
// 继续导航
next();
});
router.afterEach((to) => {
console.log("路由跳转完成:", to.path);
// 可以在这里做一些统计或记录
});
export default router;

View File

@@ -20,6 +20,7 @@ declare global {
const computed: typeof import('vue')['computed']
const createApp: typeof import('vue')['createApp']
const createPinia: typeof import('pinia')['createPinia']
const createRouter: typeof import('uni-mini-router')['createRouter']
const currentThemeColor: typeof import('../composables/useTheme')['currentThemeColor']
const customRef: typeof import('vue')['customRef']
const debounce: typeof import('../utils/index')['debounce']
@@ -157,8 +158,8 @@ declare global {
const usePrevRoute: typeof import('@uni-helper/uni-use')['usePrevRoute']
const useProvider: typeof import('@uni-helper/uni-use')['useProvider']
const useRequest: typeof import('@uni-helper/uni-use')['useRequest']
const useRoute: typeof import('@uni-helper/uni-use')['useRoute']
const useRouter: typeof import('@uni-helper/uni-use')['useRouter']
const useRoute: typeof import('../composables/useCommon')['useRoute']
const useRouter: typeof import('../composables/useCommon')['useRouter']
const useScanCode: typeof import('@uni-helper/uni-use')['useScanCode']
const useScreenBrightness: typeof import('@uni-helper/uni-use')['useScreenBrightness']
const useSelectorQuery: typeof import('@uni-helper/uni-use')['useSelectorQuery']
@@ -172,7 +173,7 @@ declare global {
const useTemplateRef: typeof import('vue')['useTemplateRef']
const useTheme: typeof import('../composables/useTheme')['useTheme']
const useThemeStore: typeof import('../store/modules/theme.store')['useThemeStore']
const useToast: typeof import('wot-design-uni')['useToast']
const useToast: typeof import('../composables/useCommon')['useToast']
const useUploadFile: typeof import('@uni-helper/uni-use')['useUploadFile']
const useUserStore: typeof import('../store/modules/user.store')['useUserStore']
const useVisible: typeof import('@uni-helper/uni-use')['useVisible']
@@ -208,6 +209,7 @@ declare module 'vue' {
readonly computed: UnwrapRef<typeof import('vue')['computed']>
readonly createApp: UnwrapRef<typeof import('vue')['createApp']>
readonly createPinia: UnwrapRef<typeof import('pinia')['createPinia']>
readonly createRouter: UnwrapRef<typeof import('uni-mini-router')['createRouter']>
readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
readonly debounce: UnwrapRef<typeof import('../utils/index')['debounce']>
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
@@ -222,7 +224,6 @@ declare module 'vue' {
readonly getRefreshToken: UnwrapRef<typeof import('../utils/auth')['getRefreshToken']>
readonly getToken: UnwrapRef<typeof import('../utils/storage')['getToken']>
readonly getUserInfo: UnwrapRef<typeof import('../utils/storage')['getUserInfo']>
readonly guessSerializerType: UnwrapRef<typeof import('@uni-helper/uni-use')['guessSerializerType']>
readonly h: UnwrapRef<typeof import('vue')['h']>
readonly inject: UnwrapRef<typeof import('vue')['inject']>
readonly isLoggedIn: UnwrapRef<typeof import('../utils/auth')['isLoggedIn']>
@@ -301,59 +302,24 @@ declare module 'vue' {
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
readonly tryOnBackPress: UnwrapRef<typeof import('@uni-helper/uni-use')['tryOnBackPress']>
readonly tryOnHide: UnwrapRef<typeof import('@uni-helper/uni-use')['tryOnHide']>
readonly tryOnInit: UnwrapRef<typeof import('@uni-helper/uni-use')['tryOnInit']>
readonly tryOnLoad: UnwrapRef<typeof import('@uni-helper/uni-use')['tryOnLoad']>
readonly tryOnReady: UnwrapRef<typeof import('@uni-helper/uni-use')['tryOnReady']>
readonly tryOnScopeDispose: UnwrapRef<typeof import('@uni-helper/uni-use')['tryOnScopeDispose']>
readonly tryOnShow: UnwrapRef<typeof import('@uni-helper/uni-use')['tryOnShow']>
readonly tryOnUnload: UnwrapRef<typeof import('@uni-helper/uni-use')['tryOnUnload']>
readonly unref: UnwrapRef<typeof import('vue')['unref']>
readonly useActionSheet: UnwrapRef<typeof import('@uni-helper/uni-use')['useActionSheet']>
readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
readonly useClipboardData: UnwrapRef<typeof import('@uni-helper/uni-use')['useClipboardData']>
readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
readonly useDownloadFile: UnwrapRef<typeof import('@uni-helper/uni-use')['useDownloadFile']>
readonly useGlobalData: UnwrapRef<typeof import('@uni-helper/uni-use')['useGlobalData']>
readonly useId: UnwrapRef<typeof import('vue')['useId']>
readonly useInterceptor: UnwrapRef<typeof import('@uni-helper/uni-use')['useInterceptor']>
readonly useLoading: UnwrapRef<typeof import('@uni-helper/uni-use')['useLoading']>
readonly useMessage: UnwrapRef<typeof import('wot-design-uni')['useMessage']>
readonly useModal: UnwrapRef<typeof import('@uni-helper/uni-use')['useModal']>
readonly useModel: UnwrapRef<typeof import('vue')['useModel']>
readonly useNetwork: UnwrapRef<typeof import('@uni-helper/uni-use')['useNetwork']>
readonly useNotify: UnwrapRef<typeof import('wot-design-uni')['useNotify']>
readonly useOnline: UnwrapRef<typeof import('@uni-helper/uni-use')['useOnline']>
readonly usePage: UnwrapRef<typeof import('@uni-helper/uni-use')['usePage']>
readonly usePageScroll: UnwrapRef<typeof import('@uni-helper/uni-use')['usePageScroll']>
readonly usePages: UnwrapRef<typeof import('@uni-helper/uni-use')['usePages']>
readonly usePreferredDark: UnwrapRef<typeof import('@uni-helper/uni-use')['usePreferredDark']>
readonly usePreferredLanguage: UnwrapRef<typeof import('@uni-helper/uni-use')['usePreferredLanguage']>
readonly usePrevPage: UnwrapRef<typeof import('@uni-helper/uni-use')['usePrevPage']>
readonly usePrevRoute: UnwrapRef<typeof import('@uni-helper/uni-use')['usePrevRoute']>
readonly useProvider: UnwrapRef<typeof import('@uni-helper/uni-use')['useProvider']>
readonly useRequest: UnwrapRef<typeof import('@uni-helper/uni-use')['useRequest']>
readonly useRoute: UnwrapRef<typeof import('@uni-helper/uni-use')['useRoute']>
readonly useRouter: UnwrapRef<typeof import('@uni-helper/uni-use')['useRouter']>
readonly useScanCode: UnwrapRef<typeof import('@uni-helper/uni-use')['useScanCode']>
readonly useScreenBrightness: UnwrapRef<typeof import('@uni-helper/uni-use')['useScreenBrightness']>
readonly useSelectorQuery: UnwrapRef<typeof import('@uni-helper/uni-use')['useSelectorQuery']>
readonly useRoute: UnwrapRef<typeof import('../composables/useCommon')['useRoute']>
readonly useRouter: UnwrapRef<typeof import('../composables/useCommon')['useRouter']>
readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
readonly useSocket: UnwrapRef<typeof import('@uni-helper/uni-use')['useSocket']>
readonly useStomp: UnwrapRef<typeof import('../composables/useStomp')['useStomp']>
readonly useStorage: UnwrapRef<typeof import('@uni-helper/uni-use')['useStorage']>
readonly useStorageAsync: UnwrapRef<typeof import('@uni-helper/uni-use')['useStorageAsync']>
readonly useStorageSync: UnwrapRef<typeof import('@uni-helper/uni-use')['useStorageSync']>
readonly useTabbar: UnwrapRef<typeof import('../composables/useTabbar')['useTabbar']>
readonly useTemplateRef: UnwrapRef<typeof import('vue')['useTemplateRef']>
readonly useTheme: UnwrapRef<typeof import('../composables/useTheme')['useTheme']>
readonly useThemeStore: UnwrapRef<typeof import('../store/modules/theme.store')['useThemeStore']>
readonly useToast: UnwrapRef<typeof import('wot-design-uni')['useToast']>
readonly useUploadFile: UnwrapRef<typeof import('@uni-helper/uni-use')['useUploadFile']>
readonly useToast: UnwrapRef<typeof import('../composables/useCommon')['useToast']>
readonly useUserStore: UnwrapRef<typeof import('../store/modules/user.store')['useUserStore']>
readonly useVisible: UnwrapRef<typeof import('@uni-helper/uni-use')['useVisible']>
readonly useWechat: UnwrapRef<typeof import('../composables/useWechat')['useWechat']>
readonly user: UnwrapRef<typeof import('../api/user')['default']>
readonly watch: UnwrapRef<typeof import('vue')['watch']>

12
src/types/uni-mini-router.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
import "uni-mini-router";
declare module "uni-mini-router" {
interface Route {
path: string;
fullPath: string;
meta?: {
requireAuth?: boolean;
[key: string]: any;
};
}
}

16
src/types/virtual-uni-pages.d.ts vendored Normal file
View File

@@ -0,0 +1,16 @@
declare module "virtual:uni-pages" {
interface Page {
path: string;
style?: Record<string, any>;
[key: string]: any;
}
interface SubPackage {
root: string;
pages: Page[];
[key: string]: any;
}
export const pages: Page[];
export const subPackages: SubPackage[];
}

View File

@@ -3,7 +3,6 @@ import uni from "@dcloudio/vite-plugin-uni";
import AutoImport from "unplugin-auto-import/vite";
import UniLayouts from "@uni-helper/vite-plugin-uni-layouts";
import UniPages from "@uni-helper/vite-plugin-uni-pages";
import { uniuseAutoImports } from "@uni-helper/uni-use";
import Components from "@uni-helper/vite-plugin-uni-components";
import { WotResolver } from "@uni-helper/vite-plugin-uni-components/resolvers";
@@ -48,7 +47,10 @@ export default defineConfig(async ({ mode }: ConfigEnv): Promise<UserConfig> =>
"vue",
"uni-app",
"pinia",
uniuseAutoImports(),
{
from: "uni-mini-router",
imports: ["createRouter", "useRouter", "useRoute"],
},
{
from: "wot-design-uni",
imports: ["useToast", "useMessage", "useNotify", "CommonUtil"],