index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="container">
  3. <!-- 自定义头部 -->
  4. <view class="custom-header">
  5. <view class="header-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);"></image>
  7. </view>
  8. <text class="header-title">设置</text>
  9. <view class="header-right"></view>
  10. </view>
  11. <view class="header-placeholder"></view>
  12. <!-- 个人信息组 -->
  13. <view class="group-card">
  14. <view class="list-item" @click="navTo('profile')">
  15. <text class="item-title">个人资料</text>
  16. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  17. </view>
  18. <view class="list-item" @click="navTo('auth')">
  19. <text class="item-title">认证信息</text>
  20. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  21. </view>
  22. <!-- <view class="list-item" @click="navTo('bank')">
  23. <text class="item-title">银行卡信息</text>
  24. <view class="item-right">
  25. <view class="tag-status">已完善</view>
  26. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  27. </view>
  28. </view> -->
  29. <view class="list-item no-border" @click="navTo('security')">
  30. <text class="item-title">账号与安全</text>
  31. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  32. </view>
  33. </view>
  34. <!-- 应用设置组 -->
  35. <view class="group-card">
  36. <!-- <view class="list-item" @click="navTo('push')">
  37. <text class="item-title">推送通知</text>
  38. <view class="item-right">
  39. <text class="item-value">部分开启</text>
  40. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  41. </view>
  42. </view> -->
  43. <view class="list-item">
  44. <view class="item-row-left">
  45. <text class="item-title">位置上报</text>
  46. <text class="item-subtitle">每隔20分钟自动上报位置</text>
  47. </view>
  48. <switch :checked="isGpsEnabled" color="#FF5722" style="transform:scale(0.8)" @change="onGpsSwitchChange"/>
  49. </view>
  50. <view class="list-item" @click="clearCache">
  51. <text class="item-title">清理缓存</text>
  52. <view class="item-right">
  53. <text class="item-value">{{ cacheSize }}</text>
  54. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  55. </view>
  56. </view>
  57. <view class="list-item no-border" @click="navTo('about')">
  58. <text class="item-title">关于我们</text>
  59. <view class="item-right">
  60. <text class="item-value">v{{ version }}</text>
  61. <image class="arrow-icon" src="/static/icons/chevron_right.svg"></image>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import { startGpsTimer, stopGpsTimer } from '@/utils/gps'
  69. export default {
  70. data() {
  71. return {
  72. version: '2.0.6',
  73. cacheSize: '0B',
  74. // 明确默认状态为开启:获取不到缓存即为 true,以此确保默认值为开启。
  75. isGpsEnabled: uni.getStorageSync('GPS_REPORT_ENABLED') !== false
  76. }
  77. },
  78. onLoad() {
  79. this.getAppVersion();
  80. this.getCacheSize();
  81. },
  82. methods: {
  83. navBack() {
  84. uni.navigateBack({
  85. delta: 1
  86. });
  87. },
  88. navTo(type) {
  89. let url = '';
  90. switch(type) {
  91. case 'profile':
  92. url = '/pages/mine/settings/profile/index';
  93. break;
  94. case 'auth':
  95. url = '/pages/mine/settings/auth/index';
  96. break;
  97. case 'bank':
  98. url = '/pages/mine/settings/bank/index';
  99. break;
  100. case 'security':
  101. url = '/pages/mine/settings/security/index';
  102. break;
  103. case 'push':
  104. url = '/pages/mine/settings/notification/index';
  105. break;
  106. case 'about':
  107. url = '/pages/mine/settings/about/index';
  108. break;
  109. default:
  110. console.log('Navigate to:', type);
  111. return;
  112. }
  113. uni.navigateTo({ url });
  114. },
  115. clearCache() {
  116. uni.showModal({
  117. title: '清理缓存',
  118. content: '确定要清理应用缓存吗?',
  119. success: (res) => {
  120. if (res.confirm) {
  121. try {
  122. // 排除 token 等关键数据的清理方案,取决于实际需求。通常清除所有 Storage
  123. // 为了安全起见只同步清理所有,或者根据业务决定
  124. const token = uni.getStorageSync('Authorization_token') // 假设 token 名
  125. const gpsToggle = uni.getStorageSync('GPS_REPORT_ENABLED')
  126. uni.clearStorageSync();
  127. // 恢复关键数据以便不用退出重新登录
  128. if (token) uni.setStorageSync('Authorization_token', token)
  129. uni.setStorageSync('GPS_REPORT_ENABLED', gpsToggle)
  130. uni.showToast({ title: '清理完成', icon: 'success' });
  131. this.getCacheSize();
  132. } catch (err) {
  133. console.error('清理缓存失败:', err);
  134. uni.showToast({ title: err.message || err.msg || '请求失败', icon: 'none' });
  135. }
  136. }
  137. }
  138. });
  139. },
  140. getCacheSize() {
  141. try {
  142. const res = uni.getStorageInfoSync();
  143. const kb = res.currentSize;
  144. if (kb < 1024) {
  145. this.cacheSize = kb + 'KB';
  146. } else {
  147. this.cacheSize = (kb / 1024).toFixed(2) + 'MB';
  148. }
  149. } catch (err) {
  150. this.cacheSize = '0B';
  151. }
  152. },
  153. getAppVersion() {
  154. // #ifdef APP-PLUS
  155. plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
  156. this.version = widgetInfo.version || '2.0.6';
  157. });
  158. // #endif
  159. // #ifndef APP-PLUS
  160. const systemInfo = uni.getSystemInfoSync();
  161. this.version = systemInfo.appVersion || '2.0.6';
  162. // #endif
  163. },
  164. onGpsSwitchChange(e) {
  165. const val = e.detail.value;
  166. this.isGpsEnabled = val;
  167. uni.setStorageSync('GPS_REPORT_ENABLED', val);
  168. if (val) {
  169. startGpsTimer();
  170. } else {
  171. stopGpsTimer();
  172. }
  173. }
  174. }
  175. }
  176. </script>
  177. <style>
  178. page {
  179. background-color: #F8F8F8;
  180. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  181. }
  182. .custom-header {
  183. position: fixed;
  184. top: 0;
  185. left: 0;
  186. width: 100%;
  187. height: 88rpx;
  188. padding-top: var(--status-bar-height);
  189. background-color: #fff;
  190. display: flex;
  191. align-items: center;
  192. justify-content: space-between;
  193. padding-left: 30rpx;
  194. padding-right: 30rpx;
  195. box-sizing: content-box; /* Exclude padding from height calculation if needed, or adjust */
  196. z-index: 100;
  197. }
  198. .header-placeholder {
  199. height: calc(88rpx + var(--status-bar-height));
  200. }
  201. .back-icon {
  202. width: 40rpx;
  203. height: 40rpx;
  204. }
  205. .header-title {
  206. font-size: 28rpx; /* 14pt */
  207. font-weight: bold;
  208. color: #333;
  209. }
  210. .header-right {
  211. width: 40rpx;
  212. }
  213. .container {
  214. padding: 20rpx 30rpx;
  215. }
  216. .group-card {
  217. background-color: #fff;
  218. border-radius: 20rpx;
  219. padding: 0 30rpx;
  220. margin-bottom: 30rpx;
  221. }
  222. .list-item {
  223. display: flex;
  224. justify-content: space-between;
  225. align-items: center;
  226. height: 100rpx;
  227. border-bottom: 1px solid #F5F5F5;
  228. }
  229. .list-item.no-border {
  230. border-bottom: none;
  231. }
  232. .item-title {
  233. font-size: 28rpx; /* 14pt */
  234. color: #333;
  235. }
  236. .item-right {
  237. display: flex;
  238. align-items: center;
  239. }
  240. .arrow-icon {
  241. width: 28rpx;
  242. height: 28rpx;
  243. opacity: 0.5;
  244. margin-left: 10rpx;
  245. }
  246. .tag-status {
  247. font-size: 22rpx;
  248. color: #4CAF50;
  249. background-color: #F1F8E9;
  250. padding: 4rpx 10rpx;
  251. border-radius: 6rpx;
  252. margin-right: 6rpx;
  253. }
  254. .item-value {
  255. font-size: 28rpx; /* Changed to 14pt (28rpx) */
  256. color: #999;
  257. }
  258. .item-column {
  259. display: flex;
  260. flex-direction: column;
  261. }
  262. .item-row-left {
  263. display: flex;
  264. align-items: center;
  265. }
  266. .item-subtitle {
  267. font-size: 24rpx; /* Changed to 12pt (24rpx) for better legibility */
  268. color: #999;
  269. margin-left: 20rpx; /* Moved to right of title */
  270. margin-top: 0;
  271. }
  272. </style>