index.vue 3.5 KB

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