修复异常不良管理分页和类别显示
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-26 17:54:41 +08:00
parent 6daa09918c
commit bff5c09118
3 changed files with 39 additions and 17 deletions

View File

@@ -482,7 +482,8 @@
"exception_ng_category": "Error/NG Category",
"remark": "Remark",
"enter_remark": "Please enter remark",
"remark_length": "Length 1 to 100 characters",
"remark_length": "Length must be between 1 and 100 characters",
"load_device_category_failed": "Failed to load device categories. Please try again later",
"operation": "Action",
"add": "Add",
"edit": "Edit",

View File

@@ -482,7 +482,8 @@
"exception_ng_category": "异常不良类别",
"remark": "备注",
"enter_remark": "请输入备注",
"remark_length": "长度在1到100个字符",
"remark_length": "长度需在 1 到 100 个字符",
"load_device_category_failed": "设备类别加载失败,请稍后重试",
"operation": "操作",
"add": "新 增",
"edit": "编 辑",

View File

@@ -9,6 +9,7 @@
:placeholder="$t(key('select_device_category'))"
clearable
filterable
:loading="deviceCategoryLoading"
style="width:200px"
@focus="loadDeviceCategories"
>
@@ -137,6 +138,7 @@ export default {
importVisible: false,
search: { device_category_id: '', type: '', number: '', explain: '' },
pagination: { current: 1, size: 10, total: 0 },
deviceCategoryLoading: false,
deviceCategoryOptions: [],
formData: { device_category_id: '', type: '', number: '', explain: '', note: '' },
rules: {
@@ -184,8 +186,8 @@ export default {
clearable: true,
style: { width: '90%' },
options: [
{ label: 'ERR', value: 'ERR' },
{ label: 'NG', value: 'NG' }
{ label: this.$t(this.key('type_error')), value: 'ERR' },
{ label: this.$t(this.key('type_ng')), value: 'NG' }
]
}
],
@@ -292,22 +294,33 @@ export default {
})
},
methods: {
getTotal (source, fallback) {
if (!source || typeof source !== 'object') return fallback
const total = source.count ?? source.total ?? source.total_count ?? source.record_count ?? source.recordsTotal
const value = Number(total)
if (!Number.isNaN(value)) return value
if (source.pagination) return this.getTotal(source.pagination, fallback)
return fallback
},
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) }
const containers = [res, res && res.data, res && res.data && res.data.data].filter(Boolean)
for (const item of containers) {
if (Array.isArray(item)) {
return { list: item, total: this.getTotal(res, item.length) }
}
const list = item.data || item.list || item.rows || item.records || item.items
if (Array.isArray(list)) {
return { list, total: this.getTotal(item, this.getTotal(res, 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 deviceCategory = typeof row.DeviceCategory === 'object'
? row.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,
@@ -360,11 +373,16 @@ export default {
},
async loadDeviceCategories () {
if (this.deviceCategoryOptions.length) return
this.deviceCategoryLoading = true
try {
const res = await getDeviceCategoryAll({})
this.deviceCategoryOptions = this.normalizeOptions(res)
this.searchFormDeviceCategoryUpdate()
} catch { /* ignore */ }
} catch {
this.$message.error(this.$t(this.key('load_device_category_failed')))
} finally {
this.deviceCategoryLoading = false
}
},
searchFormDeviceCategoryUpdate () {
const catCol = this.formCols[0] && this.formCols[0][0]
@@ -384,6 +402,7 @@ export default {
this.handleType = 'create'
this.dialogTitle = this.key('add_exception_ng_category')
this.loadDeviceCategories().then(() => {
if (!this.deviceCategoryOptions.length) return
this.$nextTick(() => {
this.$refs.dialogForm && this.$refs.dialogForm.reset()
this.resetForm()
@@ -403,6 +422,7 @@ export default {
note: row.note || ''
}
this.loadDeviceCategories().then(() => {
if (!this.deviceCategoryOptions.length) return
this.dialogVisible = true
})
},