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