From bff5c09118f44f0bc8485b00c2f6c08faf7a8f0c Mon Sep 17 00:00:00 2001 From: sheng <905537351@qq.com> Date: Fri, 26 Jun 2026 17:54:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=82=E5=B8=B8=E4=B8=8D?= =?UTF-8?q?=E8=89=AF=E7=AE=A1=E7=90=86=E5=88=86=E9=A1=B5=E5=92=8C=E7=B1=BB?= =?UTF-8?q?=E5=88=AB=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/locales/en.json | 3 +- src/locales/zh-chs.json | 3 +- .../product-model/product-ng-info/index.vue | 50 +++++++++++++------ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index cf8570c0..246122c3 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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", diff --git a/src/locales/zh-chs.json b/src/locales/zh-chs.json index ce4abdec..84e602db 100644 --- a/src/locales/zh-chs.json +++ b/src/locales/zh-chs.json @@ -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": "编 辑", diff --git a/src/views/production-master-data/product-model/product-ng-info/index.vue b/src/views/production-master-data/product-model/product-ng-info/index.vue index ff76fcf7..09e831e6 100644 --- a/src/views/production-master-data/product-model/product-ng-info/index.vue +++ b/src/views/production-master-data/product-model/product-ng-info/index.vue @@ -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 }) },