yak_handcuffs/src/store/common.ts

32 lines
645 B
TypeScript
Raw Normal View History

2025-04-01 18:07:18 +08:00
import { defineStore } from 'pinia';
2025-04-11 18:46:52 +08:00
import { TLogin, TRoleList } from "@/api/index.d";
import { roleList } from '@/api';
2025-04-01 18:07:18 +08:00
export const useCommonStore = defineStore('common', {
state: () => {
return {
2025-04-03 18:21:17 +08:00
time: new Date(),
2025-04-11 18:46:52 +08:00
user: <TLogin.IRes>{},
roleList: <TRoleList[]>[]
2025-04-01 18:07:18 +08:00
};
},
getters: {},
actions: {
setTime() {
this.time = new Date();
2025-04-03 18:21:17 +08:00
},
2025-04-11 18:46:52 +08:00
getRoleList() {
roleList().then(res => {
this.roleList = res
})
},
2025-04-03 18:21:17 +08:00
setUser(data: TLogin.IRes) {
this.user = data
},
clearStore() {
this.$reset();
2025-04-01 18:07:18 +08:00
}
2025-04-03 18:21:17 +08:00
},
persist: true
2025-04-01 18:07:18 +08:00
});