| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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<Location[]>([]);
- 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,
- };
- }
|