26 lines
888 B
JavaScript
26 lines
888 B
JavaScript
/**
|
|
* 会话列表卡片右上角相对时间(工作台「正在接诊」、在线接诊列表等共用)
|
|
* @param {Object} item
|
|
* @returns {string}
|
|
*/
|
|
export function formatSessionRelativeTime(item) {
|
|
if (!item) return '';
|
|
const t =
|
|
item.last_message_time ||
|
|
item.updated_at ||
|
|
item.created_at ||
|
|
item.register_time;
|
|
if (t == null || t === '') return '';
|
|
const ms = typeof t === 'number' ? (t > 1e12 ? t : t * 1000) : new Date(t).getTime();
|
|
if (Number.isNaN(ms)) return '';
|
|
const d = new Date(ms);
|
|
const now = Date.now();
|
|
const diff = Math.floor((now - ms) / 60000);
|
|
if (diff < 1) return '刚刚';
|
|
if (diff < 60) return `${diff}分钟前`;
|
|
const h = Math.floor(diff / 60);
|
|
if (h < 24) return `${h}小时前`;
|
|
const pad = (n) => (n < 10 ? '0' + n : '' + n);
|
|
return `${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
}
|