setting.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!-- index.vue -->
  2. <template>
  3. <view class="container">
  4. <!-- 列表区域 -->
  5. <view class="list-item" @click="pwdEdit">
  6. <view>
  7. <uni-icons type="locked-filled" size="20"></uni-icons>
  8. <text>修改密码</text>
  9. </view>
  10. <text>></text>
  11. </view>
  12. <view class="list-item" @click="checkUpdate">
  13. <view>
  14. <uni-icons type="refreshempty" size="20"></uni-icons>
  15. <text>检查更新</text>
  16. </view>
  17. <text>></text>
  18. </view>
  19. <view class="list-item" @click="clearCache">
  20. <view>
  21. <uni-icons type="trash-filled" size="20"></uni-icons>
  22. <text>清理缓存</text>
  23. </view>
  24. <text>></text>
  25. </view>
  26. <!-- 退出登录按钮 -->
  27. <view class="logOut">
  28. <button type="warn" @click="logOut">退出登录</button>
  29. </view>
  30. </view>
  31. </template>
  32. <script setup>
  33. import $tab from "@/plugins/tab.js"
  34. import { getUserInfo } from '@/utils/auth'
  35. import { useUserStore } from '@/store/user.js'
  36. const userStore = useUserStore()
  37. // 退出登录
  38. function logOut() {
  39. uni.showModal({
  40. title: '系统提示',
  41. content: '确定注销并退出系统吗?',
  42. success: function(res) {
  43. if (res.confirm) {
  44. userStore.LogOut()
  45. $tab.reLaunch('/pages/login')
  46. } else if (res.cancel) {
  47. console.log('用户点击取消');
  48. }
  49. }
  50. });
  51. };
  52. // 清理缓存
  53. function clearCache() {
  54. uni.showModal({
  55. title: '系统提示',
  56. content: '是否确定要清理缓存?',
  57. success: function(res) {
  58. if (res.confirm) {
  59. const userInfo = getUserInfo()
  60. uni.clearStorageSync();
  61. uni.setStorageSync('userInfo', userInfo)
  62. userStore.user = userInfo
  63. userStore.useId = userInfo.useId
  64. // 提示用户缓存清理成功
  65. uni.showToast({
  66. title: '缓存清理成功',
  67. icon: 'success',
  68. duration: 2000
  69. });
  70. } else if (res.cancel) {
  71. console.log('用户点击取消');
  72. }
  73. }
  74. });
  75. }
  76. // 修改密码
  77. function pwdEdit() {
  78. $tab.navigateTo('/pages/mine/setting/pwdEdit/pwdEdit');
  79. };
  80. // 检查更新
  81. function checkUpdate() {
  82. const updateManager = uni.getUpdateManager();
  83. updateManager.onCheckForUpdate(function(res) {
  84. // 请求完新版本信息的回调
  85. if (res.hasUpdate) {
  86. updateManager.onUpdateReady(function(res) {
  87. uni.showModal({
  88. title: '更新提示',
  89. content: '新版本已经准备好,是否重启应用?',
  90. success(res) {
  91. if (res.confirm) {
  92. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  93. updateManager.applyUpdate();
  94. }
  95. }
  96. });
  97. });
  98. } else {
  99. uni.showToast({
  100. title: '暂无版本更新',
  101. icon: 'none'
  102. });
  103. }
  104. });
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .container {
  109. padding: 20px;
  110. }
  111. .list-item {
  112. display: flex;
  113. align-items: center;
  114. justify-content: space-between;
  115. font-size: 1rem;
  116. padding: 0.75rem;
  117. background-color: #ffffff;
  118. border-radius: 10rpx;
  119. margin-bottom: 0.75rem;
  120. border-bottom: 1px solid gainsboro;
  121. uni-icons{
  122. margin-right: 6px;
  123. }
  124. }
  125. .logOut{
  126. margin-top: 2rem;
  127. }
  128. </style>