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

main
zhongwenkai 2 days ago
parent c75e31aab5
commit ec337f1921

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

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

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

Loading…
Cancel
Save