import { ref } from 'vue'; import { getWorkLocationList } from '@/api/datamanagement/alert'; type Location = { value: number; label: string; children: { value: number; label: string; }[]; }; export function useWorkLocation() { const locationOptions = ref([]); const getLocationOptions = () => { getWorkLocationList().then((res) => { locationOptions.value = res?.map((item) => { const newChildren = item.workspaceList?.map((x) => { return { value: x.workspaceId, label: x.workspaceName }; }) || []; return { value: item.workshopId, label: item.workshopName, children: newChildren, }; }) || []; }); }; const getNameByWorkid = (workshopId, workspaceId, array) => { const shop = array.find((item) => item.value === workshopId); if (!shop) { return '-'; } if (!shop.children || !Array.isArray(shop.children)) return '-'; const space = shop.children.find((item) => item.value === workspaceId); let str = shop.label; if (space?.label) { str += ' - ' + space?.label } return str; }; return { locationOptions, getLocationOptions, getNameByWorkid, }; }