修复异常不良管理分页和类别显示
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", "exception_ng_category": "Error/NG Category",
"remark": "Remark", "remark": "Remark",
"enter_remark": "Please enter 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", "operation": "Action",
"add": "Add", "add": "Add",
"edit": "Edit", "edit": "Edit",

View File

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

View File

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