fix: 修复精度丢失问题

main
zhongwenkai 1 day ago
parent 0736edf8af
commit 7e8242aa58

@ -252,8 +252,8 @@ const currentDeviceRelationRow = ref<any>()
const currentProductData = ref<any>()
const selectedDeviceRows = ref<any[]>([])
const deviceRelationForm = reactive({
productId: undefined as number | undefined,
devices: [] as { id: number; name: string }[]
productId: undefined as string | undefined,
devices: [] as { id: string; name: string }[]
})
const deviceColumns = computed(() => [
@ -304,7 +304,7 @@ const taskDetailRequestMap = new Map<string, Promise<any[]>>()
const currentDetailRequestId = ref(0)
const taskTableBusy = computed(() => taskLoading.value || taskSelectionLoading.value)
const getRelationName = (item: Record<string, any>, nameKeys: string[], fallbackPrefix: string, id: number) => {
const getRelationName = (item: Record<string, any>, nameKeys: string[], fallbackPrefix: string, id: string) => {
for (const key of nameKeys) {
const value = item[key]
if (value !== undefined && value !== null && String(value).trim() !== '') {
@ -318,11 +318,11 @@ const normalizeRelationList = (
fallbackRows: any[] | undefined,
nameKeys: string[],
fallbackPrefix: string
): { id: number; name: string }[] => {
const fallbackMap = new Map<number, string>()
): { id: string; name: string }[] => {
const fallbackMap = new Map<string, string>()
;(fallbackRows || []).forEach((row) => {
const id = Number(row?.id)
if (!Number.isFinite(id)) return
const id = String(row?.id)
if (!id || id === 'undefined' || id === 'null') return
fallbackMap.set(id, getRelationName(row, nameKeys, fallbackPrefix, id))
})
const parseArray = (source: unknown): any[] => {
@ -342,23 +342,23 @@ const normalizeRelationList = (
return parseArray(value)
.map((item) => {
if (typeof item === 'object' && item !== null) {
const id = Number((item as any).id)
if (!Number.isFinite(id)) return undefined
const id = String((item as any).id)
if (!id || id === 'undefined' || id === 'null') return undefined
return {
id,
name: getRelationName(item as any, nameKeys, fallbackPrefix, id)
}
}
const id = Number(item)
if (!Number.isFinite(id)) return undefined
const id = String(item)
if (!id || id === 'undefined' || id === 'null') return undefined
return {
id,
name: fallbackMap.get(id) || `${fallbackPrefix}ID:${id}`
}
})
.filter((item): item is { id: number; name: string } => Boolean(item))
.filter((item): item is { id: string; name: string } => Boolean(item))
}
const toDeviceRows = (devices: { id: number; name: string }[]) => {
const toDeviceRows = (devices: { id: string; name: string }[]) => {
return devices.map((item) => ({
id: item.id,
deviceName: item.name,
@ -625,7 +625,7 @@ const openDeviceRelationDialog = async (row: any) => {
deviceRelationLoading.value = true
selectedDeviceRows.value = []
try {
const productData = await ProductApi.getProduct(Number(row.productId))
const productData = await ProductApi.getProduct(String(row.productId))
currentProductData.value = productData
const devices = normalizeRelationList(
(productData as any).devices ?? (productData as any).deviceIds,
@ -633,7 +633,7 @@ const openDeviceRelationDialog = async (row: any) => {
['name', 'deviceName', 'code'],
t('ProductionPlan.TaskSummary.deviceColumnName')
)
deviceRelationForm.productId = Number(row.productId)
deviceRelationForm.productId = String(row.productId)
deviceRelationForm.devices = devices
selectedDeviceRows.value = toDeviceRows(devices)
} finally {
@ -656,7 +656,7 @@ const handleDeviceSelectConfirm = (payload: { ids: (number | string)[]; rows: an
name: item.deviceName || item.name || item.code || `${t('ProductionPlan.TaskSummary.deviceColumnName')}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
}
const refreshDetailListAfterDeviceSaved = async () => {

Loading…
Cancel
Save