新增部分优惠券页面

This commit is contained in:
gyq
2025-11-20 10:27:08 +08:00
parent 805236dc5d
commit f74364a253
13 changed files with 887 additions and 368 deletions

View File

@@ -1,3 +1,7 @@
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
dayjs.extend(customParseFormat); // 注册插件
/**
* 过滤输入,只允许数字和最多两位小数
* @param {string} value - 输入框当前值
@@ -41,4 +45,30 @@ export function filterNumberInput(value, isIntegerOnly = false) {
}
return filtered;
}
}
/**
* 时间格式互转HH:mm → HH:mm:ssHH:mm:ss → HH:mm
* @param {string} timeStr - 输入的时间字符串
* @returns {string} 转换后的时间字符串
*/
export const convertTimeFormat = (timeStr) => {
if (!timeStr) return '00:00';
// 正则判断格式
const isHms = /^\d{1,2}:\d{2}:\d{2}$/.test(timeStr); // HH:mm:ss
const isHm = /^\d{1,2}:\d{2}$/.test(timeStr); // HH:mm
if (isHm) {
// HH:mm → 解析后格式化为 HH:mm:ss
return dayjs(timeStr, 'HH:mm').format('HH:mm:ss');
}
if (isHms) {
// HH:mm:ss → 解析后格式化为 HH:mm
return dayjs(timeStr, 'HH:mm:ss').format('HH:mm');
}
// 非法格式兜底
return '00:00';
};