From d1448cb0ef10f358bb7bddb4e1ec268515e0b787 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 11:46:57 +0800 Subject: [PATCH] 项目初始化 --- uni_modules/uview-ui/components/u-calendar/util.js | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 85 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/components/u-calendar/util.js b/uni_modules/uview-ui/components/u-calendar/util.js new file mode 100644 index 0000000..ca4736b --- /dev/null +++ b/uni_modules/uview-ui/components/u-calendar/util.js @@ -0,0 +1,85 @@ +export default { + methods: { + // 璁剧疆鏈堜唤鏁版嵁 + setMonth() { + // 鏈堝垵鏄懆鍑� + const day = dayjs(this.date).date(1).day() + const start = day == 0 ? 6 : day - 1 + + // 鏈湀澶╂暟 + const days = dayjs(this.date).endOf('month').format('D') + + // 涓婁釜鏈堝ぉ鏁� + const prevDays = dayjs(this.date).endOf('month').subtract(1, 'month').format('D') + + // 鏃ユ湡鏁版嵁 + const arr = [] + // 娓呯┖琛ㄦ牸 + this.month = [] + + // 娣诲姞涓婃湀鏁版嵁 + arr.push( + ...new Array(start).fill(1).map((e, i) => { + const day = prevDays - start + i + 1 + + return { + value: day, + disabled: true, + date: dayjs(this.date).subtract(1, 'month').date(day).format('YYYY-MM-DD') + } + }) + ) + + // 娣诲姞鏈湀鏁版嵁 + arr.push( + ...new Array(days - 0).fill(1).map((e, i) => { + const day = i + 1 + + return { + value: day, + date: dayjs(this.date).date(day).format('YYYY-MM-DD') + } + }) + ) + + // 娣诲姞涓嬩釜鏈� + arr.push( + ...new Array(42 - days - start).fill(1).map((e, i) => { + const day = i + 1 + + return { + value: day, + disabled: true, + date: dayjs(this.date).add(1, 'month').date(day).format('YYYY-MM-DD') + } + }) + ) + + // 鍒嗗壊鏁扮粍 + for (let n = 0; n < arr.length; n += 7) { + this.month.push( + arr.slice(n, n + 7).map((e, i) => { + e.index = i + n + + // 鑷畾涔変俊鎭� + const custom = this.customList.find((c) => c.date == e.date) + + // 鍐滃巻 + if (this.lunar) { + const { + IDayCn, + IMonthCn + } = this.getLunar(e.date) + e.lunar = IDayCn == '鍒濅竴' ? IMonthCn : IDayCn + } + + return { + ...e, + ...custom + } + }) + ) + } + } + } +} -- Gitblit v1.9.3