index.vue 3.3 KB

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