style:设备关键件/采集设备模型-导入按钮添加报错提示

main
黄伟杰 3 weeks ago
parent c5cd170d47
commit d99a461d79

@ -147,6 +147,7 @@ import { DeviceModelAttributeApi, DeviceModelAttributeVO } from '@/api/iot/devic
import DeviceModelAttributeForm from './DeviceModelAttributeForm.vue' import DeviceModelAttributeForm from './DeviceModelAttributeForm.vue'
import { DeviceAttributeTypeApi, DeviceAttributeTypeVO } from '@/api/iot/deviceattributetype' import { DeviceAttributeTypeApi, DeviceAttributeTypeVO } from '@/api/iot/deviceattributetype'
import { getAccessToken, getTenantId } from '@/utils/auth' import { getAccessToken, getTenantId } from '@/utils/auth'
import { ElMessageBox } from 'element-plus'
const props = defineProps<{ const props = defineProps<{
id?: number // id id?: number // id
@ -189,6 +190,15 @@ const uploadHeaders = ref()
const importFileList = ref([]) const importFileList = ref([])
const updateSupport = ref(0) const updateSupport = ref(0)
const escapeHtml = (value: unknown) => {
return String(value ?? '')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
}
const selectedIds = ref<number[]>([]) const selectedIds = ref<number[]>([])
const handleSelectionChange = (rows: any[]) => { const handleSelectionChange = (rows: any[]) => {
selectedIds.value = rows?.map((row) => row.id).filter((id) => id !== undefined) ?? [] selectedIds.value = rows?.map((row) => row.id).filter((id) => id !== undefined) ?? []
@ -318,13 +328,29 @@ const submitImport = async () => {
uploadRef.value?.submit() uploadRef.value?.submit()
} }
const handleImportSuccess = (response: any) => { const handleImportSuccess = async (response: any) => {
if (!response || response.code !== 0) { if (!response || response.code !== 0) {
message.error(response?.msg || '导入失败') message.error(response?.msg || '导入失败')
importLoading.value = false importLoading.value = false
return return
} }
message.success('导入成功') const failureCodes = response?.data?.failureCodes
if (failureCodes && typeof failureCodes === 'object') {
const entries = Object.entries(failureCodes).filter(([key]) => String(key).trim() !== '')
if (entries.length > 0) {
const detail = entries
.map(([code, err], index) => `${index + 1}. ${escapeHtml(code)}${escapeHtml(err)}`)
.join('<br />')
await ElMessageBox.alert(`以下点位编码导入失败:<br />${detail}`, t('common.confirmTitle'), {
type: 'error',
dangerouslyUseHTMLString: true,
})
} else {
message.success('导入成功')
}
} else {
message.success('导入成功')
}
importLoading.value = false importLoading.value = false
importDialogVisible.value = false importDialogVisible.value = false
getList() getList()

@ -145,6 +145,7 @@ import download from '@/utils/download'
import { CriticalComponentApi, CriticalComponentVO } from '@/api/mes/criticalComponent' import { CriticalComponentApi, CriticalComponentVO } from '@/api/mes/criticalComponent'
import { getAccessToken, getTenantId } from '@/utils/auth' import { getAccessToken, getTenantId } from '@/utils/auth'
import CriticalComponentForm from './CriticalComponentForm.vue' import CriticalComponentForm from './CriticalComponentForm.vue'
import { ElMessageBox } from 'element-plus'
defineOptions({ name: 'CriticalComponent' }) defineOptions({ name: 'CriticalComponent' })
@ -178,6 +179,15 @@ const uploadHeaders = ref()
const importFileList = ref([]) const importFileList = ref([])
const updateSupport = ref(0) const updateSupport = ref(0)
const escapeHtml = (value: unknown) => {
return String(value ?? '')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
}
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
@ -267,13 +277,29 @@ const submitImport = async () => {
uploadRef.value?.submit() uploadRef.value?.submit()
} }
const handleImportSuccess = (response: any) => { const handleImportSuccess = async (response: any) => {
if (!response || response.code !== 0) { if (!response || response.code !== 0) {
message.error(response?.msg || '导入失败') message.error(response?.msg || '导入失败')
importLoading.value = false importLoading.value = false
return return
} }
message.success('导入成功') const failureCodes = response?.data?.failureCodes
if (failureCodes && typeof failureCodes === 'object') {
const entries = Object.entries(failureCodes).filter(([key]) => String(key).trim() !== '')
if (entries.length > 0) {
const detail = entries
.map(([code, err], index) => `${index + 1}. ${escapeHtml(code)}${escapeHtml(err)}`)
.join('<br />')
await ElMessageBox.alert(`以下编码导入失败:<br />${detail}`, t('common.confirmTitle'), {
type: 'error',
dangerouslyUseHTMLString: true,
})
} else {
message.success('导入成功')
}
} else {
message.success('导入成功')
}
importLoading.value = false importLoading.value = false
importDialogVisible.value = false importDialogVisible.value = false
getList() getList()

Loading…
Cancel
Save