前端-工具总结
时间处理函数:
// 日期格式化
const formatRiqistamp = (timestamp) => {
const date = new Date(timestamp);
const year = date.getFullYear();
const month = addZero(date.getMonth() + 1);
const day = addZero(date.getDate());
return `${year}-${month}-${day}`;
};
// 时间格式化
const formatShijianstamp = (timestamp) => {
const date = new Date(timestamp);
const hours = addZero(date.getHours());
const minutes = addZero(date.getMinutes());
const seconds = addZero(date.getSeconds());
// return `${hours}:${minutes}:${seconds}`;
return `${hours}:${minutes}`;
};
form表单校验:
{
pattern: /^[+]?\d+[.]?\d{0,2}$/,
message: "请输入一个大于等于0的数,并且只到小数点后2位",
trigger: "blur",
},
{
pattern: /^\d+$/,
message: "请输入一个大于等于0的正整数",
trigger: "blur",
},
{
pattern: /^\+?[1-9]\d*$/,
message: "请输入一个大于0的正整数",
trigger: "blur",
},
{
pattern: /^(?:[1-9]|[1-9][0-9])$/,
message: "请输入一个大于0小于100的正整数",
trigger: "blur",
},