Commit f8b6d9cd by nningxx

add 设备sort

parent b0a240ed
...@@ -526,20 +526,27 @@ ...@@ -526,20 +526,27 @@
if (!deviceStateData || !Array.isArray(deviceStateData)) { if (!deviceStateData || !Array.isArray(deviceStateData)) {
return; return;
} }
const codeToSeqMap = {};
this.allEquipmentData.forEach(equip => {
codeToSeqMap[equip.code] = equip.sequence;
});
// 获取当前车间下的设备 code 列表 // 获取当前车间下的设备 code 列表
const validCodes = this.allEquipmentData const validCodes = this.allEquipmentData
.filter(e => !this.selectedWorkshop || e.plant_name === this.selectedWorkshop) .filter(e => !this.selectedWorkshop || e.plant_name === this.selectedWorkshop)
.map(e => e.code); .map(e => e.code);
// 过滤掉不属于当前车间的设备
const filteredDevices = deviceStateData.filter(d => // 过滤掉不属于当前车间的设备
!this.selectedWorkshop || validCodes.includes(d.code) const filteredDevices = deviceStateData.filter(d =>
); !this.selectedWorkshop || validCodes.includes(d.code)
).map(device => ({
...device,
seq: codeToSeqMap[device.code] || Number.MAX_SAFE_INTEGER // 如果找不到 seq,默认排最后
}));
// 将API返回的数据转换为页面所需的格式 // 将API返回的数据转换为页面所需的格式
this.deviceList = filteredDevices.map((device) => { this.deviceList = filteredDevices.map((device) => {
// 根据API返回的状态确定前端显示的状态 // 根据API返回的状态确定前端显示的状态
let status = "off"; let status = "off";
if (device.state === "green") { if (device.state === "green") {
...@@ -553,7 +560,9 @@ ...@@ -553,7 +560,9 @@
} }
// 计算持续时间的显示格式 // 计算持续时间的显示格式
let durationText = "0" let durationText = "0"
if (device.duration_hours !== undefined) { durationText = this.formatTime(Number(device.duration_hours * 3600)) } if (device.duration_hours !== undefined) {
durationText = this.formatTime(Number(device.duration_hours * 3600))
}
let run_seconds = "0" let run_seconds = "0"
if (device.run_seconds !== undefined) run_seconds = this.formatTime(Number(device.run_seconds)) if (device.run_seconds !== undefined) run_seconds = this.formatTime(Number(device.run_seconds))
...@@ -569,13 +578,13 @@ ...@@ -569,13 +578,13 @@
// 计算利用率百分比,确保有效值 // 计算利用率百分比,确保有效值
const percentage = device.utilization_rate !== undefined ? Math.round(device const percentage = device.utilization_rate !== undefined ? Math.round(device
.utilization_rate) : 0 .utilization_rate) : 0
// 从所有设备列表中获取准确的设备名称 // 从所有设备列表中获取准确的设备名称
let deviceName = device.name || device.code // 默认使用API返回的名称或编码 let deviceName = device.name || device.code // 默认使用API返回的名称或编码
// 在所有设备列表中查找匹配的设备 // 在所有设备列表中查找匹配的设备
if (this.allEquipmentData && this.allEquipmentData.length > 0) { if (this.allEquipmentData && this.allEquipmentData.length > 0) {
const matchedDevice = this.allEquipmentData.find( const matchedDevice = this.allEquipmentData.find(
(equip) => equip.code === device.code (equip) => equip.code === device.code
) )
// 如果找到匹配的设备,使用其名称 // 如果找到匹配的设备,使用其名称
if (matchedDevice && matchedDevice.name) { if (matchedDevice && matchedDevice.name) {
...@@ -594,7 +603,8 @@ ...@@ -594,7 +603,8 @@
yellow_seconds: yellow_seconds, yellow_seconds: yellow_seconds,
red_seconds: red_seconds red_seconds: red_seconds
} }
}); }).sort((a, b) => (codeToSeqMap[a.code] || Number.MAX_SAFE_INTEGER)
- (codeToSeqMap[b.code] || Number.MAX_SAFE_INTEGER));
}, },
formatTime(seconds) { formatTime(seconds) {
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
<xpath expr="//field[@name='workshop_id']" position="after"> <xpath expr="//field[@name='workshop_id']" position="after">
<field name="data_acquisition_code"/> <field name="data_acquisition_code"/>
</xpath> </xpath>
<xpath expr="//field[@name='work_center_id']" position="after">
<field name="sequence"/>
</xpath>
</field> </field>
</record> </record>
<record id="view_roke_mes_equipment_tree_tht" model="ir.ui.view"> <record id="view_roke_mes_equipment_tree_tht" model="ir.ui.view">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment