53 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-08-27 21:02:29 +08:00
import { defineStore } from "pinia";
import { jsFindByIdApi } from "@/api/base/jsApi";
2025-09-02 23:10:03 +08:00
import { xkkclxFindAllApi, getXkkcDetailByIdApi } from "@/api/base/xkApi";
2025-08-27 21:02:29 +08:00
interface CommonState {
data: any;
}
export const useCommonStore = defineStore({
id: "app-common",
state: (): CommonState => ({
// 字典数据
data: {}
}),
getters: {
getData(): any {
return this.data;
}
},
actions: {
setData(data: any) {
this.data = data;
},
// 根据教师ID获取教师信息带缓存机制
async getJsById(params: any): Promise<any> {
if (!this.data.js || !this.data.js[params.id]) {
this.data.js = this.data.js || {};
this.data.js[params.id] = await jsFindByIdApi(params);
}
return Promise.resolve(this.data.js[params.id]);
},
async getAllXkkcLx() : Promise<any> {
if (!this.data.xkkcLx) {
this.data.xkkcLx = await xkkclxFindAllApi();
}
return Promise.resolve(this.data.xkkcLx);
},
2025-09-02 23:10:03 +08:00
async getXkkcDetailByIdApi(id: string) : Promise<any> {
if (!this.data.xkkc || !this.data.xkkc[id]) {
this.data.xkkc = this.data.xkkc || {};
const res = await getXkkcDetailByIdApi(id);
console.log(res);
}
return Promise.resolve(this.data.xkkc[id]);
},
2025-08-27 21:02:29 +08:00
},
persist: {
enabled: true,
detached: true,
H5Storage: localStorage
},
});