diff --git a/pages.config.ts b/pages.config.ts
index e7a2291..05e9c00 100644
--- a/pages.config.ts
+++ b/pages.config.ts
@@ -3,37 +3,45 @@ import { defineUniPages } from "@uni-helper/vite-plugin-uni-pages";
export default defineUniPages({
// 你也可以定义 pages 字段,它具有最高的优先级。
- pages: [
- {
- path: "pages/index/index",
- layout: "tabbar",
- },
- {
- path: "pages/mine/index",
- layout: "tabbar",
- },
- ],
+ pages: [],
globalStyle: {
- navigationStyle: "custom",
- navigationBarTextStyle: "black",
- navigationBarTitleText: "youlai-mall-app",
- navigationBarBackgroundColor: "#F8F8F8",
- backgroundColor: "#F8F8F8",
+ // 导航栏配置
+ navigationBarBackgroundColor: "@navBgColor",
+ navigationBarTextStyle: "@navTxtStyle",
+ navigationBarTitleText: "Wot-Demo",
+
+ // 页面背景配置
+ backgroundColor: "@bgColor",
+ backgroundTextStyle: "@bgTxtStyle",
+ backgroundColorTop: "@bgColorTop",
+ backgroundColorBottom: "@bgColorBottom",
+
+ // 下拉刷新配置
+ enablePullDownRefresh: false,
+ onReachBottomDistance: 50,
+
+ // 动画配置
+ animationType: "pop-in",
+ animationDuration: 300,
},
tabBar: {
custom: true,
- height: "0px",
- color: "#00000000",
- selectedColor: "#00000000",
- backgroundColor: "#00000000",
+ // #ifdef MP-ALIPAY
+ customize: true,
+ // 暂时不生效。4.71.2025061206-alpha已修复:https://uniapp.dcloud.net.cn/release-note-alpha.html#_4-71-2025061206-alpha,我们等正式版发布后更新。
+ overlay: true,
+ // #endif
+ height: "0",
+ color: "@tabColor",
+ selectedColor: "@tabSelectedColor",
+ backgroundColor: "@tabBgColor",
+ borderStyle: "@tabBorderStyle",
list: [
{
- text: "首页",
pagePath: "pages/index/index",
},
{
- text: "我的",
pagePath: "pages/mine/index",
},
],
diff --git a/src/layouts/tabbar.vue b/src/layouts/tabbar.vue
index e3311d7..058e745 100644
--- a/src/layouts/tabbar.vue
+++ b/src/layouts/tabbar.vue
@@ -25,14 +25,16 @@
+
+{
+ "name": "home",
+ "style": { "navigationStyle": "custom" },
+ "layout": "tabbar"
+}
+
diff --git a/src/pages/mine/index.vue b/src/pages/mine/index.vue
index 5438760..f6fe53b 100644
--- a/src/pages/mine/index.vue
+++ b/src/pages/mine/index.vue
@@ -249,6 +249,14 @@ onShow(() => {
});
+
+{
+ "name": "mine",
+ "style": { "navigationStyle": "custom" },
+ "layout": "tabbar"
+}
+
+
diff --git a/src/router/index.ts b/src/router/index.ts
index fb2edd7..fda51fa 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -1,5 +1,7 @@
import { pages, subPackages } from "virtual:uni-pages";
import { isLoggedIn } from "@/utils/auth";
+import { createRouter } from "uni-mini-router";
+
// 生成路由配置
function generateRoutes() {
const routes = pages.map((page: { path: string; [key: string]: any }) => {
@@ -17,7 +19,6 @@ function generateRoutes() {
routes.push(...subRoutes);
});
}
-
return routes;
}
@@ -28,39 +29,41 @@ const router = createRouter({
// 全局前置守卫
router.beforeEach((to, from, next) => {
- console.log("路由跳转:", to.path);
// 检查页面是否需要登录
- 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;
- }
+ if (to.meta && to.meta.requireAuth && !isLoggedIn()) {
+ uni.showModal({
+ title: "提示",
+ content: "该功能需要登录后使用",
+ confirmText: "去登录",
+ cancelText: "返回",
+ success: (res) => {
+ if (res.confirm) {
+ // 记住原来要去的页面
+ uni.setStorageSync("redirect", to.fullPath);
+ // 使用 uni 原生导航而不是 router
+ uni.navigateTo({
+ url: "/pages/login/index",
+ });
+ } else {
+ // 取消则返回首页
+ uni.switchTab({
+ url: "/pages/index/index",
+ });
+ }
+ },
+ // 确保在取消弹窗时也能调用 next
+ fail: () => {
+ next(false);
+ },
+ });
+ } else {
+ // 继续导航
+ next();
}
-
- // 继续导航
- next();
});
router.afterEach((to) => {
console.log("路由跳转完成:", to.path);
-
- // 可以在这里做一些统计或记录
});
export default router;
diff --git a/theme.json b/theme.json
new file mode 100644
index 0000000..2c2ef36
--- /dev/null
+++ b/theme.json
@@ -0,0 +1,26 @@
+{
+ "light": {
+ "bgColor": "#F8F8F8",
+ "bgColorBottom": "#F8F8F8",
+ "bgColorTop": "#F8F8F8",
+ "bgTxtStyle": "dark",
+ "navBgColor": "#FFF",
+ "navTxtStyle": "black",
+ "tabBgColor": "#ffffff",
+ "tabBorderStyle": "black",
+ "tabColor": "#bfbfbf",
+ "tabSelectedColor": "#0165FF"
+ },
+ "dark": {
+ "bgColor": "#000",
+ "bgColorBottom": "#000",
+ "bgColorTop": "#000",
+ "bgTxtStyle": "light",
+ "navBgColor": "#000000",
+ "navTxtStyle": "white",
+ "tabBgColor": "#1a1a1a",
+ "tabBorderStyle": "white",
+ "tabColor": "#bfbfbf",
+ "tabSelectedColor": "#0165FF"
+ }
+}
diff --git a/tsconfig.json b/tsconfig.json
index c6223b4..6bf4ab8 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -13,7 +13,7 @@
"@/*": ["./src/*"]
},
"lib": ["esnext", "dom"],
- "types": ["@dcloudio/types", "@uni-helper/uni-types", "wot-design-uni/global"]
+ "types": ["@dcloudio/types", "@uni-helper/uni-types", "wot-design-uni/global", "./src/types/vite-plugin-uni-pages"]
},
"vueCompilerOptions": {
// 调整 Volar(Vue 语言服务工具)解析行为,用于为 uni-app 组件提供 TypeScript 类型
diff --git a/vite.config.ts b/vite.config.ts
index d7acb2c..4212750 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -57,7 +57,7 @@ export default defineConfig(async ({ mode }: ConfigEnv): Promise =>
},
],
dts: "src/types/auto-imports.d.ts", // 自动生成的类型声明文件
- dirs: ["./src/composables", "src/store", "src/utils", "src/api"],
+ dirs: ["src/composables", "src/store", "src/utils", "src/api"],
vueTemplate: true,
}),