设备状态ui提交
parent
4b0db12a76
commit
5df6f6ff84
|
|
@ -78,43 +78,46 @@ export default {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onShow() {
|
||||||
|
this.getSortDate();
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 核心时间格式化方法
|
|
||||||
formatTime(timeStr) {
|
formatTime(timeStr) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const target = new Date(timeStr);
|
const target = new Date(timeStr);
|
||||||
const nowTime = now.getTime();
|
const diff = now - target;
|
||||||
const targetTime = target.getTime();
|
const day = 86400000;
|
||||||
const diffTime = nowTime - targetTime;
|
const week = 7 * day;
|
||||||
const oneDay = 24 * 60 * 60 * 1000;
|
|
||||||
const sevenDays = 7 * oneDay;
|
|
||||||
|
|
||||||
// 格式化时分秒
|
// 时间
|
||||||
const hh = String(target.getHours()).padStart(2, '0');
|
const h = String(target.getHours()).padStart(2, '0');
|
||||||
const mm = String(target.getMinutes()).padStart(2, '0');
|
const m = String(target.getMinutes()).padStart(2, '0');
|
||||||
const timeSuffix = `${hh}:${mm}`;
|
const time = `${h}:${m}`;
|
||||||
|
|
||||||
// 今天
|
// 今天
|
||||||
if (now.toDateString() === target.toDateString()) {
|
if (now.toDateString() === target.toDateString())
|
||||||
return `今天 ${timeSuffix}`;
|
return `今天 ${time}`;
|
||||||
}
|
|
||||||
// 昨天
|
// 昨天
|
||||||
const yesterday = new Date(now);
|
const yest = new Date(now);
|
||||||
yesterday.setDate(now.getDate() - 1);
|
yest.setDate(now.getDate() - 1);
|
||||||
if (yesterday.toDateString() === target.toDateString()) {
|
if (yest.toDateString() === target.toDateString())
|
||||||
return `昨天 ${timeSuffix}`;
|
return `昨天 ${time}`;
|
||||||
}
|
|
||||||
// 7天内(含昨天)
|
// 7天内
|
||||||
if (diffTime <= sevenDays) {
|
if (diff <= week) {
|
||||||
const weekMap = ['日', '一', '二', '三', '四', '五', '六'];
|
const weekMap = ['日', '一', '二', '三', '四', '五', '六'];
|
||||||
const week = weekMap[target.getDay()];
|
return `星期${weekMap[target.getDay()]} ${time}`;
|
||||||
return `星期${week} ${timeSuffix}`;
|
|
||||||
}
|
}
|
||||||
// 7天以前
|
|
||||||
const y = target.getFullYear();
|
// 7天前
|
||||||
const m = String(target.getMonth() + 1).padStart(2, '0');
|
const Y = target.getFullYear();
|
||||||
const d = String(target.getDate()).padStart(2, '0');
|
const M = String(target.getMonth() + 1).padStart(2, '0');
|
||||||
return `${y}-${m}-${d} ${timeSuffix}`;
|
const D = String(target.getDate()).padStart(2, '0');
|
||||||
|
return `${Y}-${M}-${D} ${time}`;
|
||||||
|
},
|
||||||
|
getSortDate() {
|
||||||
|
return this.messageList.sort((a, b) => new Date(a.time) - new Date(b.time));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue