Browse Source

设备历史时间格式转换

chrislee 6 months ago
parent
commit
04f56c55b2
2 changed files with 38 additions and 7 deletions
  1. 21 0
      src/utils/date-util.js
  2. 17 7
      src/views/modules/device/device-history.vue

+ 21 - 0
src/utils/date-util.js

@@ -0,0 +1,21 @@
+/**
+ * 时间格式
+ */
+export function formatTime (time) {
+  if (!time || time.length < 6) return ''
+  let seconds = time.slice(-2)
+  let minutes = time.slice(-4, -2)
+  let hours = time.slice(0, -4)
+  return hours + ':' + minutes + ':' + seconds
+}
+
+/**
+ * 日期格式
+ */
+export function formatDate (date) {
+  if (!date || date.length < 6) return ''
+  let day = date.slice(-2)
+  let month = date.slice(-4, -2)
+  let year = date.slice(0, -4)
+  return year + '.' + month + '.' + day
+}

+ 17 - 7
src/views/modules/device/device-history.vue

@@ -102,6 +102,7 @@
       <el-table-column
         header-align="center"
         align="center"
+        min-width="100"
         label="第一轴下一指令">
         <template slot-scope="scope">
           <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos1'">{{ item.value }}</span>
@@ -110,6 +111,7 @@
       <el-table-column
         header-align="center"
         align="center"
+        min-width="100"
         label="第二轴下一指令">
         <template slot-scope="scope">
           <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos2'">{{ item.value }}</span>
@@ -118,6 +120,7 @@
       <el-table-column
         header-align="center"
         align="center"
+        min-width="100"
         label="第三轴下一指令">
         <template slot-scope="scope">
           <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos3'">{{ item.value }}</span>
@@ -126,6 +129,7 @@
       <el-table-column
         header-align="center"
         align="center"
+        min-width="100"
         label="第四轴下一指令">
         <template slot-scope="scope">
           <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos4'">{{ item.value }}</span>
@@ -134,6 +138,7 @@
       <el-table-column
         header-align="center"
         align="center"
+        min-width="100"
         label="第五轴下一指令">
         <template slot-scope="scope">
           <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos5'">{{ item.value }}</span>
@@ -142,6 +147,7 @@
       <el-table-column
         header-align="center"
         align="center"
+        min-width="100"
         label="第六轴下一指令">
         <template slot-scope="scope">
           <span v-for="item in scope.row.points" v-if="item.name==='NextDistancePos6'">{{ item.value }}</span>
@@ -150,19 +156,19 @@
       <el-table-column
         header-align="center"
         align="center"
-        min-width="90"
+        min-width="100"
         label="自动运行时间">
         <template slot-scope="scope">
-          <span v-for="item in scope.row.points" v-if="item.name==='RunTime'">{{ item.value }}</span>
+          <span v-for="item in scope.row.points" v-if="item.name==='RunTime'">{{ formatTime(item.value) }}</span>
         </template>
       </el-table-column>
       <el-table-column
         header-align="center"
         align="center"
-        min-width="90"
+        min-width="100"
         label="自动启动时间">
         <template slot-scope="scope">
-          <span v-for="item in scope.row.points" v-if="item.name==='StartTime'">{{ item.value }}</span>
+          <span v-for="item in scope.row.points" v-if="item.name==='StartTime'">{{ formatTime(item.value) }}</span>
         </template>
       </el-table-column>
       <el-table-column
@@ -180,7 +186,7 @@
         min-width="90"
         label="上电时间">
         <template slot-scope="scope">
-          <span v-for="item in scope.row.points" v-if="item.name==='KeepAliveTime'">{{ item.value }}</span>
+          <span v-for="item in scope.row.points" v-if="item.name==='KeepAliveTime'">{{ formatTime(item.value) }}</span>
         </template>
       </el-table-column>
       <el-table-column
@@ -189,7 +195,7 @@
         min-width="90"
         label="系统日期">
         <template slot-scope="scope">
-          <span v-for="item in scope.row.points" v-if="item.name==='SystemDate'">{{ item.value }}</span>
+          <span v-for="item in scope.row.points" v-if="item.name==='SystemDate'">{{ formatDate(item.value) }}</span>
         </template>
       </el-table-column>
       <el-table-column
@@ -198,7 +204,7 @@
         min-width="90"
         label="系统时间">
         <template slot-scope="scope">
-          <span v-for="item in scope.row.points" v-if="item.name==='SystemTime'">{{ item.value }}</span>
+          <span v-for="item in scope.row.points" v-if="item.name==='SystemTime'">{{ formatTime(item.value) }}</span>
         </template>
       </el-table-column>
       <el-table-column
@@ -655,6 +661,8 @@
 </template>
 
 <script>
+import {formatDate, formatTime} from '@/utils/date-util'
+
 export default {
   name: 'device-history',
   components: {
@@ -672,6 +680,8 @@ export default {
     }
   },
   methods: {
+    formatDate,
+    formatTime,
     async init (code) {
       this.code = code
       this.search()