Compare commits
5 Commits
3f30c9c017
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 192867a8d5 | |||
| e643512dfa | |||
| f0835726de | |||
| 030e587480 | |||
| fb7b12ff76 |
+31
-15
@@ -1,8 +1,20 @@
|
|||||||
// calendar.js
|
// calendar.js
|
||||||
const storage = require('../../utils/storage')
|
const storage = require('../../utils/storage')
|
||||||
const dateUtils = require('../../utils/date')
|
const dateUtils = require('../../utils/date')
|
||||||
|
const lunar = require('../../utils/lunar')
|
||||||
const { TYPE_NAMES, TYPE_ICONS, IMPORTANCE_COLORS } = require('../../utils/constants')
|
const { TYPE_NAMES, TYPE_ICONS, IMPORTANCE_COLORS } = require('../../utils/constants')
|
||||||
|
|
||||||
|
// 算出某条纪念日在指定年份的公历 (month, day)
|
||||||
|
// 公历纪念日:每年同月同日,直接用录入时的 solarMonth/solarDay
|
||||||
|
// 农历纪念日:把农历月日转回当年公历,因为农历对应的公历日期每年都不同
|
||||||
|
function getAnniversaryDateInYear(a, year) {
|
||||||
|
if (a.isLunar && a.lunarMonth && a.lunarDay) {
|
||||||
|
const date = lunar.lunarToSolar(year, a.lunarMonth, a.lunarDay, !!a.isLeapMonth)
|
||||||
|
return { month: date.getMonth() + 1, day: date.getDate() }
|
||||||
|
}
|
||||||
|
return { month: a.solarMonth, day: a.solarDay }
|
||||||
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
currentYear: new Date().getFullYear(),
|
currentYear: new Date().getFullYear(),
|
||||||
@@ -27,8 +39,9 @@ Page({
|
|||||||
buildEventIndex(anniversaries, year, month) {
|
buildEventIndex(anniversaries, year, month) {
|
||||||
const index = {}
|
const index = {}
|
||||||
for (const a of anniversaries) {
|
for (const a of anniversaries) {
|
||||||
if (a.solarYear === year && a.solarMonth === month) {
|
const { month: m, day: d } = getAnniversaryDateInYear(a, year)
|
||||||
const key = String(a.solarDay)
|
if (m === month) {
|
||||||
|
const key = String(d)
|
||||||
if (!index[key]) index[key] = []
|
if (!index[key]) index[key] = []
|
||||||
index[key].push(a)
|
index[key].push(a)
|
||||||
}
|
}
|
||||||
@@ -99,26 +112,29 @@ Page({
|
|||||||
const { currentYear, currentMonth } = this.data
|
const { currentYear, currentMonth } = this.data
|
||||||
const persons = storage.getPersons()
|
const persons = storage.getPersons()
|
||||||
const anniversaries = storage.getAnniversaries()
|
const anniversaries = storage.getAnniversaries()
|
||||||
|
|
||||||
// 筛选本月纪念日
|
|
||||||
const monthEvents = anniversaries
|
const monthEvents = anniversaries
|
||||||
.filter(a => a.solarYear === currentYear && a.solarMonth === currentMonth)
|
|
||||||
.map(a => {
|
.map(a => {
|
||||||
const person = persons.find(p => p.id === a.personId)
|
const { month: m, day: d } = getAnniversaryDateInYear(a, currentYear)
|
||||||
const date = new Date(currentYear, currentMonth - 1, a.solarDay)
|
return { ...a, _displayMonth: m, _displayDay: d }
|
||||||
const daysUntil = dateUtils.getDaysUntil(date)
|
})
|
||||||
|
.filter(x => x._displayMonth === currentMonth)
|
||||||
|
.map(x => {
|
||||||
|
const person = persons.find(p => p.id === x.personId)
|
||||||
|
const date = new Date(currentYear, x._displayMonth - 1, x._displayDay)
|
||||||
|
const ld = lunar.solarToLunar(date)
|
||||||
return {
|
return {
|
||||||
...a,
|
...x,
|
||||||
personName: person ? person.name : '未知',
|
personName: person ? person.name : '未知',
|
||||||
typeIcon: this.getTypeIcon(a.type),
|
typeIcon: this.getTypeIcon(x.type),
|
||||||
typeName: a.customTypeName || this.getTypeName(a.type),
|
typeName: x.customTypeName || this.getTypeName(x.type),
|
||||||
dateText: dateUtils.formatDate(date, 'MM月DD日'),
|
dateText: dateUtils.formatDate(date, 'MM月DD日'),
|
||||||
daysUntil
|
lunarMD: ld.lunarText,
|
||||||
|
daysUntil: dateUtils.getDaysUntil(date)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.sort((a, b) => a.solarDay - b.solarDay)
|
.sort((a, b) => a._displayDay - b._displayDay)
|
||||||
|
|
||||||
this.setData({ monthEvents })
|
this.setData({ monthEvents })
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,10 @@
|
|||||||
<view class="event-header">
|
<view class="event-header">
|
||||||
<text class="event-icon">{{item.typeIcon}}</text>
|
<text class="event-icon">{{item.typeIcon}}</text>
|
||||||
<text class="event-title">{{item.personName}} - {{item.typeName}}</text>
|
<text class="event-title">{{item.personName}} - {{item.typeName}}</text>
|
||||||
<text class="event-date">{{item.dateText}}</text>
|
<view class="event-date-group">
|
||||||
|
<text class="event-date">{{item.dateText}}</text>
|
||||||
|
<text class="event-lunar">{{item.lunarMD}}</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="event-info">
|
<view class="event-info">
|
||||||
<text wx:if="{{item.isLunar}}" class="lunar-badge">农历</text>
|
<text wx:if="{{item.isLunar}}" class="lunar-badge">农历</text>
|
||||||
|
|||||||
@@ -249,11 +249,23 @@
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.event-date-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin-left: 12rpx;
|
||||||
|
gap: 2rpx;
|
||||||
|
}
|
||||||
|
|
||||||
.event-date {
|
.event-date {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #8A8278;
|
color: #8A8278;
|
||||||
flex-shrink: 0;
|
}
|
||||||
margin-left: 12rpx;
|
|
||||||
|
.event-lunar {
|
||||||
|
font-size: 20rpx;
|
||||||
|
color: #A9A096;
|
||||||
}
|
}
|
||||||
|
|
||||||
.event-info {
|
.event-info {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// person-detail.js
|
// person-detail.js
|
||||||
const storage = require('../../utils/storage')
|
const storage = require('../../utils/storage')
|
||||||
const dateUtils = require('../../utils/date')
|
const dateUtils = require('../../utils/date')
|
||||||
|
const lunar = require('../../utils/lunar')
|
||||||
const fmt = require('../../utils/format')
|
const fmt = require('../../utils/format')
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@@ -52,11 +53,13 @@ Page({
|
|||||||
const formatted = anniversaries.map(a => {
|
const formatted = anniversaries.map(a => {
|
||||||
const date = new Date(a.solarYear, a.solarMonth - 1, a.solarDay)
|
const date = new Date(a.solarYear, a.solarMonth - 1, a.solarDay)
|
||||||
const daysUntil = dateUtils.getDaysUntil(date)
|
const daysUntil = dateUtils.getDaysUntil(date)
|
||||||
|
const ld = lunar.solarToLunar(date)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...a,
|
...a,
|
||||||
date,
|
date,
|
||||||
dateText: dateUtils.formatDate(date, 'YYYY年MM月DD日'),
|
dateText: dateUtils.formatDate(date, 'YYYY年MM月DD日'),
|
||||||
|
lunarText: `农历 ${ld.year}年 ${ld.lunarText}`,
|
||||||
daysUntil,
|
daysUntil,
|
||||||
daysUntilAbs: Math.abs(daysUntil),
|
daysUntilAbs: Math.abs(daysUntil),
|
||||||
typeIcon: fmt.getTypeIcon(a.type),
|
typeIcon: fmt.getTypeIcon(a.type),
|
||||||
|
|||||||
@@ -44,6 +44,11 @@
|
|||||||
<text wx:if="{{item.isLunar}}" class="lunar-badge">农历</text>
|
<text wx:if="{{item.isLunar}}" class="lunar-badge">农历</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<view class="anniversary-lunar">
|
||||||
|
<text class="lunar-icon">🌙</text>
|
||||||
|
<text class="lunar-text">{{item.lunarText}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
<view wx:if="{{item.daysUntil !== undefined}}" class="days-info">
|
<view wx:if="{{item.daysUntil !== undefined}}" class="days-info">
|
||||||
<text wx:if="{{item.daysUntil === 0}}" class="days-text urgent">今天</text>
|
<text wx:if="{{item.daysUntil === 0}}" class="days-text urgent">今天</text>
|
||||||
<text wx:elif="{{item.daysUntil === 1}}" class="days-text warning">明天</text>
|
<text wx:elif="{{item.daysUntil === 1}}" class="days-text warning">明天</text>
|
||||||
|
|||||||
@@ -193,11 +193,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.anniversary-date {
|
.anniversary-date {
|
||||||
margin-bottom: 12rpx;
|
margin-bottom: 8rpx;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #5A5247;
|
color: #5A5247;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.anniversary-lunar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8rpx;
|
||||||
|
margin-bottom: 12rpx;
|
||||||
|
font-size: 22rpx;
|
||||||
|
color: #8A8278;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lunar-icon {
|
||||||
|
font-size: 20rpx;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
.date-label {
|
.date-label {
|
||||||
color: #8A8278;
|
color: #8A8278;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Page({
|
|||||||
personsCount: 0,
|
personsCount: 0,
|
||||||
anniversariesCount: 0,
|
anniversariesCount: 0,
|
||||||
lastBackupText: '从未备份',
|
lastBackupText: '从未备份',
|
||||||
version: 'v2.1.3'
|
version: 'v2.1.6'
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
|||||||
Reference in New Issue
Block a user