bug修复

This commit is contained in:
FengHui
2026-04-13 12:29:47 +08:00
parent 3d8e13c665
commit 321e686d68
5 changed files with 109 additions and 25 deletions

View File

@@ -584,6 +584,86 @@ function isInWechatMiniProgramWebview() {
function isEmptyObject(obj) {
return obj && typeof obj === 'object' && !Array.isArray(obj) && Object.keys(obj).length === 0;
}
/**
* 农历日期工具
* 提供公历转农历日期的中文表示
*/
export const LunarUtil = {
/**
* 获取农历日期的中文表示
* @param {number} year - 公历年
* @param {number} month - 公历月 (1-12)
* @param {number} day - 公历日
* @returns {string} 农历日期的中文表示(初一、初二...三十)
*/
getLunarDayInChinese(year, month, day) {
// 这里使用简化的农历转换算法
// 实际项目中可以根据需要扩展更完整的农历功能
const lunarDays = this.solarToLunar(year, month, day);
return this.getDayInChinese(lunarDays.day);
},
/**
* 简化的公历转农历日期算法
* 注意:这是一个简化版,实际农历计算更复杂
* 仅用于生成初一到三十的日期表示
*/
solarToLunar(year, month, day) {
// 这里使用简化算法,实际项目中可以使用更精确的算法
// 对于本项目,我们只需要生成初一到三十的序列
// 实际的农历计算需要考虑节气、闰月等因素
const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// 处理闰年
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
daysInMonth[1] = 29;
}
// 计算当年已过天数
let dayOfYear = 0;
for (let i = 0; i < month - 1; i++) {
dayOfYear += daysInMonth[i];
}
dayOfYear += day;
// 简化的农历月份计算(实际农历月份计算更复杂)
const lunarMonth = Math.ceil(dayOfYear / 29.5);
const lunarDay = (dayOfYear % 29) || 29;
return {
month: lunarMonth,
day: lunarDay
};
},
/**
* 将农历日期转换为中文表示
* @param {number} day - 农历日
* @returns {string} 中文表示(初一、初二...三十)
*/
getDayInChinese(day) {
if (day === 1) {
return '初一';
} else if (day === 15) {
return '十五';
} else if (day === 30) {
return '三十';
} else {
const digits = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十'];
if (day <= 10) {
return '初' + digits[day];
} else if (day <= 19) {
return '十' + (day === 10 ? '' : digits[day - 10]);
} else if (day <= 29) {
return '廿' + (day === 20 ? '' : digits[day - 20]);
} else {
return '三十';
}
}
}
};
/**
* 身份证号码校验工具
* 支持15位和18位身份证号码校验
@@ -941,6 +1021,7 @@ export default {
cloneDeep,
formatDate,
IdCardValidator,
LunarUtil,
getdeviceInfo,
checkingPhoneRegExp,
checkingEmailRegExp,