Files
mzltMpfqGS e4a087e67e init
2026-04-15 19:45:16 +08:00

148 lines
3.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/settings/settings.js
// 系统设置逻辑处理
const app = getApp()
Page({
data: {
version: '1.0.0',
notificationEnabled: true,
locationEnabled: false,
autoPlayVideo: true,
cacheSize: '0KB'
},
onLoad() {
this.calculateCacheSize()
},
onShow() {
this.checkLoginStatus()
},
// 检查登录状态
checkLoginStatus() {
const userInfo = wx.getStorageSync('userInfo')
this.setData({ hasLogin: !!userInfo })
},
// 计算缓存大小
calculateCacheSize() {
wx.getStorageInfo({
success: res => {
const { currentSize, limitSize } = res
let size = ''
if (currentSize < 1024) {
size = currentSize + 'KB'
} else if (currentSize < 1024 * 1024) {
size = (currentSize / 1024).toFixed(2) + 'MB'
} else {
size = (currentSize / (1024 * 1024)).toFixed(2) + 'GB'
}
this.setData({ cacheSize: size })
}
})
},
// 清除缓存
onClearCache() {
wx.showModal({
title: '提示',
content: '确定要清除缓存吗?',
success: res => {
if (res.confirm) {
wx.showLoading({ title: '清除中...' })
wx.clearStorage({
success: () => {
wx.hideLoading()
wx.showToast({ title: '清除成功', icon: 'success' })
this.setData({ cacheSize: '0KB' })
},
fail: () => {
wx.hideLoading()
wx.showToast({ title: '清除失败', icon: 'none' })
}
})
}
}
})
},
// 切换通知
onNotificationChange(e) {
const enabled = e.detail.value
this.setData({ notificationEnabled: enabled })
if (enabled) {
wx.requestSubscribeMessage({
tmplIds: ['notification_template_id'],
success: () => {},
fail: () => {}
})
}
},
// 切换位置
onLocationChange(e) {
const enabled = e.detail.value
this.setData({ locationEnabled: enabled })
if (enabled) {
wx.getLocation({
type: 'gcj02',
success: () => {},
fail: () => {
wx.showToast({ title: '获取定位失败', icon: 'none' })
}
})
}
},
// 切换自动播放视频
onAutoPlayVideoChange(e) {
this.setData({ autoPlayVideo: e.detail.value })
},
// 用户协议
onUserAgreement() {
wx.navigateTo({
url: '/pages/web-view/web-view?url=https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415/agreement'
})
},
// 隐私政策
onPrivacyPolicy() {
wx.navigateTo({
url: '/pages/web-view/web-view?url=https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415/privacy'
})
},
// 关于我们
onAboutUs() {
wx.navigateTo({
url: '/pages/web-view/web-view?url=https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415/about'
})
},
// 退出登录
onLogout() {
wx.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: res => {
if (res.confirm) {
wx.removeStorageSync('userInfo')
wx.removeStorageSync('token')
wx.reLaunch({ url: '/pages/home/home' })
}
}
})
}
})
/**
* @联系作者16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415查看完整运行演示。
*/