fix(wish-tree): 修复切换树时导航栏消失问题
- Canvas添加z-index: 1,确保不覆盖导航栏 - top-bar添加pointer-events: none,子元素恢复auto - WXML添加trees.length保护,防止空数组访问 - switchTree添加空数组保护
This commit is contained in:
@@ -939,6 +939,8 @@ Page({
|
||||
const direction = e.currentTarget.dataset.direction;
|
||||
const { trees, currentTreeIndex } = this.data;
|
||||
|
||||
if (!trees.length) return;
|
||||
|
||||
let newIndex = currentTreeIndex;
|
||||
if (direction === 'prev') {
|
||||
newIndex = (currentTreeIndex - 1 + trees.length) % trees.length;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<view class="switch-btn" bindtap="switchTree" data-direction="prev">
|
||||
<text class="switch-icon">‹</text>
|
||||
</view>
|
||||
<view class="tree-name">{{trees[currentTreeIndex].name || '许愿树'}}</view>
|
||||
<view class="tree-name">{{trees.length > 0 ? trees[currentTreeIndex].name : '许愿树'}}</view>
|
||||
<view class="switch-btn" bindtap="switchTree" data-direction="next">
|
||||
<text class="switch-icon">›</text>
|
||||
</view>
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* 顶部导航 */
|
||||
@@ -26,6 +27,11 @@
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
z-index: 100;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.top-bar > * {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.tree-switcher {
|
||||
|
||||
@@ -269,14 +269,60 @@ function getConstellation(month, day) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取节气 */
|
||||
/** 计算某年某节气的公历日期(21世纪 C 值法,误差±1天) */
|
||||
function getSolarTermDate(year, termIndex) {
|
||||
// 21世纪 C 值表(小寒=0, 大寒=1, 立春=2 ... 冬至=23)
|
||||
const C21 = [
|
||||
6.11, 20.84, 4.6295, 19.4599, 6.3826, 21.4155, // 小寒 大寒 立春 雨水 惊蛰 春分
|
||||
5.59, 20.888, 6.318, 21.86, 6.5, 22.20, // 清明 谷雨 立夏 小满 芒种 夏至
|
||||
7.928, 23.65, 8.35, 23.95, 8.44, 23.822, // 小暑 大暑 立秋 处暑 白露 秋分
|
||||
9.098, 24.218, 8.218, 23.08, 7.9, 22.60 // 寒露 霜降 立冬 小雪 大雪 冬至
|
||||
];
|
||||
// 20世纪 C 值表
|
||||
const C20 = [
|
||||
6.9, 21.37, 5.4055, 20.12, 7.1082, 22.83,
|
||||
6.38, 21.646, 7.108, 22.36, 7.5, 23.13,
|
||||
8.318, 24.64, 9.35, 24.77, 9.74, 24.643,
|
||||
9.878, 24.918, 9.11, 23.65, 8.8, 23.54
|
||||
];
|
||||
const Y = year % 100;
|
||||
const C = year >= 2000 ? C21[termIndex] : C20[termIndex];
|
||||
// 闰年修正:小寒、大寒、立春、雨水(1-2月)
|
||||
let leapAdjust = 0;
|
||||
if (termIndex <= 3 && isLeapYear(year)) leapAdjust = 1;
|
||||
// 特殊修正
|
||||
if (year === 2026 && termIndex === 3) leapAdjust = -1; // 2026雨水
|
||||
if (year === 2084 && termIndex === 3) leapAdjust = 1;
|
||||
if (year === 1911 && termIndex === 6) leapAdjust = 1; // 清明
|
||||
if (year === 1984 && termIndex === 7) leapAdjust = -1; // 谷雨
|
||||
if (year === 1911 && termIndex === 8) leapAdjust = 1; // 立夏
|
||||
if (year === 1981 && termIndex === 10) leapAdjust = -1; // 芒种
|
||||
if (year === 1902 && termIndex === 11) leapAdjust = 1; // 夏至
|
||||
if (year === 1928 && termIndex === 12) leapAdjust = 1; // 小暑
|
||||
if (year === 1925 && termIndex === 13) leapAdjust = -1; // 大暑
|
||||
if (year === 2002 && termIndex === 14) leapAdjust = 1; // 立秋
|
||||
if (year === 1927 && termIndex === 16) leapAdjust = 1; // 白露
|
||||
if (year === 1942 && termIndex === 17) leapAdjust = 1; // 秋分
|
||||
if (year === 2089 && termIndex === 18) leapAdjust = 1; // 寒露
|
||||
if (year === 2089 && termIndex === 19) leapAdjust = 1; // 霜降
|
||||
if (year === 1978 && termIndex === 20) leapAdjust = 1; // 立冬
|
||||
if (year === 1954 && termIndex === 21) leapAdjust = -1; // 小雪
|
||||
if (year === 1918 && termIndex === 22) leapAdjust = 1; // 大雪
|
||||
if (year === 2021 && termIndex === 22) leapAdjust = -1;
|
||||
if (year === 1902 && termIndex === 23) leapAdjust = 1; // 冬至
|
||||
|
||||
return Math.floor(Y * 0.2422 + C) - Math.floor((Y - 1) / 4) + leapAdjust;
|
||||
}
|
||||
|
||||
/** 获取节气(准确算法) */
|
||||
function getSolarTerm(year, month, day) {
|
||||
const termDates = SOLAR_TERM_DATES[month - 1];
|
||||
if (day === termDates[0]) {
|
||||
return SOLAR_TERMS[(month - 1) * 2];
|
||||
} else if (day === termDates[1]) {
|
||||
return SOLAR_TERMS[(month - 1) * 2 + 1];
|
||||
}
|
||||
// 每月两个节气:第1个在 index (month-1)*2,第2个在 (month-1)*2+1
|
||||
const idx1 = (month - 1) * 2;
|
||||
const idx2 = idx1 + 1;
|
||||
const d1 = getSolarTermDate(year, idx1);
|
||||
const d2 = getSolarTermDate(year, idx2);
|
||||
if (day === d1) return SOLAR_TERMS[idx1];
|
||||
if (day === d2) return SOLAR_TERMS[idx2];
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user