diff --git a/build/cool/temp/eps.d.ts b/build/cool/temp/eps.d.ts index b597820..c2cc090 100644 --- a/build/cool/temp/eps.d.ts +++ b/build/cool/temp/eps.d.ts @@ -291,7 +291,7 @@ declare namespace Eps { */ price?: number; /** - * 分类 + * 分类 0-衣服 1-鞋子 2-裤子 */ type?: number; /** diff --git a/package.json b/package.json index 73b8660..e46b7b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "front-next", - "version": "5.7.8", + "version": "5.7.9", "scripts": { "dev": "vite --host", "build": "vite build", diff --git a/src/modules/base/config.ts b/src/modules/base/config.ts index 2995c50..5ef27d1 100644 --- a/src/modules/base/config.ts +++ b/src/modules/base/config.ts @@ -61,21 +61,28 @@ export default (): ModuleConfig => { document.title = config.app.name; }, async onLoad() { - const { user, menu } = useStore(); + const { user, menu, app } = useStore(); - if (user.token) { + // token 事件 + async function hasToken(cb: () => Promise | void) { + if (cb) { + app.addEvent("hasToken", cb); + + if (user.token) { + await cb(); + } + } + } + + await hasToken(async () => { // 获取用户信息 user.get(); // 获取菜单权限 await menu.get(); - } + }); return { - async hasToken(cb: () => Promise | void) { - if (user.token) { - if (cb) await cb(); - } - } + hasToken }; } }; diff --git a/src/modules/base/pages/login/index.vue b/src/modules/base/pages/login/index.vue index e35ac47..656cdd2 100644 --- a/src/modules/base/pages/login/index.vue +++ b/src/modules/base/pages/login/index.vue @@ -99,11 +99,8 @@ async function toLogin() { user.setToken(res); }); - // 用户信息 - user.get(); - - // 权限菜单 - await menu.get(); + // token 事件 + await Promise.all(app.events.hasToken.map((e) => e())); // 跳转 router.push("/"); diff --git a/src/modules/base/store/app.ts b/src/modules/base/store/app.ts index c9643ce..eef6d68 100644 --- a/src/modules/base/store/app.ts +++ b/src/modules/base/store/app.ts @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import { ref } from "vue"; +import { reactive, ref } from "vue"; import { config } from "/@/cool"; import { deepMerge, getBrowser, storage } from "/@/cool/utils"; @@ -15,6 +15,11 @@ export const useAppStore = defineStore("app", function () { // 是否折叠 const isFold = ref(browser.value.isMini || false); + // 事件 + const events = reactive<{ [key: string]: any[] }>({ + hasToken: [] + }); + // 折叠 function fold(v?: boolean) { if (v === undefined) { @@ -35,12 +40,21 @@ export const useAppStore = defineStore("app", function () { browser.value = getBrowser(); } + // 添加事件 + function addEvent(name: string, func: any) { + if (func) { + events[name].push(func); + } + } + return { info, browser, isFold, fold, + events, set, - setBrowser + setBrowser, + addEvent }; }); diff --git a/src/modules/demo/views/crud.vue b/src/modules/demo/views/crud.vue index c29e8e9..fad3de7 100644 --- a/src/modules/demo/views/crud.vue +++ b/src/modules/demo/views/crud.vue @@ -41,11 +41,14 @@ + xxxx +