useWorkLocation.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { ref } from 'vue';
  2. import { getWorkLocationList } from '@/api/datamanagement/alert';
  3. type Location = {
  4. value: number;
  5. label: string;
  6. children: {
  7. value: number;
  8. label: string;
  9. }[];
  10. };
  11. export function useWorkLocation() {
  12. const locationOptions = ref<Location[]>([]);
  13. const getLocationOptions = () => {
  14. getWorkLocationList().then((res) => {
  15. locationOptions.value =
  16. res?.map((item) => {
  17. const newChildren =
  18. item.workspaceList?.map((x) => {
  19. return { value: x.workspaceId, label: x.workspaceName };
  20. }) || [];
  21. return {
  22. value: item.workshopId,
  23. label: item.workshopName,
  24. children: newChildren,
  25. };
  26. }) || [];
  27. });
  28. };
  29. const getNameByWorkid = (workshopId, workspaceId, array) => {
  30. const shop = array.find((item) => item.value === workshopId);
  31. if (!shop) {
  32. return '-';
  33. }
  34. if (!shop.children || !Array.isArray(shop.children)) return '-';
  35. const space = shop.children.find((item) => item.value === workspaceId);
  36. let str = shop.label;
  37. if (space?.label) {
  38. str += ' - ' + space?.label
  39. }
  40. return str;
  41. };
  42. return {
  43. locationOptions,
  44. getLocationOptions,
  45. getNameByWorkid,
  46. };
  47. }