index.vue 5.5 KB

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