Initial Commit
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
// settings.js
|
||||
const storage = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
dataCount: {
|
||||
persons: 0,
|
||||
anniversaries: 0
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadDataCount()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadDataCount()
|
||||
},
|
||||
|
||||
/**
|
||||
* 加载数据统计
|
||||
*/
|
||||
loadDataCount() {
|
||||
const persons = storage.getPersons()
|
||||
const anniversaries = storage.getAnniversaries()
|
||||
|
||||
this.setData({
|
||||
dataCount: {
|
||||
persons: persons.length,
|
||||
anniversaries: anniversaries.length
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*/
|
||||
onExportData() {
|
||||
const data = storage.exportData()
|
||||
|
||||
// 转换为JSON字符串
|
||||
const jsonStr = JSON.stringify(data, null, 2)
|
||||
|
||||
// 在小程序中,可以通过提示用户复制
|
||||
wx.setClipboardData({
|
||||
data: jsonStr,
|
||||
success: () => {
|
||||
wx.showToast({
|
||||
title: '数据已复制到剪贴板',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*/
|
||||
onImportData() {
|
||||
wx.showModal({
|
||||
title: '导入数据',
|
||||
content: '将从剪贴板读取数据并导入。注意:导入会覆盖现有数据,请先备份!',
|
||||
confirmText: '确认导入',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// 读取剪贴板
|
||||
wx.getClipboardData({
|
||||
success: (res) => {
|
||||
try {
|
||||
const data = JSON.parse(res.data)
|
||||
const success = storage.importData(data)
|
||||
|
||||
if (success) {
|
||||
wx.showToast({
|
||||
title: '导入成功',
|
||||
icon: 'success'
|
||||
})
|
||||
setTimeout(() => {
|
||||
wx.reLaunch({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}, 1500)
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '导入失败,请检查数据格式',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
wx.showToast({
|
||||
title: '数据格式错误',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 清空所有数据
|
||||
*/
|
||||
onClearData() {
|
||||
wx.showModal({
|
||||
title: '确认清空',
|
||||
content: '确定要清空所有数据吗?此操作不可恢复!',
|
||||
confirmText: '确认清空',
|
||||
confirmColor: '#ff5722',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const success = storage.clearAllData()
|
||||
|
||||
if (success) {
|
||||
wx.showToast({
|
||||
title: '已清空',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
wx.reLaunch({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<!--settings.wxml-->
|
||||
<view class="container">
|
||||
<view class="settings-list">
|
||||
<!-- 数据备份 -->
|
||||
<view class="setting-section">
|
||||
<text class="section-title">数据管理</text>
|
||||
|
||||
<view class="setting-item" bindtap="onExportData">
|
||||
<text class="item-label">📤 导出数据</text>
|
||||
<text class="item-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="setting-item" bindtap="onImportData">
|
||||
<text class="item-label">📥 导入数据</text>
|
||||
<text class="item-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<view class="setting-item" bindtap="onClearData">
|
||||
<text class="item-label danger">🗑️ 清空所有数据</text>
|
||||
<text class="item-arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 关于 -->
|
||||
<view class="setting-section">
|
||||
<text class="section-title">关于</text>
|
||||
|
||||
<view class="setting-item">
|
||||
<text class="item-label">版本号</text>
|
||||
<text class="item-value">v1.0.0</text>
|
||||
</view>
|
||||
|
||||
<view class="setting-item">
|
||||
<text class="item-label">开发作者</text>
|
||||
<text class="item-value">生日提醒团队</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 提示信息 -->
|
||||
<view class="info-box">
|
||||
<text class="info-title">💡 温馨提示</text>
|
||||
<text class="info-text">1. 建议定期导出数据备份\n2. 农历转换目前使用简化算法\n3. 提醒功能需要小程序权限</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/**settings.wxss**/
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background-color: #f5f5f5;
|
||||
padding-bottom: 120rpx;
|
||||
}
|
||||
|
||||
.settings-list {
|
||||
padding: 32rpx;
|
||||
}
|
||||
|
||||
.setting-section {
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
margin-bottom: 32rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
padding: 24rpx 32rpx;
|
||||
background-color: #f9f9f9;
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
font-weight: 500;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 32rpx;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.setting-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.item-label {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.item-label.danger {
|
||||
color: #ff5722;
|
||||
}
|
||||
|
||||
.item-value {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.item-arrow {
|
||||
font-size: 40rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
background-color: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 32rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.info-title {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
display: block;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.info-text {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
line-height: 2;
|
||||
white-space: pre-line;
|
||||
display: block;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user