dictionary.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { store } from "@/store";
  2. import { defineStore } from "pinia";
  3. import { getUserList } from "@/api/auth";
  4. export const useDictionaryStore = defineStore("dictionaryStore", () => {
  5. const types = [
  6. "defect_mana",
  7. "stage",
  8. "process_state",
  9. "outsource_state",
  10. "work_order_seq_state",
  11. "station_task_state",
  12. "accessories_type",
  13. "danwei_type",
  14. "system_message_type",
  15. "plan_work_order_state",
  16. "disposal_measures_type",
  17. "escalation_fault_state",
  18. "excel_type",
  19. "device_type",
  20. "station_type",
  21. ];
  22. const dicts = ref<{ [key: string]: any[] }>({});
  23. // 所有的用户列表
  24. const allUsers = ref<any[]>([]);
  25. function checkAllData() {
  26. if (allUsers.value.length === 0) {
  27. getUserList().then((res) => {
  28. allUsers.value = res.data || [];
  29. });
  30. }
  31. }
  32. function getLableByValue(type: string, value: string) {
  33. const dict = dicts.value[type];
  34. if (dict) {
  35. const lable = dict.find((item: any) => item.dictValue === value);
  36. return lable?.dictLabel;
  37. }
  38. return "";
  39. }
  40. return {
  41. types,
  42. dicts,
  43. allUsers,
  44. checkAllData,
  45. getLableByValue,
  46. };
  47. });
  48. export function useDictionaryStoreHook() {
  49. // console.log('dicts:',useDictionaryStore(store))
  50. return useDictionaryStore(store);
  51. }