|
|
@@ -1,15 +1,6 @@
|
|
|
import dayjs from 'dayjs';
|
|
|
import { abs } from 'mathjs';
|
|
|
-require('dayjs/locale/zh-cn');
|
|
|
-dayjs.locale('zh-cn');
|
|
|
-var relativeTime = require('dayjs/plugin/relativeTime');
|
|
|
-dayjs.extend(relativeTime);
|
|
|
-var calendar = require('dayjs/plugin/calendar');
|
|
|
-dayjs.extend(calendar);
|
|
|
-var duration = require('dayjs/plugin/duration');
|
|
|
-dayjs.extend(duration);
|
|
|
-var isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
|
|
|
-dayjs.extend(isSameOrBefore);
|
|
|
+import { differenceInSeconds } from 'date-fns';
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -90,16 +81,22 @@ export default {
|
|
|
if (!this.isAppointment) {
|
|
|
return;
|
|
|
}
|
|
|
- var x = dayjs(startTime);
|
|
|
- var y = dayjs();
|
|
|
- let d = dayjs.duration(x.diff(y));
|
|
|
- let day = parseInt(d.asDays());
|
|
|
+
|
|
|
+ let seconds = differenceInSeconds(new Date(startTime), new Date());
|
|
|
+ console.log(seconds);
|
|
|
let str = '';
|
|
|
- if (abs(day) > 0) {
|
|
|
- str += day + '天 ';
|
|
|
+ let d = Math.floor(seconds / 24 / 3600);
|
|
|
+ if (abs(d) > 0) {
|
|
|
+ str += d + '天 ';
|
|
|
}
|
|
|
|
|
|
- this.startTime = str + dayjs.duration(x.diff(y)).format('HH:mm:ss');
|
|
|
+ this.startTime =
|
|
|
+ str +
|
|
|
+ Math.floor((seconds % 24) / 3600) +
|
|
|
+ ':' +
|
|
|
+ Math.floor((seconds % 3600) / 60) +
|
|
|
+ ':' +
|
|
|
+ Math.floor((seconds % 3600) % 60);
|
|
|
if (this.timer) {
|
|
|
clearTimeout(this.timer);
|
|
|
this.timer = null;
|
|
|
@@ -121,5 +118,11 @@ export default {
|
|
|
}
|
|
|
return str;
|
|
|
}
|
|
|
+ },
|
|
|
+ beforeUnmount() {
|
|
|
+ if (this.timer) {
|
|
|
+ clearTimeout(this.timer);
|
|
|
+ this.timer = null;
|
|
|
+ }
|
|
|
}
|
|
|
};
|