You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
import dayjs from "dayjs";
|
|
require("dayjs/locale/zh-cn");
|
|
import isToday from "dayjs/plugin/isToday.js";
|
|
|
|
dayjs.locale("zh-cn");
|
|
dayjs.extend(isToday);
|
|
|
|
export { dayjs };
|
|
|
|
// https://dayjs.fenxianglu.cn/category/display.html
|
|
export function timeFormat(dateTime = null, formatStr = "YYYY-MM-DD") {
|
|
return dayjs(dateTime).format(formatStr);
|
|
}
|
|
|
|
/**
|
|
* 时间间隔,返回值为 xx小时xx分钟
|
|
* @param {String} fromTime
|
|
* @param {String} toTime
|
|
*/
|
|
export function timeDiff(fromTime, toTime) {
|
|
const diff = dayjs(toTime).diff(dayjs(fromTime), "minute", true);
|
|
let result = "";
|
|
if (diff >= 60) {
|
|
result += `${parseInt(diff / 60)}小时`;
|
|
}
|
|
if (diff % 60 !== 0) {
|
|
result += `${diff % 60}分`;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 隐藏身份证号
|
|
* @param {String} idCardNo
|
|
*/
|
|
export function hideIdCardNo(idCardNo) {
|
|
return idCardNo.replace(/(.{4}).+(.{3})/, `$1****$2`);
|
|
}
|
|
|
|
export function hideMobileNo(mobileNo) {
|
|
return mobileNo.replace(/(.{3}).+(.{4})/, `$1****$2`);
|
|
}
|
|
|
|
export function hideBankCardNo(bankCardNo) {
|
|
return bankCardNo.replace(/(.{4}).+(.{4})/, `$1****$2`);
|
|
}
|