From 321e686d68597c653d32983301c0db1aa4c312ff Mon Sep 17 00:00:00 2001 From: FengHui Date: Mon, 13 Apr 2026 12:29:47 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/globalFunction.js | 81 ++++++++++++++++++++++++ packageA/pages/selectDate/selectDate.vue | 19 ++---- pages/login/sms-verify.vue | 15 +++-- pages/mine/company-mine.vue | 7 +- stores/useUserStore.js | 12 ++-- 5 files changed, 109 insertions(+), 25 deletions(-) diff --git a/common/globalFunction.js b/common/globalFunction.js index a523251..de59a3b 100644 --- a/common/globalFunction.js +++ b/common/globalFunction.js @@ -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, diff --git a/packageA/pages/selectDate/selectDate.vue b/packageA/pages/selectDate/selectDate.vue index ff13fc7..bb02342 100644 --- a/packageA/pages/selectDate/selectDate.vue +++ b/packageA/pages/selectDate/selectDate.vue @@ -46,12 +46,10 @@