index.vue 5.7 KB

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