240 lines
5.8 KiB
TypeScript
240 lines
5.8 KiB
TypeScript
// pages/settings/settings.ts
|
||
import { todoStorage } from '../../utils/todoStorage';
|
||
|
||
Component({
|
||
data: {
|
||
activeTab: 'settings',
|
||
darkMode: false,
|
||
notifications: true,
|
||
autoBackup: true,
|
||
stats: {} as any,
|
||
appVersion: '1.0.0',
|
||
showAboutDialog: false,
|
||
showBackupDialog: false,
|
||
backupData: ''
|
||
},
|
||
|
||
lifetimes: {
|
||
attached() {
|
||
this.loadSettings();
|
||
this.loadStats();
|
||
}
|
||
},
|
||
|
||
methods: {
|
||
// 加载设置
|
||
loadSettings() {
|
||
try {
|
||
const settings = wx.getStorageSync('pure_todo_settings');
|
||
if (settings) {
|
||
const parsedSettings = JSON.parse(settings);
|
||
this.setData({
|
||
darkMode: parsedSettings.darkMode || false,
|
||
notifications: parsedSettings.notifications !== false,
|
||
autoBackup: parsedSettings.autoBackup !== false
|
||
});
|
||
}
|
||
} catch (error) {
|
||
console.error('加载设置失败:', error);
|
||
}
|
||
},
|
||
|
||
// 保存设置
|
||
saveSettings() {
|
||
try {
|
||
const settings = {
|
||
darkMode: this.data.darkMode,
|
||
notifications: this.data.notifications,
|
||
autoBackup: this.data.autoBackup
|
||
};
|
||
wx.setStorageSync('pure_todo_settings', JSON.stringify(settings));
|
||
} catch (error) {
|
||
console.error('保存设置失败:', error);
|
||
}
|
||
},
|
||
|
||
// 加载统计信息
|
||
loadStats() {
|
||
const stats = todoStorage.getStats();
|
||
this.setData({ stats });
|
||
},
|
||
|
||
// 切换深色模式
|
||
onDarkModeChange(e: any) {
|
||
this.setData({ darkMode: e.detail.value }, () => {
|
||
this.saveSettings();
|
||
wx.showToast({
|
||
title: e.detail.value ? '已开启深色模式' : '已关闭深色模式',
|
||
icon: 'success'
|
||
});
|
||
});
|
||
},
|
||
|
||
// 切换通知
|
||
onNotificationsChange(e: any) {
|
||
this.setData({ notifications: e.detail.value }, () => {
|
||
this.saveSettings();
|
||
wx.showToast({
|
||
title: e.detail.value ? '已开启通知' : '已关闭通知',
|
||
icon: 'success'
|
||
});
|
||
});
|
||
},
|
||
|
||
// 切换自动备份
|
||
onAutoBackupChange(e: any) {
|
||
this.setData({ autoBackup: e.detail.value }, () => {
|
||
this.saveSettings();
|
||
wx.showToast({
|
||
title: e.detail.value ? '已开启自动备份' : '已关闭自动备份',
|
||
icon: 'success'
|
||
});
|
||
});
|
||
},
|
||
|
||
// 导出数据
|
||
exportData() {
|
||
const data = todoStorage.exportData();
|
||
this.setData({
|
||
backupData: data,
|
||
showBackupDialog: true
|
||
});
|
||
},
|
||
|
||
// 导入数据
|
||
importData() {
|
||
wx.showModal({
|
||
title: '导入数据',
|
||
content: '请将备份数据粘贴到输入框中',
|
||
editable: true,
|
||
placeholderText: '粘贴备份数据...',
|
||
success: (res) => {
|
||
if (res.confirm && res.content) {
|
||
const success = todoStorage.importData(res.content);
|
||
if (success) {
|
||
this.loadStats();
|
||
wx.showToast({
|
||
title: '数据导入成功',
|
||
icon: 'success'
|
||
});
|
||
} else {
|
||
wx.showToast({
|
||
title: '数据格式错误',
|
||
icon: 'error'
|
||
});
|
||
}
|
||
}
|
||
}
|
||
});
|
||
},
|
||
|
||
// 清空数据
|
||
clearData() {
|
||
wx.showModal({
|
||
title: '确认清空',
|
||
content: '确定要清空所有数据吗?此操作不可恢复!',
|
||
success: (res) => {
|
||
if (res.confirm) {
|
||
todoStorage.clearAllData();
|
||
this.loadStats();
|
||
wx.showToast({
|
||
title: '数据已清空',
|
||
icon: 'success'
|
||
});
|
||
}
|
||
}
|
||
});
|
||
},
|
||
|
||
// 重置设置
|
||
resetSettings() {
|
||
wx.showModal({
|
||
title: '确认重置',
|
||
content: '确定要重置所有设置吗?',
|
||
success: (res) => {
|
||
if (res.confirm) {
|
||
this.setData({
|
||
darkMode: false,
|
||
notifications: true,
|
||
autoBackup: true
|
||
}, () => {
|
||
this.saveSettings();
|
||
wx.showToast({
|
||
title: '设置已重置',
|
||
icon: 'success'
|
||
});
|
||
});
|
||
}
|
||
}
|
||
});
|
||
},
|
||
|
||
// 显示关于对话框
|
||
showAbout() {
|
||
this.setData({ showAboutDialog: true });
|
||
},
|
||
|
||
// 隐藏关于对话框
|
||
hideAbout() {
|
||
this.setData({ showAboutDialog: false });
|
||
},
|
||
|
||
// 隐藏备份对话框
|
||
hideBackup() {
|
||
this.setData({ showBackupDialog: false });
|
||
},
|
||
|
||
// 复制备份数据
|
||
copyBackupData() {
|
||
wx.setClipboardData({
|
||
data: this.data.backupData,
|
||
success: () => {
|
||
wx.showToast({
|
||
title: '备份数据已复制',
|
||
icon: 'success'
|
||
});
|
||
}
|
||
});
|
||
},
|
||
|
||
// 标签页切换
|
||
onTabChange(e: any) {
|
||
const targetPage = e.detail.value;
|
||
if (targetPage === 'home') {
|
||
wx.switchTab({ url: '/pages/index/index' });
|
||
} else if (targetPage === 'list') {
|
||
wx.switchTab({ url: '/pages/list/list' });
|
||
} else if (targetPage === 'statistics') {
|
||
wx.switchTab({ url: '/pages/statistics/statistics' });
|
||
}
|
||
},
|
||
|
||
// 联系开发者
|
||
contactDeveloper() {
|
||
wx.showModal({
|
||
title: '联系开发者',
|
||
content: '如有问题或建议,请通过以下方式联系:\n\n邮箱:developer@example.com\n微信:developer_wechat',
|
||
showCancel: false
|
||
});
|
||
},
|
||
|
||
// 检查更新
|
||
checkUpdate() {
|
||
wx.showToast({
|
||
title: '已是最新版本',
|
||
icon: 'success'
|
||
});
|
||
},
|
||
|
||
// 给应用评分
|
||
rateApp() {
|
||
wx.showModal({
|
||
title: '给应用评分',
|
||
content: '感谢您的使用!请在应用商店给Pure Todo一个好评吧!',
|
||
showCancel: false
|
||
});
|
||
}
|
||
}
|
||
});
|
||
|