diff --git a/src/App.vue b/src/App.vue
index 5a37691..795402e 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -2,10 +2,13 @@
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app';
import { useAuthStore } from '@/state/modules/auth';
import { setupInterceptors } from '@/utils/interceptors';
+ import { useAppStore } from '@/state/modules/app';
onLaunch(() => {
console.log('App Launch');
setupInterceptors();
+ const appStore = useAppStore();
+ appStore.initialize();
});
onShow(() => {
const authStore = useAuthStore();
diff --git a/src/components/AppProvider/inedx.vue b/src/components/AppProvider/inedx.vue
new file mode 100644
index 0000000..0deb5f2
--- /dev/null
+++ b/src/components/AppProvider/inedx.vue
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
diff --git a/src/manifest.json b/src/manifest.json
index 7e33ba0..c5a9281 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -18,6 +18,9 @@
},
/* 模块配置 */
"modules" : {},
+ "optimization": {
+ "subPackages": true
+ },
/* 应用发布信息 */
"distribute" : {
/* android打包配置 */
@@ -58,10 +61,16 @@
"minified" : true
},
"usingComponents" : true,
- "permission" : {}
+ "permission" : {},
+ "optimization": {
+ "subPackages": true
+ }
},
"mp-alipay" : {
- "usingComponents" : true
+ "usingComponents" : true,
+ "optimization": {
+ "subPackages": true
+ }
},
"mp-baidu" : {
"usingComponents" : true
@@ -81,6 +90,6 @@
"devServer" : {
"https" : false
},
- "title" : "uni-preset-vue3"
+ "title" : "uniapp_vue3_vite_ts"
}
}
diff --git a/src/pages.json b/src/pages.json
index 8c37930..b8c949f 100644
--- a/src/pages.json
+++ b/src/pages.json
@@ -5,6 +5,9 @@
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "首页"
+ },
+ "meta": {
+ "ignoreAuth": true
}
},
{
@@ -38,6 +41,28 @@
}
}
],
+ "subPackages": [{
+ "root": "pagesA",
+ "pages": [{
+ "path": "list/test1/index",
+ "style": {
+ "navigationBarTitleText": "test1"
+ }
+ },{
+ "path": "list/test2/index",
+ "style": {
+ "navigationBarTitleText": "test2"
+ }
+ }]
+ }, {
+ "root": "pagesB",
+ "pages": [{
+ "path": "detail/index",
+ "style": {
+ "navigationBarTitleText": "Detail"
+ }
+ }]
+ }],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
diff --git a/src/pages/about/index.vue b/src/pages/about/index.vue
index cc75432..cc49dfe 100644
--- a/src/pages/about/index.vue
+++ b/src/pages/about/index.vue
@@ -1,5 +1,6 @@
-
-
-
-
+
+
+
+
+
+
+ {{ isLogin ? '测试' : '未登入' }}
- {{ isLogin ? '测试' : '未登入' }}
+ log
+ 登出
+ 登入
- log
- 登出
- 登入
-
+
diff --git a/src/pagesA/list/test2/index.vue b/src/pagesA/list/test2/index.vue
new file mode 100644
index 0000000..7f85915
--- /dev/null
+++ b/src/pagesA/list/test2/index.vue
@@ -0,0 +1,3 @@
+
+ Test2
+
diff --git a/src/pagesB/detail/index.vue b/src/pagesB/detail/index.vue
new file mode 100644
index 0000000..53e96c8
--- /dev/null
+++ b/src/pagesB/detail/index.vue
@@ -0,0 +1,3 @@
+
+ Detail
+
diff --git a/src/state/modules/app.ts b/src/state/modules/app.ts
new file mode 100644
index 0000000..09e2c2f
--- /dev/null
+++ b/src/state/modules/app.ts
@@ -0,0 +1,35 @@
+import { defineStore } from 'pinia';
+import { Pages } from '@/types/pages';
+import { pagesMap } from '@/utils/router/pages';
+
+interface AppStore {
+ pages: Map | undefined;
+ currentPage: Pages | undefined;
+}
+
+export const useAppStore = defineStore({
+ id: 'app',
+ state: (): AppStore => ({
+ pages: undefined,
+ currentPage: undefined,
+ }),
+ getters: {
+ getPages(state) {
+ return state.pages;
+ },
+ getCurrentPage(state) {
+ return state.currentPage;
+ },
+ },
+ actions: {
+ initialize() {
+ this.setPages();
+ },
+ setPages() {
+ this.pages = pagesMap;
+ },
+ setCurrentPage(path: string) {
+ this.currentPage = this.pages?.get(path);
+ },
+ },
+});
diff --git a/src/types/pages.d.ts b/src/types/pages.d.ts
new file mode 100644
index 0000000..958cea4
--- /dev/null
+++ b/src/types/pages.d.ts
@@ -0,0 +1,15 @@
+export interface Pages extends Record {
+ path: string;
+ meta?: {
+ ignoreAuth?: boolean;
+ };
+ style: {
+ navigationBarTitleText: string;
+ [key: string]: string;
+ };
+}
+
+export interface SubPackages {
+ root: string;
+ pages: Pages[];
+}
diff --git a/src/utils/router/constant.ts b/src/utils/router/constant.ts
new file mode 100644
index 0000000..e69de29
diff --git a/src/utils/router/pages.ts b/src/utils/router/pages.ts
new file mode 100644
index 0000000..cdbb992
--- /dev/null
+++ b/src/utils/router/pages.ts
@@ -0,0 +1,23 @@
+import pagesJson from '@/pages.json';
+import { Pages } from '@/types/pages';
+
+const { pages, subPackages } = pagesJson;
+
+// 将pages.json转换成Map对象,path为key
+const pagesMap = new Map();
+
+pages.forEach((page) => {
+ pagesMap.set(page.path, page as Pages);
+});
+
+if (Array.isArray(subPackages) && subPackages.length) {
+ subPackages.forEach((el) => {
+ const rootPath = el.root;
+ el.pages.forEach((page) => {
+ page.path = rootPath + '/' + page.path;
+ pagesMap.set(page.path, page as Pages);
+ });
+ });
+}
+
+export { pagesMap };