From f49bfd6c085cbf28a25d9404f8dc5b74368b716a Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 29 五月 2026 15:54:02 +0800
Subject: [PATCH] 新疆马铃薯 1.代码更新
---
src/views/equipmentManagement/operationManagement/index.vue | 132 +++-----------------------------------------
1 files changed, 9 insertions(+), 123 deletions(-)
diff --git a/src/views/equipmentManagement/operationManagement/index.vue b/src/views/equipmentManagement/operationManagement/index.vue
index 99c3bd1..008cc2c 100644
--- a/src/views/equipmentManagement/operationManagement/index.vue
+++ b/src/views/equipmentManagement/operationManagement/index.vue
@@ -104,7 +104,7 @@
align="center"
>
<template #default="scope">
- {{ getRuntimeDurationDisplay(scope.row) }}
+ {{ scope.row.runtimeDuration || '-' }}
</template>
</el-table-column>
<el-table-column
@@ -154,8 +154,7 @@
</template>
<script setup>
-import { ref, onMounted, onUnmounted, computed } from 'vue'
-import dayjs from 'dayjs'
+import { ref, onMounted, computed } from 'vue'
import { ElMessage } from 'element-plus'
import {
VideoPlay,
@@ -194,98 +193,6 @@
return filtered
})
-
-// 杩愯涓棤缁撴潫鏃堕棿鏃讹紝杩愯鏃堕暱闇�闅忓綋鍓嶆椂闂村彉鍖栵紝鐢� tick 瑙﹀彂妯℃澘閲嶇畻
-const runtimeDisplayTick = ref(0)
-
-/** 鍙栧悗绔彲鑳戒娇鐢ㄧ殑寮�濮�/缁撴潫鏃堕棿瀛楁 */
-const pickStartTime = (row) => row?.startRuntimeTime ?? row?.startTime ?? row?.start_time
-const pickEndTime = (row) => row?.endRuntimeTime ?? row?.endTime ?? row?.end_time
-
-/**
- * 瑙f瀽鎺ュ彛/鍓嶇鍐欏叆鐨勫悇绫绘椂闂达細鏃堕棿鎴炽�両SO 瀛楃涓层�亂yyy-MM-dd HH:mm:ss銆丣ackson 鏁扮粍 [y,M,d,h,m,s]銆佸惈涓枃鐨� toLocaleString 绛�
- */
-const parseDeviceTime = (input) => {
- if (input === null || input === undefined || input === '') return null
- if (typeof input === 'number' && !Number.isNaN(input)) {
- const d = dayjs(input)
- return d.isValid() ? d.toDate() : null
- }
- if (Array.isArray(input)) {
- const [y, mo, day, h = 0, mi = 0, se = 0] = input
- if (y == null || y === '') return null
- const d = dayjs()
- .year(Number(y))
- .month(Number(mo || 1) - 1)
- .date(Number(day || 1))
- .hour(Number(h) || 0)
- .minute(Number(mi) || 0)
- .second(Number(se) || 0)
- return d.isValid() ? d.toDate() : null
- }
- const s = String(input).trim()
- if (!s || s === '-') return null
- let d = dayjs(s)
- if (d.isValid()) return d.toDate()
- d = dayjs(s.replace(/-/g, '/'))
- if (d.isValid()) return d.toDate()
- d = dayjs(s.replace(/\//g, '-'))
- if (d.isValid()) return d.toDate()
- return null
-}
-
-const formatDurationMs = (durationMs) => {
- if (durationMs == null || Number.isNaN(durationMs) || durationMs < 0) return '-'
- const hours = Math.floor(durationMs / (1000 * 60 * 60))
- const minutes = Math.floor((durationMs % (1000 * 60 * 60)) / (1000 * 60))
- if (hours === 0 && minutes === 0) return '涓嶈冻1鍒嗛挓'
- return `${hours}灏忔椂${minutes}鍒嗛挓`
-}
-
-const hasMeaningfulEnd = (endRaw) =>
- endRaw !== null &&
- endRaw !== undefined &&
- String(endRaw).trim() !== '' &&
- String(endRaw).trim() !== '-'
-
-const formatStoredDuration = (row) => {
- const rd = row?.runtimeDuration
- if (rd === null || rd === undefined) return ''
- const t = String(rd).trim()
- return t === '' || t === '-' ? '' : String(rd)
-}
-
-/** 杩愯涓細濮嬬粓鐢ㄣ�屽綋鍓嶆椂闂� - 寮�濮嬫椂闂淬�嶏紱宸插仠姝細浼樺厛鎺ュ彛 runtimeDuration锛屽惁鍒欑敤缁撴潫-寮�濮嬶紱鏃犵粨鏉熷彲鐪嬪凡瀛樻椂闀挎垨鍔ㄦ�佹帹绠� */
-const getRuntimeDurationDisplay = (row) => {
- void runtimeDisplayTick.value
- const start = parseDeviceTime(pickStartTime(row))
- if (!start) {
- return formatStoredDuration(row) || '-'
- }
-
- const statusStr = String(row?.status ?? '').trim()
- const isRunning = statusStr === '杩愯涓�' || statusStr === '1'
- const endRaw = pickEndTime(row)
- const hasEnd = hasMeaningfulEnd(endRaw)
-
- // 鏃犵粨鏉熸椂闂达細杩愯涓竴瀹氬姩鎬佺畻锛涘凡鍋滄鍒欎紭鍏堝睍绀哄悗绔凡瀛樻椂闀匡紝娌℃湁鍐嶆寜褰撳墠鏃堕棿鎺ㄧ畻
- if (!hasEnd) {
- if (isRunning) return formatDurationMs(Date.now() - start.getTime())
- const stored = formatStoredDuration(row)
- if (stored) return stored
- return formatDurationMs(Date.now() - start.getTime())
- }
-
- if (isRunning) {
- return formatDurationMs(Date.now() - start.getTime())
- }
-
- const end = parseDeviceTime(endRaw)
- const stored = formatStoredDuration(row)
- if (stored) return stored
- if (end) return formatDurationMs(end.getTime() - start.getTime())
- return '-'
-}
// 妫�鏌ヨ澶囨槸鍚﹁秴鏃舵湭鍚姩
const isOverdue = (device) => {
@@ -339,11 +246,12 @@
device.endRuntimeTime = currentTime
// 璁$畻杩愯鏃堕暱
if (device.startRuntimeTime) {
- const startTime = parseDeviceTime(device.startRuntimeTime)
- const endTime = parseDeviceTime(currentTime)
- if (startTime && endTime) {
- device.runtimeDuration = formatDurationMs(endTime.getTime() - startTime.getTime())
- }
+ const startTime = new Date(device.startRuntimeTime)
+ const endTime = new Date(currentTime)
+ const duration = endTime - startTime
+ const hours = Math.floor(duration / (1000 * 60 * 60))
+ const minutes = Math.floor((duration % (1000 * 60 * 60)) / (1000 * 60))
+ device.runtimeDuration = `${hours}灏忔椂${minutes}鍒嗛挓`
}
}
const params = {
@@ -389,31 +297,9 @@
-const POLL_MS = 60 * 1000
-const RUNTIME_TICK_MS = 30 * 1000
-let listPollTimer = null
-let runtimeTickTimer = null
-
-// 缁勪欢鎸傝浇鏃舵媺鍙栨暟鎹紝骞舵瘡鍒嗛挓鍒锋柊涓�娆″垪琛紱杩愯涓椂闀挎瘡 30 绉掑埛鏂版樉绀�
+// 缁勪欢鎸傝浇鏃跺垵濮嬪寲鏁版嵁
onMounted(() => {
getList()
- listPollTimer = setInterval(() => {
- getList()
- }, POLL_MS)
- runtimeTickTimer = setInterval(() => {
- runtimeDisplayTick.value++
- }, RUNTIME_TICK_MS)
-})
-
-onUnmounted(() => {
- if (listPollTimer != null) {
- clearInterval(listPollTimer)
- listPollTimer = null
- }
- if (runtimeTickTimer != null) {
- clearInterval(runtimeTickTimer)
- runtimeTickTimer = null
- }
})
</script>
--
Gitblit v1.9.3