黄伟杰 3 days ago
commit 6c334890ed

@ -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<CriticalComponentVO>) => {
@ -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)}`
})

@ -807,8 +807,8 @@ const message = useMessage() // 娑堟伅寮圭獥
const loading = ref(true)
const total = ref(0)
const bjTotal = ref(0)
const selectedIds = ref<number[]>([])
const bjSelectedIds = ref<number[]>([])
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<any[]>([]) // 瀛樺偍鎵€鏈夐€変腑鐨勮
//
const multipleTableRef = ref<InstanceType<typeof ElTable>>()
const bjMultipleTableRef = ref<InstanceType<typeof ElTable>>()
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<UserVO[]>([])
type SelectionOption = { label: string; value: number }
type SelectionOption = { label: string; value: number | string }
const criticalComponentOptions = ref<SelectionOption[]>([])
const beijianOptions = ref<SelectionOption[]>([])
const savedCriticalComponentOptions = ref<SelectionOption[]>([])
@ -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<number, SelectionOption>()
groups.flat().forEach((item) => optionMap.set(item.value, item))
const optionMap = new Map<string, SelectionOption>()
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<number[]>([])
const beijianDraft = ref<number[]>([])
const criticalComponentDraft = ref<(number | string)[]>([])
const beijianDraft = ref<(number | string)[]>([])
const formatSelectedSummary = (ids: number[], options: { label: string; value: number }[]) => {
const optionMap = new Map<number, string>(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<string, string>(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<number[]>([])
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<number[]>([])
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)
}
})

@ -874,15 +874,15 @@ const updateActionBarRectAfterLayout = () => {
}
const criticalComponentDialogVisible = ref(false)
const beijianDialogVisible = ref(false)
const criticalComponentDraft = ref<number[]>([])
const beijianDraft = ref<number[]>([])
const criticalComponentDraft = ref<(number | string)[]>([])
const beijianDraft = ref<(number | string)[]>([])
const list = ref<CriticalComponentVO[]>([])
const bjList = ref<ProductVO[]>([])
const loading = ref(true)
const total = ref(0)
const bjTotal = ref(0)
const selectedIds = ref<number[]>([])
const bjSelectedIds = ref<number[]>([])
const selectedIds = ref<(number | string)[]>([])
const bjSelectedIds = ref<(number | string)[]>([])
//
const multipleTableRef = ref<InstanceType<typeof ElTable>>()
const bjMultipleTableRef = ref<InstanceType<typeof ElTable>>()
@ -896,13 +896,13 @@ const iotDeviceTotal = ref(0)
const iotDeviceSelectedLabel = ref('')
const iotDeviceDraftId = ref<string | undefined>()
const iotDeviceDraftRow = ref<DeviceVO | undefined>()
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<any[]>([]) //
const bjSelectedRows = ref<any[]>([]) //
@ -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<any[]>([])
const ids = ref<number[]>([])
const bjIds = ref<number[]>([])
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<UserVO[]>([])
type SelectionOption = { label: string; value: number }
type SelectionOption = { label: string; value: number | string }
const criticalComponentOptions = ref<SelectionOption[]>([])
const beijianOptions = ref<SelectionOption[]>([])
const savedCriticalComponentOptions = ref<SelectionOption[]>([])
const savedBeijianOptions = ref<SelectionOption[]>([])
const editableCriticalComponentRows = ref<any[]>([])
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<number, SelectionOption>()
groups.flat().forEach((item) => optionMap.set(item.value, item))
const optionMap = new Map<string, SelectionOption>()
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<number, string>(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<string, string>(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<number>(
const selectedIds = new Set<string>(
(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<number, any>()
const optionMap = new Map<string, any>()
;[...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'))

@ -507,7 +507,7 @@ type RepairFormType = 'create' | 'update' | 'repair' | 'detail' | ''
interface DvRepairFormData extends Partial<DvRepairVO> {
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<UserVO[]>([])
@ -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()

Loading…
Cancel
Save