import { store } from "@/store"; import { defineStore } from "pinia"; import { getUserDicts, getUserList } from "@/api/auth"; export const useDictionaryStore = defineStore("dictionaryStore", () => { const types = [ "defect_mana", "stage", "process_state", "outsource_state", "work_order_seq_state", "accessories_type", "danwei_type", ]; const dicts = ref<{ [key: string]: any[] }>({}); // 所有的用户列表 const allUsers = ref([]); function checkAllData() { if (JSON.stringify(dicts.value) === "{}") { getUserDicts(types).then((res) => { if (res.data) { dicts.value = res?.data ?? []; } }); } if (allUsers.value.length === 0) { getUserList().then((res) => { allUsers.value = res.data || []; }); } } function getLableByValue(type: string, value: string) { const dict = dicts.value[type]; if (dict) { const lable = dict.find((item: any) => item.dictValue === value); return lable?.dictLabel; } return ""; } return { types, dicts, allUsers, checkAllData, getLableByValue, }; }); export function useDictionaryStoreHook() { // console.log('dicts:',useDictionaryStore(store)) return useDictionaryStore(store); }