fix: 设备管理的任务计划和维修工单-修复雪花算法ID精度丢失问题

main
zhongwenkai 4 hours ago
parent c75e31aab5
commit ec337f1921

@ -506,7 +506,7 @@ defineOptions({ name: 'DvRepairForm' })
type RepairFormType = 'create' | 'update' | 'repair' | 'detail' | ''
interface DvRepairFormData extends Partial<DvRepairVO> {
deviceId?: number
deviceId?: string
componentId?: number
isShutdown?: boolean
isCode?: boolean
@ -607,13 +607,13 @@ const showComponentSelect = computed(() => formData.value.machineryTypeId === 2)
const selectedDeviceText = computed(() => {
const deviceId = formData.value.deviceId
if (typeof deviceId !== 'number') return ''
const option = deviceOptions.value.find((item) => item.value === deviceId)
if (deviceId == null || deviceId === '') return ''
const option = deviceOptions.value.find((item) => String(item.value) === String(deviceId))
return option?.label || `ID:${deviceId}`
})
const deviceLoading = ref(false)
const deviceOptions = ref<{ label: string; value: number; raw?: DeviceLedgerVO }[]>([])
const deviceOptions = ref<{ label: string; value: string | number; raw?: DeviceLedgerVO }[]>([])
const deviceOptionsLoaded = ref(false)
const deviceDialogVisible = ref(false)
@ -697,7 +697,7 @@ const toComponentOption = (item: any) => {
return { label, value: id }
}
const loadComponentOptionsByDeviceId = async (deviceId: number) => {
const loadComponentOptionsByDeviceId = async (deviceId: string) => {
componentLoading.value = true
try {
const data = await RepairItemsApi.getComponentList(deviceId)
@ -810,7 +810,7 @@ const confirmDeviceSelection = (row?: DeviceLedgerVO) => {
return
}
const id = Number(selected.id)
const id = String(selected.id)
const label = `${selected.deviceCode ?? ''} ${selected.deviceName ?? ''}`.trim()
deviceOptions.value = upsertDeviceOption(deviceOptions.value, { label, value: id, raw: selected })
formData.value.deviceId = id
@ -854,12 +854,12 @@ watch(
if (isHydrating.value) return
formData.value.componentId = undefined
componentOptions.value = []
if (typeof deviceId !== 'number') {
if (deviceId == null || deviceId === '') {
setLineRows([])
return
}
const option = deviceOptions.value.find((item) => item.value === deviceId)
const option = deviceOptions.value.find((item) => String(item.value) === String(deviceId))
if (option?.raw) {
formData.value.machineryCode = option.raw.deviceCode
formData.value.machineryName = option.raw.deviceName
@ -883,7 +883,7 @@ watch(
if (isHydrating.value) return
if (formData.value.machineryTypeId !== 2) return
const deviceId = formData.value.deviceId
if (typeof deviceId !== 'number' || typeof componentId !== 'number') {
if (deviceId == null || deviceId === '' || typeof componentId !== 'number') {
setLineRows([])
return
}
@ -1103,14 +1103,14 @@ const open = async (type: string, id?: number) => {
formData.value.machineryTypeId = Number.isNaN(typeId) ? formData.value.machineryTypeId : typeId
const deviceId = formData.value.deviceId
const resolvedDeviceId = typeof deviceId === 'number' ? deviceId : formData.value.machineryId
if (typeof resolvedDeviceId === 'number') {
const resolvedDeviceId = (deviceId != null && deviceId !== '') ? deviceId : formData.value.machineryId
if (resolvedDeviceId != null && resolvedDeviceId !== '') {
formData.value.deviceId = resolvedDeviceId
const label = `${formData.value.machineryCode ?? ''} ${formData.value.machineryName ?? ''}`.trim() || `ID:${resolvedDeviceId}`
deviceOptions.value = upsertDeviceOption(deviceOptions.value, { label, value: resolvedDeviceId })
}
if (formData.value.machineryTypeId === 2 && typeof formData.value.deviceId === '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

@ -416,7 +416,7 @@ const formData = ref({
name: undefined as string | undefined,
taskType: undefined as number | undefined,
deviceList: [] as string[],
projectForm: undefined as number | undefined,
projectForm: undefined as string | undefined,
dateRange: [] as string[],
cronExpression: undefined as string | undefined,
operableUsers: [] as string[],
@ -492,8 +492,7 @@ const open = async (type: string, row?: TaskManagementVO) => {
formData.value.deviceList = parseIdsValue((row as any).deviceList)
const projectFormIds = parseIdsValue((row as any).projectForm)
if (projectFormIds.length) {
const n = Number(projectFormIds[0])
formData.value.projectForm = Number.isFinite(n) ? n : undefined
formData.value.projectForm = projectFormIds[0] || undefined
const projectFormName = String((row as any).projectFormName ?? '').trim()
if (formData.value.projectForm !== undefined && projectFormName) {
planSelectionCache.value[String(formData.value.projectForm)] = {
@ -664,8 +663,8 @@ const confirmPlanSelection = (row?: PlanOption) => {
return
}
const id = Number(selected.id)
formData.value.projectForm = Number.isFinite(id) ? id : undefined
const id = String(selected.id)
formData.value.projectForm = id || undefined
cachePlanRows([selected])
planDialogVisible.value = false
formRef.value?.clearValidate?.('projectForm')

@ -301,7 +301,7 @@ type PlanOption = {
}
const planOptions = ref<PlanOption[]>([])
const deviceOptions = ref<{ id: number; label: string; raw?: DeviceLedgerVO }[]>([])
const deviceOptions = ref<{ id: string | number; label: string; raw?: DeviceLedgerVO }[]>([])
const users = ref<UserVO[]>([])
const queryParams = reactive({
@ -339,7 +339,7 @@ const ensureDeviceOptionsLoaded = async () => {
const deviceRes = await DeviceLedgerApi.getDeviceLedgerList()
const rows = (Array.isArray(deviceRes) ? deviceRes : deviceRes?.list ?? deviceRes?.data ?? []) as DeviceLedgerVO[]
deviceOptions.value = rows
.filter((item) => typeof item?.id === 'number')
.filter((item) => item?.id != null)
.map((item) => ({
id: item.id,
label: `${item.deviceCode ?? ''} ${item.deviceName ?? ''}`.trim() || String(item.id),

Loading…
Cancel
Save