"use strict"; const common_vendor = require("../../common/vendor.js"); const request_api = require("../../request/api.js"); const common_assets = require("../../common/assets.js"); const _sfc_main = { name: "LCCalendar", data() { return { weekList: ["日", "一", "二", "三", "四", "五", "六"], monthDateList: [], selectMonthIndex: 0, //选中月份下标 selectMonth: "", //选中年月 selectDateStr: "", //选中日期 startDateStr: "", //开始日期 endDateStr: "", //结束日期 selectYear: "", Month: "", calendarApiData: [] // 新增:存储接口返回的日历数据 }; }, created() { let currentDate = /* @__PURE__ */ new Date(); let currentYear = currentDate.getFullYear(); let currentMonth = currentDate.getMonth() + 1; let currentDay = currentDate.getDate(); this.selectMonthIndex = 20 * 12 + currentMonth - 1; this.selectMonth = currentYear + "年" + currentMonth + "月"; this.startDateStr = currentYear + "-" + (currentMonth > 9 ? currentMonth : "0" + currentMonth) + "-01"; this.endDateStr = this.selectDateStr = `${currentYear}-${currentMonth > 9 ? currentMonth : "0" + currentMonth}-${currentDay > 9 ? currentDay : "0" + currentDay}`; this.getYesterdayDateData(); this.generateMonthDateListData(); this.emitDateChange( currentYear, currentMonth, currentDay, this.getTodayItem(currentYear, currentMonth, currentDay), this.getPrevDayItem(currentYear, currentMonth, currentDay) // 新增上一天数据 ); }, mounted() { this.getCalendarCombinedData(); }, methods: { // 3. 在日历组件methods中新增getPrevDayItem方法 /** * 获取指定日期的上一天数据 */ getPrevDayItem(year, month, day) { const currentDate = /* @__PURE__ */ new Date(`${year}-${month}-${day}`); const prevDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1e3); const prevYear = prevDate.getFullYear(); const prevMonth = prevDate.getMonth() + 1; const prevDay = prevDate.getDate(); const targetDate = `${prevYear}-${prevMonth > 9 ? prevMonth : "0" + prevMonth}-${prevDay > 9 ? prevDay : "0" + prevDay}`; const currentMonthList = this.monthDateList[this.selectMonthIndex] || []; const localItem = currentMonthList.find((item) => item.date === targetDate) || null; const apiData = this.getCalendarItemByDate(targetDate) || {}; return { ...localItem, zt_count: apiData.zt_count || 0, top_sector: apiData.top_sector || "-", zaban_rate: apiData.zaban_rate || "0%" }; }, /** * 获取当天的item数据(合并接口数据) */ getTodayItem(year, month, day) { const targetDate = `${year}-${month > 9 ? month : "0" + month}-${day > 9 ? day : "0" + day}`; const currentMonthList = this.monthDateList[this.selectMonthIndex] || []; const localItem = currentMonthList.find((item) => item.date === targetDate) || null; if (!localItem) return null; const apiData = this.getCalendarItemByDate(targetDate) || {}; return { ...localItem, zt_count: apiData.zt_count || 0, top_sector: apiData.top_sector || "-", // 可补充其他接口字段 zaban_rate: apiData.zaban_rate || "0%" // 示例:炸板率 }; }, /** * 触发日期变更事件(传递包含接口数据的item) */ // emitDateChange(year, month, day, item) { // const yearMonth = `${year}-${month > 9 ? month : '0' + month}`; // const fullDate = `${year}-${month > 9 ? month : '0' + month}-${day > 9 ? day : '0' + day}`; // this.$emit('date-change', { // yearMonth, // fullDate, // item: item || { // 兜底:无item时赋值空对象+默认值 // date: fullDate, // year, // month, // day, // zt_count: 0, // top_sector: '-', // zaban_rate: '0%' // }, // year, // month, // day // }); // }, emitDateChange(year, month, day, item, prevItem = { zt_count: 0 }) { const yearMonth = `${year}-${month > 9 ? month : "0" + month}`; const fullDate = `${year}-${month > 9 ? month : "0" + month}-${day > 9 ? day : "0" + day}`; this.$emit("date-change", { yearMonth, fullDate, item: item || { // 兜底:无当前item时赋值空对象+默认值 date: fullDate, year, month, day, zt_count: 0, top_sector: "-", zaban_rate: "0%" }, prevItem: prevItem || { // 新增:传递上一天数据,兜底默认值 zt_count: 0, top_sector: "-", zaban_rate: "0%" }, year, month, day }); }, /** * 获取当前时间前一天的数据 */ getYesterdayDateData() { let currentDate = /* @__PURE__ */ new Date(); let selectDate = new Date(currentDate); selectDate.setDate(selectDate.getDate() - 1); selectDate.getFullYear(); selectDate.getMonth() + 1; selectDate.getDate(); this.selectYear = selectDate.getFullYear(); this.Month = selectDate.getMonth() + 1; }, /** * 根据日期查找接口中的日历数据 * @param {String} dateStr 格式:2026-01-01 * @returns {Object} 匹配的日历数据 */ getCalendarItemByDate(dateStr) { if (!dateStr || !this.calendarApiData.length) return null; const formatDate = dateStr.replace(/-/g, ""); return this.calendarApiData.find((item) => item.date === formatDate) || null; }, /** * 根据zt_count和是否休市获取背景色样式类 * @param {Number} count zt_count数值 * @param {Number} index 日期下标(判断是否休市) * @returns {String} 样式类名 */ getZtCountBgClass(count, index) { if (index % 7 === 0 || index % 7 === 6 || count === 0 || count === null || count === void 0) { return ""; } if (count >= 80) return "zt-bg-80"; if (count >= 60) return "zt-bg-60"; if (count >= 40) return "zt-bg-40"; return "zt-bg-40-less"; }, /** * 根据zt_count值获取文字颜色 * @param {Number} count zt_count数值 * @param {Number} index 日期下标(用于判断周末) * @returns {String} 文字颜色值 */ getZtCountTextColor(count, index) { if (index !== void 0 && (index % 7 === 0 || index % 7 === 6)) { return "#999999"; } if (count === void 0 || count === null || count === 0) { return "#2A2A2A"; } if (count >= 80) return "#5D288F"; if (count >= 60) return "#BE1B1B"; if (count >= 40) return "#F59B38"; return "#2958AA"; }, /** * 获取日历接口数据 */ async getCalendarCombinedData() { try { let param = { year: this.selectYear, month: this.Month }; const res = await request_api.calendarCombinedData(param); if (res.success && Array.isArray(res.data)) { this.calendarApiData = res.data; if (this.selectDateStr) { const [year, month, day] = this.selectDateStr.split("-").map(Number); this.emitDateChange( year, month, day, this.getTodayItem(year, month, day), this.getPrevDayItem(year, month, day) // 新增上一天数据 ); } } else { this.calendarApiData = []; common_vendor.index.__f__("warn", "at components/LCCalendar/LCCalendar.vue:330", "日历接口返回数据格式异常", res); } } catch (error) { this.calendarApiData = []; common_vendor.index.__f__("error", "at components/LCCalendar/LCCalendar.vue:334", "获取日历数据失败", error); } }, /** * 生成日期数组 */ generateMonthDateListData() { let currentDate = /* @__PURE__ */ new Date(); let currentYear = currentDate.getFullYear(); let currentMonth = currentDate.getMonth() + 1; let currentDay = currentDate.getDate(); let monthDateList = []; for (var i = currentYear - 20; i < currentYear + 20; i++) { for (var j = 0; j < 12; j++) { let date = new Date(i, j + 1, 0); let firstDayOfMonth = new Date(i, j + 1, 0); firstDayOfMonth.setDate(1); let currentMonthDay = date.getDate(); let firstDayWeek = firstDayOfMonth.getDay() + 1; let daysOfMonth = []; for (var k = 1; k <= currentMonthDay; k++) { let newDate = new Date(i, j + 1, 0); newDate.setDate(k); let newMonth = newDate.getMonth() + 1; let newDay = newDate.getDate(); let time = newDate.getTime(); let date2 = i + "-" + (newMonth > 9 ? newMonth : "0" + newMonth) + "-" + (newDay > 9 ? newDay : "0" + newDay); daysOfMonth.push({ date: date2, year: i, month: newMonth, day: newDay, isToday: i == currentYear && newMonth == currentMonth && newDay == currentDay ? true : false, isCurrentMonth: true, isLastDay: newDay == currentMonthDay ? true : false, timestamp: time }); } for (var k = 0; k < firstDayWeek - 1; k++) { let year = i; let month = j; if (j < 1) { year = i - 1; month = 12; } let lastMonthDay = new Date(year, month, 0).getDate(); let newDate = new Date(year, month - 1, lastMonthDay - k); let newMonth = newDate.getMonth() + 1; let newDay = newDate.getDate(); let time = newDate.getTime(); let date2 = year + "-" + (newMonth > 9 ? newMonth : "0" + newMonth) + "-" + (newDay > 9 ? newDay : "0" + newDay); daysOfMonth.unshift({ date: date2, year, month: newMonth, day: newDay, isToday: false, isCurrentMonth: false, isLastDay: false, timestamp: time }); } let nextMonthFirstDay = new Date(i, j + 1, 1); let lastDayOfMonth = new Date(nextMonthFirstDay - 24 * 60 * 60 * 1e3); let lastDayWeek = lastDayOfMonth.getDay() + 1; for (var k = 1; k < 8 - lastDayWeek; k++) { let year = i; let month = j; if (month > 11) { month = 0; year++; } let newDate = new Date(year, month + 1, k); let newMonth = newDate.getMonth() + 1; let newDay = newDate.getDate(); let time = newDate.getTime(); let date2 = year + "-" + (newMonth > 9 ? newMonth : "0" + newMonth) + "-" + (newDay > 9 ? newDay : "0" + newDay); daysOfMonth.push({ date: date2, year, month: newMonth, day: newDay, isToday: false, isCurrentMonth: false, isLastDay: false, timestamp: time }); } monthDateList.push(daysOfMonth); } } this.monthDateList = monthDateList; }, /** * 点击上个月 */ clickPreMonth() { if (this.selectMonthIndex > 0) { this.selectMonthIndex--; let monthList = this.monthDateList[this.selectMonthIndex]; let year = ""; let month = ""; for (let item of monthList) { if (item.isCurrentMonth) { year = item.year; month = item.month; break; } } let lastDay = ""; for (let item of monthList) { if (item.isLastDay) { lastDay = item.day; break; } } this.selectMonth = year + "年" + month + "月"; this.startDateStr = year + "-" + (month > 9 ? month : "0" + month) + "-01"; this.endDateStr = year + "-" + (month > 9 ? month : "0" + month) + "-" + lastDay; this.selectYear = year; this.Month = month; this.getCalendarCombinedData(); common_vendor.index.__f__("log", "at components/LCCalendar/LCCalendar.vue:469", "点击上个月"); } }, /** * 点击下个月 */ clickNextMonth() { if (this.selectMonthIndex < this.monthDateList.length - 1) { this.selectMonthIndex++; let monthList = this.monthDateList[this.selectMonthIndex]; let year = ""; let month = ""; for (let item of monthList) { if (item.isCurrentMonth) { year = item.year; month = item.month; break; } } let lastDay = ""; for (let item of monthList) { if (item.isLastDay) { lastDay = item.day; break; } } this.selectMonth = year + "年" + month + "月"; this.startDateStr = year + "-" + (month > 9 ? month : "0" + month) + "-01"; this.endDateStr = year + "-" + (month > 9 ? month : "0" + month) + "-" + lastDay; common_vendor.index.__f__("log", "at components/LCCalendar/LCCalendar.vue:498", "点击下个月"); this.selectYear = year; this.Month = month; this.getCalendarCombinedData(); } }, monthChange(e) { let currentDate = /* @__PURE__ */ new Date(); let currentYear = currentDate.getFullYear(); let yearMonth = e.detail.value; let selectYear = parseInt(yearMonth.split("-")[0]); let selectMonth = parseInt(yearMonth.split("-")[1]); this.selectMonthIndex = (selectYear - (currentYear - 20)) * 12 + selectMonth - 1; this.selectMonth = selectYear + "年" + selectMonth + "月"; this.startDateStr = selectYear + "-" + (selectMonth > 9 ? selectMonth : "0" + selectMonth) + "-01"; let lastDayOfMonth = new Date(selectYear, selectMonth, 0); this.endDateStr = selectYear + "-" + (selectMonth > 9 ? selectMonth : "0" + selectMonth) + "-" + lastDayOfMonth.getDate(); common_vendor.index.__f__("log", "at components/LCCalendar/LCCalendar.vue:518", "月份变更"); this.selectYear = selectYear; this.Month = selectMonth; this.getCalendarCombinedData(); }, /** * 点击选择开始日期和结束日期 * @param {Object} item */ clickSelectDate(item, index) { if (!item.isCurrentMonth) return; if (this.selectDateStr != item.date) { this.selectDateStr = item.date; const apiData = this.getCalendarItemByDate(item.date) || {}; const mergedItem = { ...item, // 本地日期基础数据 zt_count: apiData.zt_count || 0, // 涨停家数,默认0 top_sector: apiData.top_sector || "-", // 热门板块,默认'-' zaban_rate: apiData.zaban_rate || "0%", // 炸板率,示例字段 isWeekend: index % 7 === 0 || index % 7 === 6 // 是否周末 }; const currentDate = new Date(item.date); const prevDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1e3); const prevYear = prevDate.getFullYear(); const prevMonth = prevDate.getMonth() + 1; const prevDay = prevDate.getDate(); const prevDateStr = `${prevYear}-${prevMonth > 9 ? prevMonth : "0" + prevMonth}-${prevDay > 9 ? prevDay : "0" + prevDay}`; const prevApiData = this.getCalendarItemByDate(prevDateStr) || {}; let prevLocalItem = null; const currentMonthList = this.monthDateList[this.selectMonthIndex] || []; prevLocalItem = currentMonthList.find((i) => i.date === prevDateStr); if (!prevLocalItem) { const prevMonthIndex = this.selectMonthIndex - (prevMonth < item.month ? 1 : 0); const prevMonthList = this.monthDateList[prevMonthIndex] || []; prevLocalItem = prevMonthList.find((i) => i.date === prevDateStr); } const prevMergedItem = { ...prevLocalItem || {}, zt_count: prevApiData.zt_count || 0, top_sector: prevApiData.top_sector || "-", zaban_rate: prevApiData.zaban_rate || "0%", isWeekend: false // 兜底默认值 }; this.chgStockData = mergedItem; const [year, month, day] = item.date.split("-").map(Number); this.emitDateChange(year, month, day, mergedItem, prevMergedItem); common_vendor.index.__f__("log", "at components/LCCalendar/LCCalendar.vue:580", "点击某天(含接口数据)", { current: mergedItem, prev: prevMergedItem }); } } // clickSelectDate(item, index) { // if (!item.isCurrentMonth) return // if (this.selectDateStr != item.date) { // this.selectDateStr = item.date // const apiData = this.getCalendarItemByDate(item.date) || {}; // const mergedItem = { // ...item, // zt_count: apiData.zt_count || 0, // top_sector: apiData.top_sector || '-', // zaban_rate: apiData.zaban_rate || '0%', // isWeekend: index % 7 === 0 || index % 7 === 6 // }; // this.chgStockData = mergedItem; // const [year, month, day] = item.date.split('-').map(Number); // this.emitDateChange(year, month, day, mergedItem); // uni.__f__('log','at components/LCCalendar/LCCalendar.vue:602','点击某天(含接口数据)', mergedItem); // } // } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return { a: common_assets._imports_0$1, b: common_vendor.o(($event) => $options.clickPreMonth()), c: common_assets._imports_1$16, d: common_vendor.t($data.selectDateStr), e: common_assets._imports_1$2, f: common_vendor.o(($event) => $options.clickNextMonth()), g: common_vendor.f($data.weekList, (item, index, i0) => { return { a: common_vendor.t(item), b: index }; }), h: common_vendor.f($data.monthDateList[$data.selectMonthIndex], (item, index, i0) => { var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n; return common_vendor.e({ a: item.date == $data.selectDateStr }, item.date == $data.selectDateStr ? common_vendor.e({ b: common_vendor.t(item.day), c: index % 7 == 0 || index % 7 == 6 }, index % 7 == 0 || index % 7 == 6 ? {} : common_vendor.e({ d: ((_a = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _a.zt_count) > 0 }, ((_b = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _b.zt_count) > 0 ? { e: common_vendor.t((_c = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _c.zt_count), f: $options.getZtCountTextColor((_d = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _d.zt_count), g: common_vendor.t(((_e = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _e.top_sector) || "-"), h: $options.getZtCountTextColor((_f = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _f.zt_count) } : {}), { i: common_vendor.n($options.getZtCountBgClass((_g = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _g.zt_count)) }) : common_vendor.e({ j: !item.isCurrentMonth }, !item.isCurrentMonth ? {} : common_vendor.e({ k: common_vendor.t(item.day), l: index % 7 == 0 || index % 7 == 6 ? "#999999" : "#2A2A2A", m: index % 7 == 0 || index % 7 == 6 }, index % 7 == 0 || index % 7 == 6 ? {} : common_vendor.e({ n: ((_h = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _h.zt_count) > 0 }, ((_i = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _i.zt_count) > 0 ? { o: common_vendor.t((_j = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _j.zt_count), p: $options.getZtCountTextColor((_k = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _k.zt_count), q: common_vendor.t(((_l = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _l.top_sector) || "-"), r: $options.getZtCountTextColor((_m = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _m.zt_count) } : {}), { s: common_vendor.n($options.getZtCountBgClass((_n = $options.getCalendarItemByDate(item.date)) == null ? void 0 : _n.zt_count)) })), { t: index, v: common_vendor.o(($event) => $options.clickSelectDate(item), index) }); }) }; } const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]); wx.createComponent(Component); //# sourceMappingURL=../../../.sourcemap/mp-weixin/components/LCCalendar/LCCalendar.js.map