index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 setup>
  62. import { ref } from 'vue'
  63. import { onShow } from '@dcloudio/uni-app'
  64. // 通知设置状态
  65. const notifications = ref({
  66. system: true,
  67. crop: true,
  68. weather: true
  69. })
  70. // 缓存大小
  71. const cacheSize = ref('0.00MB')
  72. // 版本号
  73. const version = ref('1.0.0')
  74. // 获取缓存大小
  75. const getCacheSize = () => {
  76. // 实际项目中需要调用相关API获取缓存大小
  77. uni.getStorageInfo({
  78. success: (res) => {
  79. const size = (res.currentSize / 1024).toFixed(2)
  80. cacheSize.value = size + 'MB'
  81. }
  82. })
  83. }
  84. // 清除缓存
  85. const 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. getCacheSize()
  98. }
  99. })
  100. }
  101. }
  102. })
  103. }
  104. // 检查更新
  105. const 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. const handleSystemNotification = (e) => {
  118. notifications.value.system = e.detail.value
  119. saveNotificationSettings()
  120. }
  121. const handleCropNotification = (e) => {
  122. notifications.value.crop = e.detail.value
  123. saveNotificationSettings()
  124. }
  125. const handleWeatherNotification = (e) => {
  126. notifications.value.weather = e.detail.value
  127. saveNotificationSettings()
  128. }
  129. // 保存通知设置
  130. const saveNotificationSettings = () => {
  131. uni.setStorageSync('notifications', notifications.value)
  132. }
  133. // 加载通知设置
  134. const loadNotificationSettings = () => {
  135. const savedSettings = uni.getStorageSync('notifications')
  136. if (savedSettings) {
  137. notifications.value = savedSettings
  138. }
  139. }
  140. // 页面跳转
  141. const navigateToAboutUs = () => {
  142. uni.navigateTo({ url: '/pages/about/index' })
  143. }
  144. const navigateToPrivacy = () => {
  145. uni.navigateTo({ url: '/pages/privacy/index' })
  146. }
  147. const handleContact = () => {
  148. uni.makePhoneCall({
  149. phoneNumber: '400-xxx-xxxx' // 替换为实际的客服电话
  150. })
  151. }
  152. // 页面显示时加载数据
  153. onShow(() => {
  154. getCacheSize()
  155. loadNotificationSettings()
  156. })
  157. </script>
  158. <style lang="scss">
  159. .settings-container {
  160. min-height: 100vh;
  161. background-color: #f5f5f5;
  162. padding: 20rpx;
  163. }
  164. .settings-section {
  165. margin-bottom: 20rpx;
  166. background-color: #ffffff;
  167. border-radius: 16rpx;
  168. overflow: hidden;
  169. }
  170. .section-title {
  171. padding: 20rpx 30rpx;
  172. font-size: 28rpx;
  173. color: #999;
  174. background-color: #f8f8f8;
  175. }
  176. .settings-list {
  177. .settings-item {
  178. display: flex;
  179. justify-content: space-between;
  180. align-items: center;
  181. padding: 30rpx;
  182. border-bottom: 1rpx solid #f0f0f0;
  183. &:last-child {
  184. border-bottom: none;
  185. }
  186. text {
  187. font-size: 28rpx;
  188. color: #333;
  189. }
  190. .item-left {
  191. display: flex;
  192. flex-direction: column;
  193. .sub-text {
  194. font-size: 24rpx;
  195. color: #999;
  196. margin-top: 4rpx;
  197. }
  198. }
  199. .arrow {
  200. color: #999;
  201. font-size: 24rpx;
  202. }
  203. switch {
  204. transform: scale(0.8);
  205. transform-origin: right center;
  206. }
  207. }
  208. }
  209. </style>