diff --git a/src/api/mes/criticalComponent/index.ts b/src/api/mes/criticalComponent/index.ts index 38255d36..f9390c78 100644 --- a/src/api/mes/criticalComponent/index.ts +++ b/src/api/mes/criticalComponent/index.ts @@ -1,7 +1,7 @@ import request from '@/config/axios' export interface CriticalComponentVO { - id: number + id?: number | string code: string isCode?: boolean name: string @@ -21,7 +21,7 @@ export const CriticalComponentApi = { getCriticalComponentList: async () => { return await request.get({ url: `/mes/critical-component/list`, }) }, - getCriticalComponent: async (id: number) => { + getCriticalComponent: async (id: number | string) => { return await request.get({ url: `/mes/critical-component/get?id=` + id }) }, createCriticalComponent: async (data: Partial) => { @@ -32,7 +32,7 @@ export const CriticalComponentApi = { return await request.put({ url: `/mes/critical-component/update`, data }) }, - regenerateCode: async (id: number, code: string) => { + regenerateCode: async (id: number | string, code: string) => { return await request.post({ url: `/mes/critical-component/regenerate-code?id=${id}&code=${encodeURIComponent(code)}` }) diff --git a/src/views/mes/deviceledger/DeviceLedgerForm.vue b/src/views/mes/deviceledger/DeviceLedgerForm.vue index 39801e8f..a950737b 100644 --- a/src/views/mes/deviceledger/DeviceLedgerForm.vue +++ b/src/views/mes/deviceledger/DeviceLedgerForm.vue @@ -807,8 +807,8 @@ const message = useMessage() // 娑堟伅寮圭獥 const loading = ref(true) const total = ref(0) const bjTotal = ref(0) -const selectedIds = ref([]) -const bjSelectedIds = ref([]) +const selectedIds = ref<(number | string)[]>([]) +const bjSelectedIds = ref<(number | string)[]>([]) const dialogTitle = ref('') // 寮圭獥鐨勬爣棰? const formLoading = ref(false) // 琛ㄥ崟鐨勫姞杞戒腑锛?锛変慨鏀规椂鐨勬暟鎹姞杞斤紱2锛夋彁浜ょ殑鎸夐挳绂佺敤 const fileUploading = ref(false) @@ -827,13 +827,13 @@ const bjSelectedRows = ref([]) // 瀛樺偍鎵€鏈夐€変腑鐨勮 // 琛ㄦ牸寮曠敤 const multipleTableRef = ref>() const bjMultipleTableRef = ref>() -const parseIdsValue = (value: any): number[] => { +const parseIdsValue = (value: any): (number | string)[] => { if (!value) return [] - if (Array.isArray(value)) return value.map((v) => Number(v)).filter((v) => !Number.isNaN(v)) + if (Array.isArray(value)) return value.map((v) => String(v)).filter((v) => v !== '') return String(value) .split(',') - .map((v) => Number(v.trim())) - .filter((v) => !Number.isNaN(v)) + .map((v) => String(v.trim())) + .filter((v) => v !== '') } const normalizeNumberish = (value: any): number | undefined => { @@ -945,13 +945,13 @@ const initFormData = () => ({ workshop: undefined, deviceLocation: undefined, systemOrg: undefined, - deviceManagerIds: [] as number[], + deviceManagerIds: [] as (number | string)[], productionDate: undefined, outgoingTime: undefined, factoryEntryDate: undefined, remark: undefined, - componentIds: [] as number[], - beijianIds: [] as number[], + componentIds: [] as (number | string)[], + beijianIds: [] as (number | string)[], fileUrl: '', qrcodeUrl: undefined, templateJson: undefined, @@ -1039,7 +1039,7 @@ const findDeviceTypeName = (id: string | number): string | undefined => { return undefined } const users = ref([]) -type SelectionOption = { label: string; value: number } +type SelectionOption = { label: string; value: number | string } const criticalComponentOptions = ref([]) const beijianOptions = ref([]) const savedCriticalComponentOptions = ref([]) @@ -1048,37 +1048,37 @@ const SPARE_PART_CATEGORY_TYPE = 3 const buildCriticalComponentOptions = (items: any[] = []): SelectionOption[] => (items ?? []) .map((item: any) => { - const id = normalizeNumberish(item?.id) - if (id === undefined) return undefined + if (item?.id === undefined || item?.id === null || item?.id === '') return undefined + const id = String(item.id) const code = item.code ? String(item.code) : '' const name = item.name ? String(item.name) : '' - const label = code && name ? `${code}-${name}` : name || code || String(id) + const label = code && name ? `${code}-${name}` : name || code || id return { label, value: id } }) .filter((item): item is SelectionOption => Boolean(item)) const buildBeijianOptions = (items: any[] = []): SelectionOption[] => (items ?? []) .map((item: any) => { - const id = normalizeNumberish(item?.id) - if (id === undefined) return undefined + if (item?.id === undefined || item?.id === null || item?.id === '') return undefined + const id = String(item.id) const code = item.barCode ? String(item.barCode) : '' const name = item.name ? String(item.name) : '' - const label = code && name ? `${code}-${name}` : name || code || String(id) + const label = code && name ? `${code}-${name}` : name || code || id return { label, value: id } }) .filter((item): item is SelectionOption => Boolean(item)) const mergeSelectionOptions = (...groups: SelectionOption[][]): SelectionOption[] => { - const optionMap = new Map() - groups.flat().forEach((item) => optionMap.set(item.value, item)) + const optionMap = new Map() + groups.flat().forEach((item) => optionMap.set(String(item.value), item)) return Array.from(optionMap.values()) } const filterValidSelectedIds = (selectedIds: any[], options: SelectionOption[]) => { - const validIds = new Set(options.map((item) => item.value)) + const validIds = new Set(options.map((item) => String(item.value))) return Array.from( new Set( (selectedIds ?? []) - .map((id) => normalizeNumberish(id)) - .filter((id): id is number => id !== undefined && validIds.has(id)) + .map((id) => (id === undefined || id === null || id === '' ? undefined : String(id))) + .filter((id): id is string => id !== undefined && validIds.has(id)) ) ) } @@ -1091,12 +1091,12 @@ const beijianTransferData = computed(() => const criticalComponentDialogVisible = ref(false) const beijianDialogVisible = ref(false) -const criticalComponentDraft = ref([]) -const beijianDraft = ref([]) +const criticalComponentDraft = ref<(number | string)[]>([]) +const beijianDraft = ref<(number | string)[]>([]) -const formatSelectedSummary = (ids: number[], options: { label: string; value: number }[]) => { - const optionMap = new Map(options.map((item) => [item.value, item.label])) - const labels = ids.map((id) => optionMap.get(id)).filter((v): v is string => Boolean(v)) +const formatSelectedSummary = (ids: (number | string)[], options: { label: string; value: number | string }[]) => { + const optionMap = new Map(options.map((item) => [String(item.value), item.label])) + const labels = ids.map((id) => optionMap.get(String(id))).filter((v): v is string => Boolean(v)) if (!labels.length) return '' if (labels.length <= 3) return labels.join(', ') return `${labels.slice(0, 3).join(', ')}...${labels.length}` @@ -1258,7 +1258,7 @@ const openBeijianDialog = () => { bjIds.value = [...(formData.value.beijianIds ?? [])] setBJDefaultSelections() } -const ids = ref([]) +const ids = ref<(number | string)[]>([]) const confirmCriticalComponentDialog = () => { //let ids = selectedRows.value.map(item => item.id); //const validMap = new Set(criticalComponentOptions.value.map((item) => item.value)) @@ -1267,7 +1267,7 @@ const confirmCriticalComponentDialog = () => { criticalComponentDialogVisible.value = false //multipleTableRef.value.clearSelection() } -const bjIds = ref([]) +const bjIds = ref<(number | string)[]>([]) const confirmBeijianDialog = () => { // let ids = bjSelectedRows.value.map(item => item.id); /* const validMap = new Set(beijianOptions.value.map((item) => item.value)) @@ -1456,12 +1456,12 @@ const bjResetQuery = () => { } const handleSelectionChange = (rows: CriticalComponentVO[]) => { - selectedIds.value = rows.map((r) => r.id).filter((id): id is number => typeof id === 'number') + selectedIds.value = rows.map((r) => r.id).filter((id) => id !== undefined && id !== null && id !== '') // 鑾峰彇褰撳墠椤垫墍鏈夎鐨?id - const currentPageIds = rows.map((item) => item.id) + const currentPageIds = rows.map((item) => String(item.id)) // 浠庡凡閫変腑鐨勬暟缁勪腑绉婚櫎褰撳墠椤电殑鏁版嵁 - selectedRows.value = selectedRows.value.filter((item) => !currentPageIds.includes(item.id)) + selectedRows.value = selectedRows.value.filter((item) => !currentPageIds.includes(String(item.id))) // 娣诲姞褰撳墠椤垫柊閫変腑鐨勬暟鎹? selectedRows.value.push(...rows) } @@ -1475,9 +1475,9 @@ const handleSelect = (selection, row) => { const isSelected = selection.includes(row) if (isSelected) { // console.log(`鉁?琛岃閫変腑: ID=${row.id}, Name=${row.name}`) - ids.value.push(row.id) + ids.value.push(String(row.id)) } else { - ids.value = ids.value.filter((item) => item !== row.id) + ids.value = ids.value.filter((item) => String(item) !== String(row.id)) // console.log(`鉂?琛岃鍙栨秷閫変腑: ID=${row.id}, Name=${row.name}`) } // 鏇存柊褰撳墠閫変腑鐘舵€? @@ -1485,21 +1485,16 @@ const handleSelect = (selection, row) => { } const handleSelectAll = (selection) => { - ids.value = selection?.map((row) => row.id).filter((id) => id !== undefined) ?? [] - - /* let newVar = selection?.map((row) => row.id).filter((id) => id !== undefined) ?? []; - newVar.forEach(row => { - ids.value.push(row) - })*/ + ids.value = selection?.map((row) => String(row.id)).filter((id) => id !== '') ?? [] } const bjHandleSelectionChange = (rows: CriticalComponentVO[]) => { - bjSelectedIds.value = rows.map((r) => r.id).filter((id): id is number => typeof id === 'number') + bjSelectedIds.value = rows.map((r) => r.id).filter((id) => id !== undefined && id !== null && id !== '') // 鑾峰彇褰撳墠椤垫墍鏈夎鐨?id - const currentPageIds = rows.map((item) => item.id) + const currentPageIds = rows.map((item) => String(item.id)) // 浠庡凡閫変腑鐨勬暟缁勪腑绉婚櫎褰撳墠椤电殑鏁版嵁 - bjSelectedRows.value = bjSelectedRows.value.filter((item) => !currentPageIds.includes(item.id)) + bjSelectedRows.value = bjSelectedRows.value.filter((item) => !currentPageIds.includes(String(item.id))) // 娣诲姞褰撳墠椤垫柊閫変腑鐨勬暟鎹? bjSelectedRows.value.push(...rows) } @@ -1513,9 +1508,9 @@ const bjHandleSelect = (selection, row) => { const isSelected = selection.includes(row) if (isSelected) { // console.log(`鉁?琛岃閫変腑: ID=${row.id}, Name=${row.name}`) - bjIds.value.push(row.id) + bjIds.value.push(String(row.id)) } else { - bjIds.value = bjIds.value.filter((item) => item !== row.id) + bjIds.value = bjIds.value.filter((item) => String(item) !== String(row.id)) // console.log(`鉂?琛岃鍙栨秷閫変腑: ID=${row.id}, Name=${row.name}`) } // 鏇存柊褰撳墠閫変腑鐘舵€? @@ -1523,7 +1518,7 @@ const bjHandleSelect = (selection, row) => { } const bjHandleSelectAll = (selection) => { - bjIds.value = selection?.map((row) => row.id).filter((id) => id !== undefined) ?? [] + bjIds.value = selection?.map((row) => String(row.id)).filter((id) => id !== '') ?? [] } const getList = async () => { @@ -1566,7 +1561,7 @@ const toggleSelection = () => { // 閬嶅巻褰撳墠椤电殑鏁版嵁 list.value.forEach((row) => { // 妫€鏌ヨ繖涓€琛屾槸鍚﹀湪宸查€変腑鏁扮粍涓? - const isSelected = selectedRows.value.some((item) => item.id === row.id) + const isSelected = selectedRows.value.some((item) => String(item.id) === String(row.id)) if (isSelected) { // 濡傛灉搴旇閫変腑锛屽氨閫変腑 @@ -1585,7 +1580,7 @@ const bjToggleSelection = () => { // 閬嶅巻褰撳墠椤电殑鏁版嵁 bjList.value.forEach((row) => { // 妫€鏌ヨ繖涓€琛屾槸鍚﹀湪宸查€変腑鏁扮粍涓? - const isSelected = bjSelectedRows.value.some((item) => item.id === row.id) + const isSelected = bjSelectedRows.value.some((item) => String(item.id) === String(row.id)) if (isSelected) { // 濡傛灉搴旇閫変腑锛屽氨閫変腑 @@ -1669,7 +1664,7 @@ const setDefaultSelections = () => { nextTick(() => { if (!multipleTableRef.value) return multipleTableRef.value.clearSelection() - const rawSubjectIds = toRaw(formData.value.componentIds) + const rawSubjectIds = (toRaw(formData.value.componentIds) ?? []).map((v) => String(v)) if (rawSubjectIds.length != 0) { let row = { id: undefined @@ -1679,7 +1674,7 @@ const setDefaultSelections = () => { // 閬嶅巻鏁版嵁锛屾壘鍒伴渶瑕侀€変腑鐨勮 list.value.forEach((row) => { let id = row.id - if (rawSubjectIds.includes(row.id)) { + if (rawSubjectIds.includes(String(row.id))) { multipleTableRef.value.toggleRowSelection(row, true) } }) @@ -1707,7 +1702,7 @@ const setBJDefaultSelections = () => { nextTick(() => { if (!bjMultipleTableRef.value) return bjMultipleTableRef.value.clearSelection() - const rawSubjectIds = toRaw(formData.value.beijianIds) + const rawSubjectIds = (toRaw(formData.value.beijianIds) ?? []).map((v) => String(v)) if (rawSubjectIds.length != 0) { let row = { id: undefined @@ -1717,7 +1712,7 @@ const setBJDefaultSelections = () => { // 閬嶅巻鏁版嵁锛屾壘鍒伴渶瑕侀€変腑鐨勮 bjList.value.forEach((row) => { let id = row.id - if (rawSubjectIds.includes(row.id)) { + if (rawSubjectIds.includes(String(row.id))) { bjMultipleTableRef.value.toggleRowSelection(row, true) } }) diff --git a/src/views/mes/deviceledger/detail/editIndex.vue b/src/views/mes/deviceledger/detail/editIndex.vue index e157296a..22b50b1c 100644 --- a/src/views/mes/deviceledger/detail/editIndex.vue +++ b/src/views/mes/deviceledger/detail/editIndex.vue @@ -874,15 +874,15 @@ const updateActionBarRectAfterLayout = () => { } const criticalComponentDialogVisible = ref(false) const beijianDialogVisible = ref(false) -const criticalComponentDraft = ref([]) -const beijianDraft = ref([]) +const criticalComponentDraft = ref<(number | string)[]>([]) +const beijianDraft = ref<(number | string)[]>([]) const list = ref([]) const bjList = ref([]) const loading = ref(true) const total = ref(0) const bjTotal = ref(0) -const selectedIds = ref([]) -const bjSelectedIds = ref([]) +const selectedIds = ref<(number | string)[]>([]) +const bjSelectedIds = ref<(number | string)[]>([]) // 琛ㄦ牸寮曠敤 const multipleTableRef = ref>() const bjMultipleTableRef = ref>() @@ -896,13 +896,13 @@ const iotDeviceTotal = ref(0) const iotDeviceSelectedLabel = ref('') const iotDeviceDraftId = ref() const iotDeviceDraftRow = ref() -const parseIdsValue = (value: any): number[] => { +const parseIdsValue = (value: any): (number | string)[] => { if (!value) return [] - if (Array.isArray(value)) return value.map((v) => Number(v)).filter((v) => !Number.isNaN(v)) + if (Array.isArray(value)) return value.map((v) => String(v)).filter((v) => v !== '') return String(value) .split(',') - .map((v) => Number(v.trim())) - .filter((v) => !Number.isNaN(v)) + .map((v) => String(v.trim())) + .filter((v) => v !== '') } const selectedRows = ref([]) // 瀛樺偍鎵€鏈夐€変腑鐨勮 const bjSelectedRows = ref([]) // 瀛樺偍鎵€鏈夐€変腑鐨勮 @@ -951,12 +951,12 @@ const bjResetQuery = () => { } const handleSelectionChange = (rows: CriticalComponentVO[]) => { - selectedIds.value = rows.map((r) => r.id).filter((id): id is number => typeof id === 'number') + selectedIds.value = rows.map((r) => r.id).filter((id) => id !== undefined && id !== null && id !== '') // 鑾峰彇褰撳墠椤垫墍鏈夎锟?id - const currentPageIds = rows.map((item) => item.id) + const currentPageIds = rows.map((item) => String(item.id)) // 浠庡凡閫変腑鐨勬暟缁勪腑绉婚櫎褰撳墠椤电殑鏁版嵁 - selectedRows.value = selectedRows.value.filter((item) => !currentPageIds.includes(item.id)) + selectedRows.value = selectedRows.value.filter((item) => !currentPageIds.includes(String(item.id))) // 娣诲姞褰撳墠椤垫柊閫変腑鐨勬暟锟? selectedRows.value.push(...rows) } @@ -967,21 +967,16 @@ const handleSelect = (selection: any[], row: any) => { const isSelected = selection.includes(row) if (isSelected) { // console.log(`锟?琛岃閫変腑: ID=${row.id}, Name=${row.name}`) - ids.value.push(row.id) + ids.value.push(String(row.id)) } else { - ids.value = ids.value.filter((item) => item !== row.id) + ids.value = ids.value.filter((item) => String(item) !== String(row.id)) // console.log(`锟?琛岃鍙栨秷閫変腑: ID=${row.id}, Name=${row.name}`) } // 鏇存柊褰撳墠閫変腑鐘讹拷? currentSelectedRows.value = selection } const handleSelectAll = (selection) => { - ids.value = selection?.map((row) => row.id).filter((id) => id !== undefined) ?? [] - - /* let newVar = selection?.map((row) => row.id).filter((id) => id !== undefined) ?? []; - newVar.forEach(row => { - ids.value.push(row) - })*/ + ids.value = selection?.map((row) => String(row.id)).filter((id) => id !== '') ?? [] } const confirmCriticalComponentDialog = () => { //let ids = selectedRows.value.map(item => item.id); @@ -993,12 +988,12 @@ const confirmCriticalComponentDialog = () => { //multipleTableRef.value.clearSelection() } const filterValidSelectedIds = (selectedIds: any[], options: SelectionOption[]) => { - const validIds = new Set(options.map((item) => item.value)) + const validIds = new Set(options.map((item) => String(item.value))) return Array.from( new Set( (selectedIds ?? []) - .map((id) => normalizeNumberish(id)) - .filter((id): id is number => id !== undefined && validIds.has(id)) + .map((id) => (id === undefined || id === null || id === '' ? undefined : String(id))) + .filter((id): id is string => id !== undefined && validIds.has(id)) ) ) } @@ -1012,12 +1007,12 @@ const confirmBeijianDialog = () => { } const bjHandleSelectionChange = (rows: CriticalComponentVO[]) => { - bjSelectedIds.value = rows.map((r) => r.id).filter((id): id is number => typeof id === 'number') + bjSelectedIds.value = rows.map((r) => r.id).filter((id) => id !== undefined && id !== null && id !== '') // 鑾峰彇褰撳墠椤垫墍鏈夎锟?id - const currentPageIds = rows.map((item) => item.id) + const currentPageIds = rows.map((item) => String(item.id)) // 浠庡凡閫変腑鐨勬暟缁勪腑绉婚櫎褰撳墠椤电殑鏁版嵁 - bjSelectedRows.value = bjSelectedRows.value.filter((item) => !currentPageIds.includes(item.id)) + bjSelectedRows.value = bjSelectedRows.value.filter((item) => !currentPageIds.includes(String(item.id))) // 娣诲姞褰撳墠椤垫柊閫変腑鐨勬暟锟? bjSelectedRows.value.push(...rows) } @@ -1028,16 +1023,16 @@ const bjHandleSelect = (selection: any[], row: any) => { const isSelected = selection.includes(row) if (isSelected) { // console.log(`锟?琛岃閫変腑: ID=${row.id}, Name=${row.name}`) - bjIds.value.push(row.id) + bjIds.value.push(String(row.id)) } else { - bjIds.value = bjIds.value.filter((item) => item !== row.id) + bjIds.value = bjIds.value.filter((item) => String(item) !== String(row.id)) // console.log(`锟?琛岃鍙栨秷閫変腑: ID=${row.id}, Name=${row.name}`) } // 鏇存柊褰撳墠閫変腑鐘讹拷? bjCurrentSelectedRows.value = selection } const bjHandleSelectAll = (selection) => { - bjIds.value = selection?.map((row) => row.id).filter((id) => id !== undefined) ?? [] + bjIds.value = selection?.map((row) => String(row.id)).filter((id) => id !== '') ?? [] } const getList = async () => { @@ -1075,7 +1070,7 @@ const toggleSelection = () => { // 閬嶅巻褰撳墠椤电殑鏁版嵁 list.value.forEach((row) => { - const isSelected = selectedRows.value.some((item) => item.id === row.id) + const isSelected = selectedRows.value.some((item) => String(item.id) === String(row.id)) if (isSelected) { // 濡傛灉搴旇閫変腑锛屽氨閫変腑 @@ -1092,7 +1087,7 @@ const bjToggleSelection = () => { // 閬嶅巻褰撳墠椤电殑鏁版嵁 bjList.value.forEach((row) => { - const isSelected = bjSelectedRows.value.some((item) => item.id === row.id) + const isSelected = bjSelectedRows.value.some((item) => String(item.id) === String(row.id)) if (isSelected) { // 濡傛灉搴旇閫変腑锛屽氨閫変腑 @@ -1104,19 +1099,19 @@ const bjToggleSelection = () => { }) } const selectedDeviceRows = ref([]) -const ids = ref([]) -const bjIds = ref([]) +const ids = ref<(number | string)[]>([]) +const bjIds = ref<(number | string)[]>([]) const openCriticalComponentDialog = () => { queryParams.name = '' queryParams.description = '' queryParams.code = '' - const rows = selectedDeviceRows.value.map((item) => ({ ...item, id: Number(item.id) })) + const rows = selectedDeviceRows.value.map((item) => ({ ...item, id: String(item.id) })) criticalComponentSelectDialogRef.value?.open(rows) let initIds = formData.value.componentIds != undefined ? formData.value.componentIds.toString().split(',') : [] - ids.value = initIds.map((id) => Number(id)) + ids.value = initIds.map((id) => String(id)).filter((id) => id !== '') } const openBeijianDialog = () => { beijianDraft.value = [...(formData.value.beijianIds ?? [])] @@ -1131,7 +1126,7 @@ const setDefaultSelections = () => { nextTick(() => { if (!multipleTableRef.value) return multipleTableRef.value.clearSelection() - const rawSubjectIds = toRaw(formData.value.componentIds) + const rawSubjectIds = (toRaw(formData.value.componentIds) ?? []).map((v) => String(v)) if (rawSubjectIds.length != 0) { let row = { id: undefined @@ -1140,7 +1135,7 @@ const setDefaultSelections = () => { } // 閬嶅巻鏁版嵁锛屾壘鍒伴渶瑕侀€変腑鐨勮 list.value.forEach((row) => { - if (rawSubjectIds.includes(row.id)) { + if (rawSubjectIds.includes(String(row.id))) { multipleTableRef.value!.toggleRowSelection(row, true) } }) @@ -1199,14 +1194,14 @@ const initFormData = () => ({ workshop: undefined, deviceLocation: undefined, systemOrg: undefined, - deviceManagerIds: [] as number[], + deviceManagerIds: [] as (number | string)[], productionDate: undefined, factoryEntryDate: undefined, sn: undefined, outgoingTime: undefined, remark: undefined, - componentIds: [] as number[], - beijianIds: [] as number[], + componentIds: [] as (number | string)[], + beijianIds: [] as (number | string)[], fileUrl: '', qrcodeUrl: undefined, templateJson: undefined, @@ -1302,29 +1297,31 @@ const findDeviceTypeName = (id: string | number): string | undefined => { return undefined } const users = ref([]) -type SelectionOption = { label: string; value: number } +type SelectionOption = { label: string; value: number | string } const criticalComponentOptions = ref([]) const beijianOptions = ref([]) const savedCriticalComponentOptions = ref([]) const savedBeijianOptions = ref([]) const editableCriticalComponentRows = ref([]) -const getCriticalComponentId = (item: any): number | undefined => - normalizeNumberish( +const getCriticalComponentId = (item: any): string | undefined => { + const raw = item?.componentId ?? - item?.criticalComponentId ?? - item?.criticalId ?? - item?.criticalComponent?.id ?? - item?.component?.id ?? - item?.id - ) + item?.criticalComponentId ?? + item?.criticalId ?? + item?.criticalComponent?.id ?? + item?.component?.id ?? + item?.id + if (raw === undefined || raw === null || raw === '') return undefined + return String(raw) +} const buildCriticalComponentOptions = (items: any[] = []): SelectionOption[] => (items ?? []) .map((item: any) => { - const id = normalizeNumberish(item?.id) - if (id === undefined) return undefined + if (item?.id === undefined || item?.id === null || item?.id === '') return undefined + const id = String(item.id) const code = item.code ? String(item.code) : '' const name = item.name ? String(item.name) : '' - const label = code && name ? `${code}-${name}` : name || code || String(id) + const label = code && name ? `${code}-${name}` : name || code || id return { label, value: id } }) .filter((item): item is SelectionOption => Boolean(item)) @@ -1332,24 +1329,24 @@ const buildCriticalComponentOptions = (items: any[] = []): SelectionOption[] => const buildBeijianOptions = (items: any[] = []): SelectionOption[] => (items ?? []) .map((item: any) => { - const id = normalizeNumberish(item?.id) - if (id === undefined) return undefined + if (item?.id === undefined || item?.id === null || item?.id === '') return undefined + const id = String(item.id) const code = item.barCode ? String(item.barCode) : '' const name = item.name ? String(item.name) : '' - const label = code && name ? `${code}-${name}` : name || code || String(id) + const label = code && name ? `${code}-${name}` : name || code || id return { label, value: id } }) .filter((item): item is SelectionOption => Boolean(item)) const mergeSelectionOptions = (...groups: SelectionOption[][]): SelectionOption[] => { - const optionMap = new Map() - groups.flat().forEach((item) => optionMap.set(item.value, item)) + const optionMap = new Map() + groups.flat().forEach((item) => optionMap.set(String(item.value), item)) return Array.from(optionMap.values()) } -const formatSelectedSummary = (ids: number[], options: SelectionOption[]) => { - const optionMap = new Map(options.map((item) => [item.value, item.label])) - const labels = ids.map((id) => optionMap.get(id)).filter((v): v is string => Boolean(v)) +const formatSelectedSummary = (ids: (number | string)[], options: SelectionOption[]) => { + const optionMap = new Map(options.map((item) => [String(item.value), item.label])) + const labels = ids.map((id) => optionMap.get(String(id))).filter((v): v is string => Boolean(v)) if (!labels.length) return '' if (labels.length <= 3) return labels.join(', ') return `${labels.slice(0, 3).join(', ')}...${labels.length}` @@ -1365,8 +1362,8 @@ const criticalComponentDisplay = computed(() => if (!list.value.length) { return formData.value.machineId ? String(formData.value.machineId) : '' } - const map = new Map(list.value.map((item) => [item.id, item.name])) - const names = ids.value.map((id) => map.get(id)).filter((name) => name) + const map = new Map(list.value.map((item) => [String(item.id), item.name])) + const names = ids.value.map((id) => map.get(String(id))).filter((name) => name) return names.join(',') } ) @@ -1385,17 +1382,17 @@ const buildCriticalComponentTableRows = () => { return detailList.map((item: any) => ({ ...item, count: normalizeNumberish(item?.count) ?? 0 })) } - const selectedIds = new Set( + const selectedIds = new Set( (formData.value.componentIds ?? []) - .map((id: any) => Number(id)) - .filter((id: number) => !Number.isNaN(id)) + .map((id: any) => String(id)) + .filter((id: string) => id !== '') ) if (!selectedIds.size) return [] - const optionMap = new Map() + const optionMap = new Map() ;[...criticalComponentOptions.value, ...savedCriticalComponentOptions.value].forEach( (item: any) => { - optionMap.set(Number(item.value), item) + optionMap.set(String(item.value), item) } ) @@ -1693,7 +1690,7 @@ const buildSubmitData = () => { const componentRows = editableCriticalComponentRows.value .map((row: any) => ({ ...row, - id: normalizeNumberish(row?.id), + id: row?.id != null && row?.id !== '' ? String(row.id) : undefined, count: normalizeNumberish(row?.count) ?? 0 })) .filter((row: any) => row.id !== undefined) @@ -1798,7 +1795,7 @@ const setBJDefaultSelections = () => { nextTick(() => { if (!bjMultipleTableRef.value) return bjMultipleTableRef.value.clearSelection() - const rawSubjectIds = toRaw(formData.value.beijianIds) + const rawSubjectIds = (toRaw(formData.value.beijianIds) ?? []).map((v) => String(v)) if (rawSubjectIds.length != 0) { let row = { id: undefined @@ -1807,7 +1804,7 @@ const setBJDefaultSelections = () => { } // 閬嶅巻鏁版嵁锛屾壘鍒伴渶瑕侀€変腑鐨勮 bjList.value.forEach((row) => { - if (rawSubjectIds.includes(row.id)) { + if (rawSubjectIds.includes(String(row.id))) { bjMultipleTableRef.value!.toggleRowSelection(row, true) } }) @@ -1872,22 +1869,22 @@ const handleCriticalComponentSelectConfirm = (payload: { }) => { formData.value.devices = payload.rows .map((item) => { - const id = Number(item.id) - if (!Number.isFinite(id)) return undefined + if (item?.id === undefined || item?.id === null || item?.id === '') return undefined + const id = String(item.id) return { id, name: item.deviceName || item.name || item.code || `璁惧ID:${id}` } }) - .filter((item): item is { id: number; name: string } => Boolean(item)) + .filter((item): item is { id: string; name: string } => Boolean(item)) selectedDeviceRows.value = payload.rows formData.value.componentIds = payload.ids.join(',') - ids.value = payload.ids.map((id) => Number(id)) + ids.value = payload.ids.map((id) => String(id)).filter((id) => id !== '') appendSelectedCriticalComponentRows(ids.value) } -const buildCriticalComponentRowById = (id: number) => { - const row = selectedRows.value.find((item: any) => normalizeNumberish(item.id) === id) +const buildCriticalComponentRowById = (id: string) => { + const row = selectedRows.value.find((item: any) => String(item.id) === String(id)) if (row) { return { ...row, @@ -1899,7 +1896,7 @@ const buildCriticalComponentRowById = (id: number) => { const option = mergeSelectionOptions( savedCriticalComponentOptions.value, criticalComponentOptions.value - ).find((item) => item.value === id) + ).find((item) => String(item.value) === String(id)) const label = option?.label ?? String(id) const [code, ...nameParts] = label.split('-') return { @@ -1913,21 +1910,21 @@ const buildCriticalComponentRowById = (id: number) => { } } -const appendSelectedCriticalComponentRows = (selectedIds: number[]) => { +const appendSelectedCriticalComponentRows = (selectedIds: (number | string)[]) => { const existingIds = new Set( editableCriticalComponentRows.value .map((row: any) => getCriticalComponentId(row)) - .filter((id): id is number => id !== undefined) + .filter((id): id is string => id !== undefined) ) const rowsToAppend = selectedIds - .filter((id) => !existingIds.has(id)) - .map((id) => buildCriticalComponentRowById(id)) + .filter((id) => !existingIds.has(String(id))) + .map((id) => buildCriticalComponentRowById(String(id))) if (rowsToAppend.length) { editableCriticalComponentRows.value = [...editableCriticalComponentRows.value, ...rowsToAppend] } } /** 鍒犻櫎鎸夐挳鎿嶄綔 */ -const buildIdsParam = (ids: number | number[]) => { +const buildIdsParam = (ids: number | string | (number | string)[]) => { return Array.isArray(ids) ? ids.join(',') : String(ids) } const handleDelete = async (id: string) => { @@ -1935,7 +1932,7 @@ const handleDelete = async (id: string) => { // 鍒犻櫎鐨勪簩娆$‘璁? await message.delConfirm() editableCriticalComponentRows.value = editableCriticalComponentRows.value.filter( - (item: any) => item.id !== id + (item: any) => String(item.id) !== String(id) ) await DeviceLedgerApi.deleteDeviceCriticalComponent(id) message.success(t('common.delSuccess')) diff --git a/src/views/mes/dvrepair/DvRepairForm.vue b/src/views/mes/dvrepair/DvRepairForm.vue index 7d7d6219..bb2fcdee 100644 --- a/src/views/mes/dvrepair/DvRepairForm.vue +++ b/src/views/mes/dvrepair/DvRepairForm.vue @@ -507,7 +507,7 @@ type RepairFormType = 'create' | 'update' | 'repair' | 'detail' | '' interface DvRepairFormData extends Partial { deviceId?: string - componentId?: number + componentId?: number | string isShutdown?: boolean isCode?: boolean faultLevel?: string @@ -631,7 +631,7 @@ const deviceDialogQueryParams = reactive({ }) const componentLoading = ref(false) -const componentOptions = ref<{ label: string; value: number }[]>([]) +const componentOptions = ref<{ label: string; value: number | string }[]>([]) const users = ref([]) @@ -681,19 +681,19 @@ const normalizeUserId = (value: any) => { } const upsertDeviceOption = ( - options: { label: string; value: number; raw?: DeviceLedgerVO }[], - option: { label: string; value: number; raw?: DeviceLedgerVO } + options: { label: string; value: number | string; raw?: DeviceLedgerVO }[], + option: { label: string; value: number | string; raw?: DeviceLedgerVO } ) => { - const existed = options.some((item) => item.value === option.value) + const existed = options.some((item) => String(item.value) === String(option.value)) return existed ? options : [option, ...options] } const toComponentOption = (item: any) => { - const id = typeof item?.id === 'number' ? item.id : Number(item?.id) - if (Number.isNaN(id)) return undefined + if (item?.id === undefined || item?.id === null || item?.id === '') return undefined + const id = String(item.id) const code = item?.code ?? item?.componentCode ?? item?.subjectCode const name = item?.name ?? item?.componentName ?? item?.subjectName - const label = `${code ?? ''} ${name ?? ''}`.trim() || String(id) + const label = `${code ?? ''} ${name ?? ''}`.trim() || id return { label, value: id } } @@ -702,7 +702,7 @@ const loadComponentOptionsByDeviceId = async (deviceId: string) => { try { const data = await RepairItemsApi.getComponentList(deviceId) const rows = (Array.isArray(data) ? data : data?.list ?? data?.data ?? []) as any[] - componentOptions.value = rows.map(toComponentOption).filter(Boolean) as { label: string; value: number }[] + componentOptions.value = rows.map(toComponentOption).filter(Boolean) as { label: string; value: number | string }[] } finally { componentLoading.value = false } @@ -884,7 +884,7 @@ watch( if (isHydrating.value) return if (formData.value.machineryTypeId !== 2) return const deviceId = formData.value.deviceId - if (deviceId == null || deviceId === '' || typeof componentId !== 'number') { + if (deviceId == null || deviceId === '' || componentId === undefined || componentId === null || componentId === '') { setLineRows([]) return } @@ -1055,7 +1055,7 @@ const setLineRows = (rows: any[]) => { dvRepairLineFormRef.value?.setData(rows) } -const prefillLinesByDeviceOrComponent = async (params: { deviceId: string; componentId?: number; deviceType: number }) => { +const prefillLinesByDeviceOrComponent = async (params: { deviceId: string; componentId?: number | string; deviceType: number }) => { if (formType.value !== 'create') return const data = await RepairItemsApi.getDeviceOrComponentList(params) const list = normalizeDeviceOrComponentList(data) @@ -1113,11 +1113,8 @@ const open = async (type: string, id?: number) => { if (formData.value.machineryTypeId === 2 && formData.value.deviceId != null && formData.value.deviceId !== '') { await loadComponentOptionsByDeviceId(formData.value.deviceId) - const componentId = typeof formData.value.componentId === 'number' - ? formData.value.componentId - : Number(formData.value.componentId) - if (!Number.isNaN(componentId)) { - formData.value.componentId = componentId + if (formData.value.componentId !== undefined && formData.value.componentId !== null && formData.value.componentId !== '') { + formData.value.componentId = String(formData.value.componentId) } } await nextTick()