From 01cf735453bb4f2757615beab5ee72480c07e417 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Wed, 20 Mar 2024 10:13:27 +0800 Subject: [PATCH] 优化图片预览组件,支持缩略图加载失败回退 --- common/Tools.js | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-) diff --git a/common/Tools.js b/common/Tools.js index e70b7ad..251ef03 100644 --- a/common/Tools.js +++ b/common/Tools.js @@ -359,17 +359,29 @@ } } } - // 转为数值的无连接符日期 + // 数值转换:8位整型日期 转 时间戳 if (timestamp < 9 * 10e6) { const timeStr = timestamp + ''; - const day = timeStr.substr(0, 4) + '-' + - timeStr.substr(4, 2) + '-' + timeStr.substr(6, 2); - timestamp = (new Date(day)).getTime(); + const dateStr = timeStr.slice(0, 4) + '-' + timeStr.slice(4, 6) + '-' + timeStr.slice(6); + if (type === 'date') { + return dateStr; + } + timestamp = (new Date(dateStr)).getTime(); } - // 按秒时间戳 + // 数值转换:时间戳 秒 转 毫秒 else if (timestamp < 9 * 10e8) { timestamp *= 1000; } + // 数值转换:14位整型日期 转 时间戳 + else if (/^2[012]\d{2}[01]\d[0123]\d[012]\d[0-5]\d[0-5]\d/.test(timestamp + '')) { + const timeStr = timestamp + ''; + const dateStr = timeStr.slice(0, 4) + '-' + timeStr.slice(4, 6) + '-' + timeStr.slice(6, 8) + + ' ' + timeStr.slice(8, 10) + ':' + timeStr.slice(10, 12) + ':' + timeStr.slice(12, 14); + if (type === 'dateTimeFull') { + return dateStr; + } + timestamp = (new Date(dateStr)).getTime(); + } const curMoment = moment(timestamp); if (type === 'date') { return curMoment.format('YYYY-MM-DD'); -- Gitblit v1.9.1