123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- Page({
- data: {
- userInfo: null,
- systemSettings: {
- // 系统设置
- autoUpdate: true,
- appVersion: '1.0.0'
- }
- },
- onLoad() {
- this.getUserInfo()
- this.loadSystemSettings()
- },
- // 获取用户信息
- getUserInfo() {
- const userInfo = wx.getStorageSync('userInfo')
- if (userInfo) {
- this.setData({ userInfo })
- }
- },
- // 加载系统设置
- loadSystemSettings() {
- const savedSettings = wx.getStorageSync('systemSettings')
- if (savedSettings) {
- this.setData({
- systemSettings: {
- ...this.data.systemSettings,
- ...savedSettings
- }
- })
- }
- },
- // 切换自动更新
- toggleAutoUpdate() {
- const { systemSettings } = this.data
- systemSettings.autoUpdate = !systemSettings.autoUpdate
- this.setData({ systemSettings })
- this.saveSystemSettings()
- },
- // 保存系统设置
- saveSystemSettings() {
- wx.setStorageSync('systemSettings', this.data.systemSettings)
- wx.showToast({
- title: '设置已保存',
- icon: 'success'
- })
- },
- // 检查更新
- checkUpdate() {
- const updateManager = wx.getUpdateManager()
-
- wx.showLoading({ title: '检查更新中' })
-
- updateManager.onCheckForUpdate((res) => {
- wx.hideLoading()
- if (res.hasUpdate) {
- wx.showModal({
- title: '更新提示',
- content: '检测到新版本,是否立即更新?',
- success: (modalRes) => {
- if (modalRes.confirm) {
- updateManager.onUpdateReady(() => {
- wx.showModal({
- title: '更新提示',
- content: '新版本已准备好,是否重启应用?',
- success: (restartRes) => {
- if (restartRes.confirm) {
- updateManager.applyUpdate()
- }
- }
- })
- })
- }
- }
- })
- } else {
- wx.showToast({
- title: '已是最新版本',
- icon: 'none'
- })
- }
- })
- },
- // 清除缓存
- clearCache() {
- wx.showModal({
- title: '清除缓存',
- content: '确定要清除所有本地缓存吗?',
- success: (res) => {
- if (res.confirm) {
- wx.clearStorageSync()
- wx.showToast({
- title: '缓存已清除',
- icon: 'success'
- })
- }
- }
- })
- },
- // 退出登录
- logout() {
- wx.showModal({
- title: '退出登录',
- content: '确定要退出当前账号吗?',
- success: (res) => {
- if (res.confirm) {
- // 清除用户信息和登录状态
- wx.removeStorageSync('userInfo')
- wx.removeStorageSync('token')
-
- // 跳转到登录页
- wx.reLaunch({
- url: '/pages/login/index'
- })
- }
- }
- })
- }
- })
|