修复异常不良管理列表和表单问题
Some checks failed
Release pipeline / publish (push) Has been cancelled
Release pipeline / Always run job (push) Has been cancelled

This commit is contained in:
sheng
2026-06-24 16:52:40 +08:00
parent 841095e6d3
commit 7a11f50e39

View File

@@ -14,9 +14,9 @@
>
<el-option
v-for="item in deviceCategoryOptions"
:key="item.id"
:label="item.name"
:value="item.id"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
@@ -74,7 +74,11 @@
auto-height
@page-change="onPageChange"
@selection-change="onSelect"
/>
>
<template #col-type="{ row }">
<span>{{ typeText(row.type) }}</span>
</template>
</page-table>
<page-dialog-form
ref="dialogForm"
@@ -168,7 +172,6 @@ export default {
clearable: true,
style: { width: '90%' },
options: [],
keys: { label: 'name', value: 'id' },
onFocus: this.onFormDeviceCategoryFocus
}
],
@@ -181,10 +184,9 @@ export default {
clearable: true,
style: { width: '90%' },
options: [
{ name: this.key('type_error'), code: 'ERR' },
{ name: this.key('type_ng'), code: 'NG' }
],
keys: { label: 'name', value: 'code' }
{ label: this.key('type_error'), value: 'ERR' },
{ label: this.key('type_ng'), value: 'NG' }
]
}
],
[
@@ -222,9 +224,8 @@ export default {
]
this.columns = useTableColumns([
{ type: 'selection', width: 55 },
{ prop: 'device_category_name', label: this.key('device_category'), minWidth: 140 },
{ prop: 'type', label: this.key('exception_ng_category'), minWidth: 120 },
{ prop: 'type', label: this.key('exception_ng_category'), minWidth: 120, slot: 'type' },
{ prop: 'number', label: this.key('ng_code'), minWidth: 140 },
{ prop: 'explain', label: this.key('ng_name'), minWidth: 140 },
{ prop: 'note', label: this.key('remark'), minWidth: 200 },
@@ -286,9 +287,45 @@ export default {
}, this.$permission)
this.toolbarButtons = btns.toolbarButtons
this.rowButtons = btns.rowButtons
this.loadDeviceCategories().then(() => {
this.fetchData()
})
},
methods: {
normalizeResponse (res) {
const root = res || {}
const data = res && res.data !== undefined ? res.data : res
if (Array.isArray(data)) return { list: data, total: Number(root.count || root.total || data.length) }
if (data && Array.isArray(data.list)) return { list: data.list, total: Number(root.count || root.total || data.count || data.total || data.list.length) }
if (data && Array.isArray(data.rows)) return { list: data.rows, total: Number(root.count || root.total || data.count || data.total || data.rows.length) }
if (data && Array.isArray(data.records)) return { list: data.records, total: Number(root.count || root.total || data.count || data.total || data.records.length) }
if (data && Array.isArray(data.data)) return { list: data.data, total: Number(root.count || root.total || data.count || data.total || data.data.length) }
if (data && data.data && Array.isArray(data.data.data)) return { list: data.data.data, total: Number(root.count || root.total || data.count || data.total || data.data.count || data.data.total || data.data.data.length) }
if (data && data.data && Array.isArray(data.data.list)) return { list: data.data.list, total: Number(root.count || root.total || data.count || data.total || data.data.count || data.data.total || data.data.list.length) }
return { list: [], total: 0 }
},
normalizeRow (row) {
const deviceCategory = typeof row.device_category === 'object'
? row.device_category
: (typeof row.category === 'object' ? row.category : {})
const option = this.deviceCategoryOptions.find(item => String(item.value) === String(row.device_category_id || deviceCategory.id || ''))
return {
...row,
device_category_id: row.device_category_id || deviceCategory.id || '',
device_category_name: row.device_category_name || deviceCategory.name || row.category_name || (option && option.label) || (typeof row.device_category === 'string' ? row.device_category : '')
}
},
normalizeOptions (res) {
return this.normalizeResponse(res).list.map(item => ({
label: item.name || item.label || item.code || item.id,
value: item.id !== undefined ? item.id : item.value
})).filter(item => item.value !== undefined && item.value !== null && item.value !== '')
},
typeText (type) {
if (type === 'ERR') return this.$t(this.key('type_error'))
if (type === 'NG') return this.$t(this.key('type_ng'))
return type
},
async fetchData () {
this.loading = true
try {
@@ -297,11 +334,9 @@ export default {
page_no: this.pagination.current,
page_size: this.pagination.size
})
const data = Array.isArray(res) ? res : (res.data || {})
const list = Array.isArray(data) ? data : (data.data || [])
const total = Array.isArray(data) ? data.length : (data.count || 0)
this.tableData = list
this.pagination.total = total
const data = this.normalizeResponse(res)
this.tableData = data.list.map(this.normalizeRow)
this.pagination.total = data.total
} finally {
this.loading = false
}
@@ -327,8 +362,7 @@ export default {
if (this.deviceCategoryOptions.length) return
try {
const res = await getDeviceCategoryAll({})
const list = Array.isArray(res) ? res : (res.data || [])
this.deviceCategoryOptions = Array.isArray(list) ? list : []
this.deviceCategoryOptions = this.normalizeOptions(res)
this.searchFormDeviceCategoryUpdate()
} catch { /* ignore */ }
},
@@ -349,18 +383,18 @@ export default {
openAdd () {
this.handleType = 'create'
this.dialogTitle = this.key('add_exception_ng_category')
this.loadDeviceCategories()
this.loadDeviceCategories().then(() => {
this.$nextTick(() => {
this.$refs.dialogForm && this.$refs.dialogForm.reset()
this.resetForm()
this.dialogVisible = true
})
})
},
openEdit (row) {
this.handleType = 'edit'
this.dialogTitle = this.key('edit_exception_ng_category')
this.editId = row.id
this.loadDeviceCategories()
this.formData = {
device_category_id: row.device_category_id || '',
type: row.type || '',
@@ -368,7 +402,9 @@ export default {
explain: row.explain || '',
note: row.note || ''
}
this.loadDeviceCategories().then(() => {
this.dialogVisible = true
})
},
async onDialogSubmit () {
this.submitting = true