|
|
@ -140,6 +140,36 @@ function getDefaultImage() { |
|
|
return defaultImg; |
|
|
return defaultImg; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 时间格式转换 |
|
|
|
|
|
* @param dateTime 如 2024-05-01 01:10:21 |
|
|
|
|
|
* @param fmt 可选参数[Y-m-d H:i:s,Y-m-d,Y-m-d H,Y-m-d H:i,H:i:s,H:i] |
|
|
|
|
|
* @returns {string} |
|
|
|
|
|
*/ |
|
|
|
|
|
function formatToDateTime(dateTime, fmt = 'Y-m-d H:i:s') { |
|
|
|
|
|
if (!dateTime) return ''; // 如果为空,返回空字符串
|
|
|
|
|
|
const date = new Date(dateTime); // 将字符串转换为 Date 对象
|
|
|
|
|
|
|
|
|
|
|
|
// 定义格式化规则
|
|
|
|
|
|
const o = { |
|
|
|
|
|
'Y+': date.getFullYear(), // 年
|
|
|
|
|
|
'm+': String(date.getMonth() + 1).padStart(2, '0'), // 月
|
|
|
|
|
|
'd+': String(date.getDate()).padStart(2, '0'), // 日
|
|
|
|
|
|
'H+': String(date.getHours()).padStart(2, '0'), // 小时
|
|
|
|
|
|
'i+': String(date.getMinutes()).padStart(2, '0'), // 分钟
|
|
|
|
|
|
's+': String(date.getSeconds()).padStart(2, '0'), // 秒
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 替换格式模板中的占位符
|
|
|
|
|
|
for (const k in o) { |
|
|
|
|
|
if (new RegExp(`(${k})`).test(fmt)) { |
|
|
|
|
|
fmt = fmt.replace(RegExp.$1, o[k]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return fmt; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//跳转首页
|
|
|
//跳转首页
|
|
|
function openHomeView() { |
|
|
function openHomeView() { |
|
|
@ -195,5 +225,6 @@ module.exports = { |
|
|
formatLocation, |
|
|
formatLocation, |
|
|
dateUtils, |
|
|
dateUtils, |
|
|
hexToRgba, |
|
|
hexToRgba, |
|
|
img |
|
|
img, |
|
|
|
|
|
formatToDateTime |
|
|
} |
|
|
} |
|
|
|