39 lines
760 B
TypeScript
39 lines
760 B
TypeScript
import { defineStore } from "pinia";
|
|
import { dicApi } from "@/api/system/dic";
|
|
|
|
interface DicState {
|
|
data: any;
|
|
}
|
|
|
|
export const useDicStore = defineStore({
|
|
id: "app-dic",
|
|
state: (): DicState => ({
|
|
// 字典数据
|
|
data: {}
|
|
}),
|
|
getters: {
|
|
getData(): any {
|
|
return this.data;
|
|
}
|
|
},
|
|
actions: {
|
|
setData(data: any) {
|
|
this.data = data;
|
|
},
|
|
async findByPid(params: any): Promise<any> {
|
|
if (!params || !params.pid) {
|
|
return Promise.resolve();
|
|
}
|
|
if (!this.data[params.pid]) {
|
|
this.data[params.pid] = await dicApi(params);
|
|
}
|
|
return Promise.resolve(this.data[params.pid]);
|
|
},
|
|
},
|
|
persist: {
|
|
enabled: true,
|
|
detached: true,
|
|
H5Storage: localStorage
|
|
},
|
|
});
|