Forráskód Böngészése

Merge branch 'master' of http://112.74.164.79:3000/chenying/X-web

chenying 6 hónapja
szülő
commit
55af115e94

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

@@ -19,3 +19,20 @@ export function formatDate (date) {
   let year = date.slice(0, -4)
   return year + '.' + month + '.' + day
 }
+
+/**
+ * 北京时间
+ * @param date
+ */
+export function formatBeijingTime (date) {
+  // let beijingTime = new Date(date.getTime() + 8 * 60 * 60 * 1000)
+// 格式化为 yyyy-MM-dd HH:mm:ss
+  const year = date.getFullYear()
+  const month = String(date.getMonth() + 1).padStart(2, '0') // 月份从0开始
+  const day = String(date.getDate()).padStart(2, '0')
+  const hours = String(date.getHours()).padStart(2, '0')
+  const minutes = String(date.getMinutes()).padStart(2, '0')
+  const seconds = String(date.getSeconds()).padStart(2, '0')
+
+  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
+}

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

@@ -661,7 +661,7 @@
 </template>
 
 <script>
-import {formatDate, formatTime} from '@/utils/date-util'
+import {formatBeijingTime, formatDate, formatTime} from '@/utils/date-util'
 
 export default {
   name: 'device-history',
@@ -684,6 +684,12 @@ export default {
     formatTime,
     async init (code) {
       this.code = code
+      // 设置默认时间范围
+      const now = new Date()
+      this.dataForm = {
+        // 初始化日期设为当天 0 点到当前时间
+        date: [formatBeijingTime(new Date(now.getFullYear(), now.getMonth(), now.getDate())), formatBeijingTime(now)]
+      }
       this.search()
     },
     onChose () {

+ 7 - 0
src/views/modules/device/temp-history.vue

@@ -97,6 +97,7 @@
 
 <script>
 import { getDictList } from '@/api/dict'
+import {formatBeijingTime} from '@/utils/date-util'
 export default {
   name: 'temp-history',
   components: {
@@ -117,6 +118,12 @@ export default {
   methods: {
     async init (code) {
       this.code = code
+      // 设置默认时间范围
+      const now = new Date()
+      this.dataForm = {
+        // 初始化日期设为当天 0 点到当前时间
+        date: [formatBeijingTime(new Date(now.getFullYear(), now.getMonth(), now.getDate())), formatBeijingTime(now)]
+      }
       this.search()
     },
     onChose () {