微信小店联盟带货小程序

index.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. Page({
  2. data: {
  3. userInfo: null,
  4. systemSettings: {
  5. // 系统设置
  6. autoUpdate: true,
  7. appVersion: '1.0.0'
  8. }
  9. },
  10. onLoad() {
  11. this.getUserInfo()
  12. this.loadSystemSettings()
  13. },
  14. // 获取用户信息
  15. getUserInfo() {
  16. const userInfo = wx.getStorageSync('userInfo')
  17. if (userInfo) {
  18. this.setData({ userInfo })
  19. }
  20. },
  21. // 加载系统设置
  22. loadSystemSettings() {
  23. const savedSettings = wx.getStorageSync('systemSettings')
  24. if (savedSettings) {
  25. this.setData({
  26. systemSettings: {
  27. ...this.data.systemSettings,
  28. ...savedSettings
  29. }
  30. })
  31. }
  32. },
  33. // 切换自动更新
  34. toggleAutoUpdate() {
  35. const { systemSettings } = this.data
  36. systemSettings.autoUpdate = !systemSettings.autoUpdate
  37. this.setData({ systemSettings })
  38. this.saveSystemSettings()
  39. },
  40. // 保存系统设置
  41. saveSystemSettings() {
  42. wx.setStorageSync('systemSettings', this.data.systemSettings)
  43. wx.showToast({
  44. title: '设置已保存',
  45. icon: 'success'
  46. })
  47. },
  48. // 检查更新
  49. checkUpdate() {
  50. const updateManager = wx.getUpdateManager()
  51. wx.showLoading({ title: '检查更新中' })
  52. updateManager.onCheckForUpdate((res) => {
  53. wx.hideLoading()
  54. if (res.hasUpdate) {
  55. wx.showModal({
  56. title: '更新提示',
  57. content: '检测到新版本,是否立即更新?',
  58. success: (modalRes) => {
  59. if (modalRes.confirm) {
  60. updateManager.onUpdateReady(() => {
  61. wx.showModal({
  62. title: '更新提示',
  63. content: '新版本已准备好,是否重启应用?',
  64. success: (restartRes) => {
  65. if (restartRes.confirm) {
  66. updateManager.applyUpdate()
  67. }
  68. }
  69. })
  70. })
  71. }
  72. }
  73. })
  74. } else {
  75. wx.showToast({
  76. title: '已是最新版本',
  77. icon: 'none'
  78. })
  79. }
  80. })
  81. },
  82. // 清除缓存
  83. clearCache() {
  84. wx.showModal({
  85. title: '清除缓存',
  86. content: '确定要清除所有本地缓存吗?',
  87. success: (res) => {
  88. if (res.confirm) {
  89. wx.clearStorageSync()
  90. wx.showToast({
  91. title: '缓存已清除',
  92. icon: 'success'
  93. })
  94. }
  95. }
  96. })
  97. },
  98. // 退出登录
  99. logout() {
  100. wx.showModal({
  101. title: '退出登录',
  102. content: '确定要退出当前账号吗?',
  103. success: (res) => {
  104. if (res.confirm) {
  105. // 清除用户信息和登录状态
  106. wx.removeStorageSync('userInfo')
  107. wx.removeStorageSync('token')
  108. // 跳转到登录页
  109. wx.reLaunch({
  110. url: '/pages/login/index'
  111. })
  112. }
  113. }
  114. })
  115. }
  116. })