From 8b259116296c5a41483f0027bcf858429f89beed Mon Sep 17 00:00:00 2001 From: sheng <905537351@qq.com> Date: Wed, 24 Jun 2026 17:57:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSPC=E9=87=87=E9=9B=86?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=A1=A8=E6=A0=BC=E6=95=B0=E6=8D=AE=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data-collection-configuration/index.vue | 157 ++++++++++++++++-- 1 file changed, 144 insertions(+), 13 deletions(-) diff --git a/src/views/production-master-data/spc-configuration/data-collection-configuration/index.vue b/src/views/production-master-data/spc-configuration/data-collection-configuration/index.vue index e7f62590..491e3282 100644 --- a/src/views/production-master-data/spc-configuration/data-collection-configuration/index.vue +++ b/src/views/production-master-data/spc-configuration/data-collection-configuration/index.vue @@ -66,7 +66,11 @@ auto-height @page-change="onPageChange" @selection-change="onSelect" - /> + > + + this.normalizeRow(row, index)) + this.pagination.total = data.total } finally { this.loading = false } }, + normalizeResponse (res) { + if (Array.isArray(res)) { + return { list: res, total: res.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.list || item.rows || item.records || item.results || item.items + if (Array.isArray(list)) { + return { + list, + total: this.getTotal(item, this.getTotal(res, list.length)) + } + } + } + + return { list: [], total: 0 } + }, + getTotal (source, fallback) { + if (!source) return fallback + const total = source.count ?? source.total ?? source.total_count ?? source.record_count + const value = Number(total) + return Number.isNaN(value) ? fallback : value + }, + firstValue (row, keys, defaultValue = '') { + if (!row) return defaultValue + for (const key of keys) { + const value = row[key] + if (value !== undefined && value !== null && value !== '') { + return value + } + } + return defaultValue + }, + normalizeCollectType (value) { + const text = String(value || '').toLowerCase() + const map = { + realtime: 'real_time', + real_time: 'real_time', + real: 'real_time', + periodic: 'periodic', + period: 'periodic', + cycle: 'periodic', + trigger: 'trigger', + event: 'trigger' + } + return map[text] || value || '' + }, + collectTypeText (value) { + const type = this.normalizeCollectType(value) + const map = { + real_time: this.key('real_time'), + periodic: this.key('periodic'), + trigger: this.key('trigger') + } + return map[type] ? this.$t(map[type]) : (value || '') + }, + normalizeStatus (row) { + const status = this.firstValue(row, ['status', 'enable', 'enabled', 'is_enable', 'active'], '') + if (typeof status === 'boolean') return status ? 1 : 0 + if (typeof status === 'number') return status + const text = String(status).toLowerCase() + if (['1', 'true', 'enable', 'enabled', 'active', 'yes'].includes(text)) return 1 + if (['0', 'false', 'disable', 'disabled', 'inactive', 'no'].includes(text)) return 0 + return status + }, + statusText (status) { + if (status === 1 || status === '1') return this.$t(this.key('enable')) + if (status === 0 || status === '0') return this.$t(this.key('disable')) + return status || '' + }, + normalizeRow (row, index) { + const sortIndex = typeof index === 'number' ? index + 1 : '' + const collectType = this.normalizeCollectType(this.firstValue(row, [ + 'collect_type', + 'collection_type', + 'type', + 'category' + ], '')) + const status = this.normalizeStatus(row) + + return { + ...row, + id: this.firstValue(row, ['id', 'binding_scada_node_id', 'config_id']), + sort: this.firstValue(row, ['sort', 'order_no', 'sequence', 'seq'], sortIndex), + code: this.firstValue(row, ['code', 'node_code', 'scada_code', 'binding_code', 'number']), + name: this.firstValue(row, ['name', 'node_name', 'scada_name', 'binding_name', 'label']), + scada_node: this.firstValue(row, [ + 'scada_node', + 'scada_node_name', + 'scadaNode', + 'node', + 'node_name', + 'node_code', + 'device_node', + 'bind_scada_node' + ]), + collect_type: collectType, + collect_type_name: this.firstValue(row, [ + 'collect_type_name', + 'collection_type_name', + 'type_name', + 'category_name' + ], this.collectTypeText(collectType)), + interval: this.firstValue(row, [ + 'interval', + 'collect_interval', + 'collection_interval', + 'period', + 'refresh_interval' + ]), + status, + status_name: this.firstValue(row, ['status_name', 'enable_name', 'enabled_name'], this.statusText(status)), + remark: this.firstValue(row, ['remark', 'note', 'description']) + } + }, onSearch () { this.pagination.current = 1 this.fetchData() @@ -342,17 +472,18 @@ export default { }) }, openEdit (row) { + const record = this.normalizeRow(row) this.handleType = 'edit' this.dialogTitle = this.key('edit_title') - this.editId = row.id + this.editId = record.id this.formData = { - code: row.code, - name: row.name, - scada_node: row.scada_node || '', - collect_type: row.collect_type || '', - interval: row.interval || 1, - status: typeof row.status === 'number' ? row.status : 1, - remark: row.remark || '' + code: record.code, + name: record.name, + scada_node: record.scada_node || '', + collect_type: record.collect_type || '', + interval: record.interval || 1, + status: typeof record.status === 'number' ? record.status : 1, + remark: record.remark || '' } this.dialogVisible = true },