index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="settings-container">
  3. <!-- 消息通知设置 -->
  4. <view class="settings-section">
  5. <view class="section-title">消息通知</view>
  6. <view class="settings-list">
  7. <view class="settings-item">
  8. <text>系统通知</text>
  9. <switch :checked="notifications.system" @change="handleSystemNotification" color="#4CAF50" />
  10. </view>
  11. <view class="settings-item">
  12. <text>作物提醒</text>
  13. <switch :checked="notifications.crop" @change="handleCropNotification" color="#4CAF50" />
  14. </view>
  15. <view class="settings-item">
  16. <text>天气预警</text>
  17. <switch :checked="notifications.weather" @change="handleWeatherNotification" color="#4CAF50" />
  18. </view>
  19. </view>
  20. </view>
  21. <!-- 通用设置 -->
  22. <view class="settings-section">
  23. <view class="section-title">通用设置</view>
  24. <view class="settings-list">
  25. <view class="settings-item" @click="handleClearCache">
  26. <view class="item-left">
  27. <text>清除缓存</text>
  28. <text class="sub-text">{{ cacheSize }}</text>
  29. </view>
  30. <text class="arrow">></text>
  31. </view>
  32. <view class="settings-item" @click="checkUpdate">
  33. <view class="item-left">
  34. <text>检查更新</text>
  35. <text class="sub-text">当前版本 {{ version }}</text>
  36. </view>
  37. <text class="arrow">></text>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 关于 -->
  42. <view class="settings-section">
  43. <view class="section-title">关于</view>
  44. <view class="settings-list">
  45. <view class="settings-item" @click="navigateToAboutUs">
  46. <text>关于我们</text>
  47. <text class="arrow">></text>
  48. </view>
  49. <view class="settings-item" @click="navigateToPrivacy">
  50. <text>隐私政策</text>
  51. <text class="arrow">></text>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. data() {
  60. return {
  61. // 通知设置状态
  62. notifications: {
  63. system: true,
  64. crop: true,
  65. weather: true
  66. },
  67. // 缓存大小
  68. cacheSize: '0.00MB',
  69. // 版本号
  70. version: '1.0.0'
  71. };
  72. },
  73. methods: {
  74. // 获取缓存大小
  75. getCacheSize() {
  76. // 实际项目中需要调用相关API获取缓存大小
  77. uni.getStorageInfo({
  78. success: (res) => {
  79. const size = (res.currentSize / 1024).toFixed(2);
  80. this.cacheSize = size + 'MB';
  81. }
  82. });
  83. },
  84. // 清除缓存
  85. handleClearCache() {
  86. uni.showModal({
  87. title: '提示',
  88. content: '确定要清除缓存吗?',
  89. success: (res) => {
  90. if (res.confirm) {
  91. uni.clearStorage({
  92. success: () => {
  93. uni.showToast({
  94. title: '清除成功',
  95. icon: 'success'
  96. });
  97. this.getCacheSize();
  98. }
  99. });
  100. }
  101. }
  102. });
  103. },
  104. // 检查更新
  105. checkUpdate() {
  106. // 实际项目中需要调用后端API检查更新
  107. uni.showLoading({ title: '检查更新中...' });
  108. setTimeout(() => {
  109. uni.hideLoading();
  110. uni.showToast({
  111. title: '已是最新版本',
  112. icon: 'none'
  113. });
  114. }, 1500);
  115. },
  116. // 通知设置处理函数
  117. handleSystemNotification(e) {
  118. this.notifications.system = e.detail.value;
  119. this.saveNotificationSettings();
  120. },
  121. handleCropNotification(e) {
  122. this.notifications.crop = e.detail.value;
  123. this.saveNotificationSettings();
  124. },
  125. handleWeatherNotification(e) {
  126. this.notifications.weather = e.detail.value;
  127. this.saveNotificationSettings();
  128. },
  129. // 保存通知设置
  130. saveNotificationSettings() {
  131. uni.setStorageSync('notifications', this.notifications);
  132. },
  133. // 加载通知设置
  134. loadNotificationSettings() {
  135. const savedSettings = uni.getStorageSync('notifications');
  136. if (savedSettings) {
  137. this.notifications = savedSettings;
  138. }
  139. },
  140. // 页面跳转
  141. navigateToAboutUs() {
  142. uni.navigateTo({ url: '/pages/about/index' });
  143. },
  144. navigateToPrivacy() {
  145. uni.navigateTo({ url: '/pages/privacy/index' });
  146. }
  147. },
  148. // 页面显示时加载数据
  149. onShow() {
  150. this.getCacheSize();
  151. this.loadNotificationSettings();
  152. }
  153. };
  154. </script>
  155. <style lang="scss">
  156. .settings-container {
  157. min-height: 100vh;
  158. background-color: #f5f5f5;
  159. padding: 20rpx;
  160. }
  161. .settings-section {
  162. margin-bottom: 20rpx;
  163. background-color: #ffffff;
  164. border-radius: 16rpx;
  165. overflow: hidden;
  166. }
  167. .section-title {
  168. padding: 20rpx 30rpx;
  169. font-size: 28rpx;
  170. color: #999;
  171. background-color: #f8f8f8;
  172. }
  173. .settings-list {
  174. .settings-item {
  175. display: flex;
  176. justify-content: space-between;
  177. align-items: center;
  178. padding: 30rpx;
  179. border-bottom: 1rpx solid #f0f0f0;
  180. &:last-child {
  181. border-bottom: none;
  182. }
  183. text {
  184. font-size: 28rpx;
  185. color: #333;
  186. }
  187. .item-left {
  188. display: flex;
  189. flex-direction: column;
  190. .sub-text {
  191. font-size: 24rpx;
  192. color: #999;
  193. margin-top: 4rpx;
  194. }
  195. }
  196. .arrow {
  197. color: #999;
  198. font-size: 24rpx;
  199. }
  200. switch {
  201. transform: scale(0.8);
  202. transform-origin: right center;
  203. }
  204. }
  205. }
  206. </style>