feat: 祈福小助手万年历小程序第一期
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
weekStartDay: 0,
|
||||
ziHourSect: 'lateZiNextDay',
|
||||
solarTime: true,
|
||||
bookmarks: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadSettings();
|
||||
this.loadBookmarks();
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadBookmarks();
|
||||
},
|
||||
|
||||
loadSettings() {
|
||||
const settings = wx.getStorageSync('lunar-settings') || {};
|
||||
this.setData({
|
||||
weekStartDay: settings.weekStartDay || 0,
|
||||
ziHourSect: settings.ziHourSect || 'lateZiNextDay',
|
||||
solarTime: settings.solarTime !== false
|
||||
});
|
||||
},
|
||||
|
||||
saveSettings() {
|
||||
const { weekStartDay, ziHourSect, solarTime } = this.data;
|
||||
wx.setStorageSync('lunar-settings', { weekStartDay, ziHourSect, solarTime });
|
||||
},
|
||||
|
||||
loadBookmarks() {
|
||||
const bookmarks = wx.getStorageSync('lunar-bookmarks') || [];
|
||||
this.setData({ bookmarks });
|
||||
},
|
||||
|
||||
setWeekStart(e) {
|
||||
this.setData({ weekStartDay: Number(e.currentTarget.dataset.v) });
|
||||
this.saveSettings();
|
||||
},
|
||||
|
||||
setZiSect(e) {
|
||||
this.setData({ ziHourSect: e.currentTarget.dataset.v });
|
||||
this.saveSettings();
|
||||
},
|
||||
|
||||
onSolarTimeChange(e) {
|
||||
this.setData({ solarTime: e.detail.value });
|
||||
this.saveSettings();
|
||||
},
|
||||
|
||||
removeBookmark(e) {
|
||||
const date = e.currentTarget.dataset.date;
|
||||
let bookmarks = this.data.bookmarks.filter(b => b.date !== date);
|
||||
wx.setStorageSync('lunar-bookmarks', bookmarks);
|
||||
this.setData({ bookmarks });
|
||||
wx.showToast({ title: '已删除', icon: 'success' });
|
||||
},
|
||||
|
||||
login() {
|
||||
wx.getUserProfile({
|
||||
desc: '用于完善用户资料',
|
||||
success: (res) => {
|
||||
this.setData({ userInfo: res.userInfo });
|
||||
wx.setStorageSync('lunar-user-info', res.userInfo);
|
||||
wx.showToast({ title: '登录成功', icon: 'success' });
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({ title: '登录失败', icon: 'none' });
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"navigationBarTitleText": "设置",
|
||||
"enablePullDownRefresh": false
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<view class="container">
|
||||
<!-- 用户信息 -->
|
||||
<view class="card">
|
||||
<view class="section-title">用户信息</view>
|
||||
<view class="flex items-center gap-2" wx:if="{{userInfo}}">
|
||||
<image src="{{userInfo.avatarUrl}}" class="avatar" mode="aspectFill"/>
|
||||
<view>
|
||||
<text class="text-base font-medium">{{userInfo.nickName}}</text>
|
||||
<text class="text-xs text-muted block">已登录</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="btn-primary" wx:else bindtap="login">微信登录</view>
|
||||
</view>
|
||||
|
||||
<!-- 偏好设置 -->
|
||||
<view class="card">
|
||||
<view class="section-title">偏好设置</view>
|
||||
|
||||
<view class="setting-item">
|
||||
<text class="setting-label">周起始日</text>
|
||||
<view class="flex gap-2">
|
||||
<view class="btn-outline {{weekStartDay === 0 ? 'active' : ''}}" bindtap="setWeekStart" data-v="0">周日</view>
|
||||
<view class="btn-outline {{weekStartDay === 1 ? 'active' : ''}}" bindtap="setWeekStart" data-v="1">周一</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="setting-item">
|
||||
<text class="setting-label">子时流派</text>
|
||||
<view class="flex gap-2">
|
||||
<view class="btn-outline {{ziHourSect === 'lateZiNextDay' ? 'active' : ''}}" bindtap="setZiSect" data-v="lateZiNextDay">晚子时算次日</view>
|
||||
<view class="btn-outline {{ziHourSect === 'lateZiSameDay' ? 'active' : ''}}" bindtap="setZiSect" data-v="lateZiSameDay">晚子时算当日</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="setting-item">
|
||||
<text class="setting-label">真太阳时校正</text>
|
||||
<switch checked="{{solarTime}}" bindchange="onSolarTimeChange" color="#C41E3A"/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 收藏管理 -->
|
||||
<view class="card">
|
||||
<view class="section-title">我的收藏</view>
|
||||
<view class="bookmark-list" wx:if="{{bookmarks.length > 0}}">
|
||||
<view class="bookmark-item" wx:for="{{bookmarks}}" wx:key="date">
|
||||
<view class="flex justify-between items-center">
|
||||
<view>
|
||||
<text class="text-base font-medium">{{item.date}}</text>
|
||||
<text class="text-xs text-muted block">{{item.lunarDate}}</text>
|
||||
</view>
|
||||
<view class="btn-ghost text-unlucky" bindtap="removeBookmark" data-date="{{item.date}}">删除</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="text-center text-muted" wx:else>
|
||||
<text>暂无收藏</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 关于 -->
|
||||
<view class="card">
|
||||
<view class="section-title">关于</view>
|
||||
<view class="text-sm text-muted">
|
||||
<text>万年历小程序 v1.0.0</text>
|
||||
<text class="block mt-1">提供农历、黄历、八字、运势、占卜等功能</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,47 @@
|
||||
.container {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
margin-bottom: 16rpx;
|
||||
color: #C41E3A;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1rpx solid #E8D5C4;
|
||||
}
|
||||
|
||||
.setting-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.btn-outline.active {
|
||||
background: #C41E3A;
|
||||
color: #FFFFFF;
|
||||
border-color: #C41E3A;
|
||||
}
|
||||
|
||||
.bookmark-item {
|
||||
padding: 16rpx 0;
|
||||
border-bottom: 1rpx solid #E8D5C4;
|
||||
}
|
||||
|
||||
.bookmark-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
Reference in New Issue
Block a user