فهرست منبع

修复日期格式化报错

wangxin 6 سال پیش
والد
کامیت
8a3e8abd31
2فایلهای تغییر یافته به همراه20 افزوده شده و 21 حذف شده
  1. 19 20
      src/utils/util.js
  2. 1 1
      src/view/index/index.vue

+ 19 - 20
src/utils/util.js

@@ -69,29 +69,28 @@ export function filterObj(obj) {
 }
 
 export function dk_formatDate(value, fmt, status) {
-    if (value) {
-        const _date = value.replace ? new Date(value.replace(/-/g, "/")) : new Date(value);
-        if (_date) {
 
-            const Y = _date.getFullYear();
-            const M = _date.getMonth() + 1;
-            const D = _date.getDate();
-            const H = _date.getHours();
-            const m = _date.getMinutes();
-            const s = _date.getSeconds();
-            if (fmt === '年') {
-                if (status) {
-                    return formt(Y) + '年' + formt(M) + '月' + formt(D) + '日' + ' ' + [H, m, s].map(formt).join(':')
-                }
-                return formt(Y) + '年' + formt(M) + '月' + formt(D) + '日'
-            } else {
-                if (status) {
-                    return [Y, M, D].map(formt).join(fmt) + ' ' + [H, m, s].map(formt).join(':')
-                }
-                return [Y, M, D].map(formt).join(fmt);
-            }
+    const _date = value.replace ? new Date(value.replace(/-/g, "/")) : new Date(value);
+    if (_date && _date instanceof Date && !isNaN(_date.getTime())) {
 
+        const Y = _date.getFullYear();
+        const M = _date.getMonth() + 1;
+        const D = _date.getDate();
+        const H = _date.getHours();
+        const m = _date.getMinutes();
+        const s = _date.getSeconds();
+        if (fmt === '年') {
+            if (status) {
+                return formt(Y) + '年' + formt(M) + '月' + formt(D) + '日' + ' ' + [H, m, s].map(formt).join(':')
+            }
+            return formt(Y) + '年' + formt(M) + '月' + formt(D) + '日'
+        } else {
+            if (status) {
+                return [Y, M, D].map(formt).join(fmt) + ' ' + [H, m, s].map(formt).join(':')
+            }
+            return [Y, M, D].map(formt).join(fmt);
         }
+
     }
     return ''
 }

+ 1 - 1
src/view/index/index.vue

@@ -123,7 +123,7 @@
 
 <script>
     import {Button, Col, Row, Toast, Loading, Dialog} from 'vant';
-    import {isToday} from '@/utils/util'
+    import {isToday,dk_formatDate} from '@/utils/util'
     import {getStore, clearAll} from "@/utils/storage";
     import {getAction} from '@/api/manage'
     import {queryStaffPunchClock} from '@/api/index'