修复批次托盘分页和设备监控统计排序
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-25 01:00:08 +08:00
parent c2db61dad9
commit f07f5d91c4
2 changed files with 119 additions and 27 deletions

View File

@@ -297,12 +297,30 @@ export default {
}, },
methods: { methods: {
normalizeListResponse (res) { normalizeListResponse (res) {
const data = Array.isArray(res) ? res : (res && res.data) || [] const root = res || {}
if (Array.isArray(data)) return { list: data, total: data.length } const data = root.data !== undefined ? root.data : root
return { if (Array.isArray(data)) {
list: data.data || [], return { list: data, total: Number(root.count || root.total || data.length) }
total: data.count || 0
} }
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) }
}
return { list: [], total: Number(root.count || root.total || data.count || data.total || 0) }
}, },
async fetchData () { async fetchData () {
this.loading = true this.loading = true
@@ -329,8 +347,8 @@ export default {
this.fetchData() this.fetchData()
}, },
onPageChange (page) { onPageChange (page) {
this.pagination.current = page.current this.pagination.current = Number(page.current || page.currentPage || 1)
this.pagination.size = page.size this.pagination.size = Number(page.size || page.pageSize || this.pagination.size)
this.fetchData() this.fetchData()
}, },
openTrayDetails (row) { openTrayDetails (row) {

View File

@@ -21,9 +21,6 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" :disabled="loading" @click="onSearch">
{{ $t(key('query')) }}
</el-button>
<el-button icon="el-icon-refresh" :disabled="loading" @click="onReset"> <el-button icon="el-icon-refresh" :disabled="loading" @click="onReset">
{{ $t(key('reset')) }} {{ $t(key('reset')) }}
</el-button> </el-button>
@@ -54,12 +51,13 @@
<page-table <page-table
:columns="columns" :columns="columns"
:data="tableData" :data="sortedTableData"
:loading="loading" :loading="loading"
:toolbar-buttons="[]" :toolbar-buttons="[]"
:row-buttons="[]" :row-buttons="[]"
:pagination="null" :pagination="null"
:table-attrs="{ size: 'mini', rowKey: 'id', highlightCurrentRow: true }" :table-attrs="{ size: 'mini', rowKey: 'id', highlightCurrentRow: true }"
:table-listeners="tableListeners"
auto-height auto-height
> >
<template #col-status="{ row }"> <template #col-status="{ row }">
@@ -103,39 +101,53 @@ export default {
activeStatus: '', activeStatus: '',
tableData: [], tableData: [],
statusNum: [], statusNum: [],
totalCount: 0,
deviceCategoryOptions: [], deviceCategoryOptions: [],
search: { search: {
device_category_id: '' device_category_id: ''
}, },
sortState: {
prop: '',
order: ''
},
refreshTimer: null refreshTimer: null
} }
}, },
computed: { computed: {
columns () { columns () {
return useTableColumns([ return useTableColumns([
{ prop: 'code', label: this.key('device_code'), minWidth: 140, showOverflowTooltip: true }, { prop: 'code', label: this.key('device_code'), minWidth: 140, sortable: 'custom', showOverflowTooltip: true },
{ prop: 'name', label: this.key('device_name'), minWidth: 160, showOverflowTooltip: true }, { prop: 'name', label: this.key('device_name'), minWidth: 160, sortable: 'custom', showOverflowTooltip: true },
{ prop: 'area_name', label: this.key('area'), minWidth: 120, showOverflowTooltip: true }, { prop: 'area_name', label: this.key('area'), minWidth: 120, sortable: 'custom', showOverflowTooltip: true },
{ prop: 'line_name', label: this.key('production_line'), minWidth: 140, showOverflowTooltip: true }, { prop: 'line_name', label: this.key('production_line'), minWidth: 140, sortable: 'custom', showOverflowTooltip: true },
{ prop: 'workstation_name', label: this.key('workstation'), minWidth: 140, showOverflowTooltip: true }, { prop: 'workstation_name', label: this.key('workstation'), minWidth: 140, sortable: 'custom', showOverflowTooltip: true },
{ prop: 'heartbeat', label: this.key('last_response'), minWidth: 170, showOverflowTooltip: true }, { prop: 'heartbeat', label: this.key('last_response'), minWidth: 170, sortable: 'custom', showOverflowTooltip: true },
{ prop: 'status', label: this.key('work_status'), minWidth: 110, slot: 'status' }, { prop: 'status', label: this.key('work_status'), minWidth: 110, sortable: 'custom', slot: 'status' },
{ prop: 'msg', label: this.key('msg'), minWidth: 180, slot: 'msg', showOverflowTooltip: true } { prop: 'msg', label: this.key('msg'), minWidth: 180, sortable: 'custom', slot: 'msg', showOverflowTooltip: true }
], { ], {
selectionWidth: 0, selectionWidth: 0,
indexWidth: 55 indexWidth: 55
}) })
}, },
tableListeners () {
return {
'sort-change': this.onSortChange
}
},
statusCountMap () { statusCountMap () {
return this.statusNum.reduce((result, item) => { return this.statusNum.reduce((result, item) => {
result[item.status] = Number(item.num || 0) const status = this.normalizeStatus(item.status || item.key || item.name || item.type)
if (status) {
result[status] = Number(item.num || item.count || item.value || item.total || 0)
}
return result return result
}, {}) }, {})
}, },
totalDeviceCount () { totalDeviceCount () {
return Object.keys(this.statusCountMap).reduce((total, status) => { const statusTotal = Object.keys(this.statusCountMap).reduce((total, status) => {
return total + this.statusCountMap[status] return total + this.statusCountMap[status]
}, 0) }, 0)
return statusTotal || this.totalCount || this.tableData.length
}, },
statusCards () { statusCards () {
return Object.keys(STATUS_META).map(status => ({ return Object.keys(STATUS_META).map(status => ({
@@ -143,6 +155,13 @@ export default {
count: this.statusCountMap[status] || 0, count: this.statusCountMap[status] || 0,
...STATUS_META[status] ...STATUS_META[status]
})) }))
},
sortedTableData () {
if (!this.sortState.prop || !this.sortState.order) return this.tableData
const direction = this.sortState.order === 'ascending' ? 1 : -1
return [...this.tableData].sort((a, b) => {
return this.compareValue(a[this.sortState.prop], b[this.sortState.prop]) * direction
})
} }
}, },
mounted () { mounted () {
@@ -164,13 +183,15 @@ export default {
this.fetchData() this.fetchData()
}, },
normalizePayload (res) { normalizePayload (res) {
const payload = res && res.data !== undefined ? res.data : (res || {}) if (!res) return {}
if (Array.isArray(res)) return { data: res, status_num: [] }
if (res.data && !Array.isArray(res.data) && (res.data.data || res.data.status_num || res.data.statusNum || res.data.status_count || res.data.statusCount)) {
return res.data
}
const payload = res || {}
if (Array.isArray(payload)) { if (Array.isArray(payload)) {
return { data: payload, status_num: [] } return { data: payload, status_num: [] }
} }
if (payload && payload.data && !Array.isArray(payload.data) && (payload.data.data || payload.data.status_num)) {
return payload.data
}
return payload || {} return payload || {}
}, },
normalizeList (res) { normalizeList (res) {
@@ -178,8 +199,37 @@ export default {
if (Array.isArray(payload)) return payload if (Array.isArray(payload)) return payload
if (Array.isArray(payload.data)) return payload.data if (Array.isArray(payload.data)) return payload.data
if (Array.isArray(payload.list)) return payload.list if (Array.isArray(payload.list)) return payload.list
if (Array.isArray(payload.rows)) return payload.rows
if (Array.isArray(payload.records)) return payload.records
return [] return []
}, },
normalizeStatus (status) {
return String(status || '').toUpperCase()
},
normalizeStatusNum (payload, list) {
const statusNum = payload.status_num || payload.statusNum || payload.status_count || payload.statusCount || payload.status_counts || payload.statusCounts
if (Array.isArray(statusNum)) return statusNum
if (statusNum && typeof statusNum === 'object') {
return Object.keys(statusNum).map(status => ({
status,
num: statusNum[status]
}))
}
const counts = list.reduce((result, row) => {
const status = this.normalizeStatus(row.status)
if (status) {
result[status] = (result[status] || 0) + 1
}
return result
}, {})
return Object.keys(counts).map(status => ({
status,
num: counts[status]
}))
},
normalizeTotal (payload, list) {
return Number(payload.count || payload.total || payload.total_count || payload.totalCount || list.length || 0)
},
async loadDeviceCategoryOptions () { async loadDeviceCategoryOptions () {
try { try {
const res = await getDeviceCategoryAll() const res = await getDeviceCategoryAll()
@@ -196,6 +246,28 @@ export default {
onSearch () { onSearch () {
this.fetchData() this.fetchData()
}, },
onSortChange ({ prop, order }) {
this.sortState = {
prop: prop || '',
order: order || ''
}
},
compareValue (left, right) {
if (left === right) return 0
if (left === undefined || left === null || left === '') return -1
if (right === undefined || right === null || right === '') return 1
const leftNumber = Number(left)
const rightNumber = Number(right)
if (!Number.isNaN(leftNumber) && !Number.isNaN(rightNumber)) {
return leftNumber - rightNumber
}
const leftDate = Date.parse(left)
const rightDate = Date.parse(right)
if (!Number.isNaN(leftDate) && !Number.isNaN(rightDate)) {
return leftDate - rightDate
}
return String(left).localeCompare(String(right), 'zh-Hans-CN')
},
async fetchData (showLoading = true) { async fetchData (showLoading = true) {
if (showLoading) this.loading = true if (showLoading) this.loading = true
try { try {
@@ -204,8 +276,10 @@ export default {
device_category_id: this.search.device_category_id device_category_id: this.search.device_category_id
}) })
const payload = this.normalizePayload(res) const payload = this.normalizePayload(res)
this.statusNum = Array.isArray(payload.status_num) ? payload.status_num : [] const list = this.normalizeList(payload)
this.tableData = Array.isArray(payload.data) ? payload.data : [] this.statusNum = this.normalizeStatusNum(payload, list)
this.totalCount = this.normalizeTotal(payload, list)
this.tableData = list
} finally { } finally {
if (showLoading) this.loading = false if (showLoading) this.loading = false
} }