修复SPC采集配置表格数据显示
This commit is contained in:
@@ -66,7 +66,11 @@
|
||||
auto-height
|
||||
@page-change="onPageChange"
|
||||
@selection-change="onSelect"
|
||||
/>
|
||||
>
|
||||
<template #col-status_name="{ row }">
|
||||
<span>{{ row.status_name || statusText(row.status) }}</span>
|
||||
</template>
|
||||
</page-table>
|
||||
|
||||
<page-dialog-form
|
||||
ref="dialogForm"
|
||||
@@ -295,14 +299,140 @@ export default {
|
||||
page_no: this.pagination.current,
|
||||
page_size: this.pagination.size
|
||||
})
|
||||
const list = Array.isArray(res) ? res : (res.data || [])
|
||||
const total = Array.isArray(res) ? res.length : (res.count || 0)
|
||||
this.tableData = list
|
||||
this.pagination.total = total
|
||||
const data = this.normalizeResponse(res)
|
||||
this.tableData = data.list.map((row, index) => 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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user