fix: 修复精度丢失问题

main
zhongwenkai 2 days ago
parent 0736edf8af
commit 7e8242aa58

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

Loading…
Cancel
Save