hasToken 优化

This commit is contained in:
icssoa 2022-08-09 14:55:59 +08:00
parent ae0be71e9c
commit 62020ec8a5
7 changed files with 44 additions and 18 deletions

View File

@ -291,7 +291,7 @@ declare namespace Eps {
*/
price?: number;
/**
*
* 0- 1- 2-
*/
type?: number;
/**

View File

@ -1,6 +1,6 @@
{
"name": "front-next",
"version": "5.7.8",
"version": "5.7.9",
"scripts": {
"dev": "vite --host",
"build": "vite build",

View File

@ -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<any> | 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<any> | void) {
if (user.token) {
if (cb) await cb();
}
}
hasToken
};
}
};

View File

@ -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("/");

View File

@ -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
};
});

View File

@ -41,11 +41,14 @@
</cl-upsert>
</cl-crud>
<cl-dialog title="xxx" v-model="dialog.visible"> xxxx </cl-dialog>
<cl-form ref="Form"></cl-form>
</template>
<script lang="tsx" setup name="crud">
import { useCrud, useUpsert, useTable, useForm } from "@cool-vue/crud";
import { reactive } from "vue";
import { useDict } from "/$/dict";
const { dict } = useDict();
@ -164,6 +167,10 @@ const Table = useTable({
]
});
const dialog = reactive({
visible: false
});
const Form = useForm();
//
@ -190,6 +197,8 @@ const Table2 = useTable({
});
function openForm() {
return (dialog.visible = true);
Form.value?.open({
title: "自定义表单",
items: [

View File

@ -5,7 +5,6 @@ export default (): ModuleConfig => {
return {
onLoad({ hasToken }) {
const { dict } = useDict();
hasToken(() => {
dict.refresh();
});