index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="settings-page">
  3. <nav-bar title="设置"></nav-bar>
  4. <view class="menu-list">
  5. <view class="cell-group">
  6. <view class="cell-item" @click="goTo('/pages/my/settings/profile/index')">
  7. <text class="cell-title">个人信息</text>
  8. <text class="arrow">›</text>
  9. </view>
  10. <view class="cell-item" @click="goTo('/pages/my/settings/change-password/index')">
  11. <text class="cell-title">修改密码</text>
  12. <text class="arrow">›</text>
  13. </view>
  14. <view class="cell-item" @click="onClearCache">
  15. <text class="cell-title">清除缓存</text>
  16. <text class="cell-value">{{ cacheSize }}</text>
  17. <text class="arrow">›</text>
  18. </view>
  19. <view class="cell-item">
  20. <text class="cell-title">版本号</text>
  21. <text class="cell-value">v{{ appVersion }}</text>
  22. </view>
  23. </view>
  24. <view class="cell-group danger-group">
  25. <view class="cell-item" @click="goTo('/pages/my/settings/account-delete/index')">
  26. <text class="cell-title danger">账号注销</text>
  27. <text class="arrow">›</text>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="logout-btn-wrapper">
  32. <button class="logout-btn" @click="onLogout">退出登录</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script setup>
  37. import { ref } from 'vue'
  38. import { onShow } from '@dcloudio/uni-app'
  39. import navBar from '@/components/nav-bar/index.vue'
  40. const cacheSize = ref('0 KB')
  41. const appVersion = ref('1.0.0')
  42. // #ifdef APP-PLUS
  43. plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
  44. appVersion.value = widgetInfo.version || '1.0.0'
  45. })
  46. // #endif
  47. // #ifndef APP-PLUS
  48. const systemInfo = uni.getSystemInfoSync()
  49. appVersion.value = systemInfo.appVersion || '1.0.0'
  50. // #endif
  51. const calculateCacheSize = () => {
  52. try {
  53. const res = uni.getStorageInfoSync()
  54. const size = res.currentSize
  55. if (size < 1024) {
  56. cacheSize.value = size + ' KB'
  57. } else {
  58. cacheSize.value = (size / 1024).toFixed(2) + ' MB'
  59. }
  60. } catch (e) {
  61. cacheSize.value = '0 KB'
  62. }
  63. }
  64. onShow(() => {
  65. calculateCacheSize()
  66. })
  67. const goTo = (url) => uni.navigateTo({ url })
  68. const onTodo = () => uni.showToast({ title: '演示功能,暂未开放', icon: 'none' })
  69. const onClearCache = () => {
  70. uni.showModal({
  71. title: '清理缓存',
  72. content: '确定要清理本地缓存吗?',
  73. success: (res) => {
  74. if (res.confirm) {
  75. try {
  76. // 清理前保留 token 等可能需要的核心认证信息
  77. const token = uni.getStorageSync('token')
  78. uni.clearStorageSync()
  79. if (token) {
  80. uni.setStorageSync('token', token)
  81. }
  82. calculateCacheSize()
  83. uni.showToast({ title: '清理成功', icon: 'success' })
  84. } catch (e) {
  85. uni.showToast({ title: '清理失败', icon: 'none' })
  86. }
  87. }
  88. }
  89. })
  90. }
  91. const onLogout = () => {
  92. uni.showModal({
  93. title: '提示',
  94. content: '确定要退出当前账号吗?',
  95. success: (res) => {
  96. if (res.confirm) {
  97. // 清空 token
  98. uni.removeStorageSync('token')
  99. uni.showToast({ title: '已安全退出', icon: 'success' })
  100. setTimeout(() => uni.reLaunch({ url: '/pages/login/index' }), 1000)
  101. }
  102. }
  103. })
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .settings-page {
  108. min-height: 100vh;
  109. background: #f7f8fa;
  110. }
  111. .menu-list {
  112. padding-top: 24rpx;
  113. }
  114. .cell-group {
  115. background: #fff;
  116. margin: 0 24rpx 24rpx;
  117. border-radius: 24rpx;
  118. overflow: hidden;
  119. }
  120. .cell-item {
  121. display: flex;
  122. align-items: center;
  123. padding: 32rpx;
  124. border-bottom: 2rpx solid #eee;
  125. }
  126. .cell-item:last-child {
  127. border-bottom: none;
  128. }
  129. .cell-title {
  130. flex: 1;
  131. font-size: 28rpx;
  132. color: #333;
  133. }
  134. .cell-title.danger {
  135. color: #ee0a24;
  136. }
  137. .cell-value {
  138. font-size: 26rpx;
  139. color: #999;
  140. margin-right: 8rpx;
  141. }
  142. .arrow {
  143. font-size: 36rpx;
  144. color: #ccc;
  145. line-height: 1;
  146. }
  147. .danger-group {
  148. margin-top: 40rpx;
  149. }
  150. .logout-btn-wrapper {
  151. padding: 80rpx 32rpx;
  152. }
  153. .logout-btn {
  154. width: 100%;
  155. height: 88rpx;
  156. background: #fff;
  157. color: #ee0a24;
  158. border: 2rpx solid #ee0a24;
  159. border-radius: 44rpx;
  160. font-size: 30rpx;
  161. font-weight: 500;
  162. line-height: 84rpx;
  163. &::after {
  164. border: none;
  165. }
  166. }
  167. </style>