2025-09-02 23:10:03 +08:00

53 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineStore } from "pinia";
import { jsFindByIdApi } from "@/api/base/jsApi";
import { xkkclxFindAllApi, getXkkcDetailByIdApi } from "@/api/base/xkApi";
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);
},
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]);
},
},
persist: {
enabled: true,
detached: true,
H5Storage: localStorage
},
});