index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <view class="container">
  3. <!-- 用户信息卡片 -->
  4. <view class="user-card">
  5. <view class="user-header">
  6. <image class="avatar" :src="userInfo.avatar || '/static/icons/user_icon.png'"></image>
  7. <view class="user-detail" v-if="isLogin">
  8. <text class="nickname">{{userInfo.nickName}}</text>
  9. <!-- <text class="user-id">性别: {{userInfo.sex == '0' ? '男' :'女' || '未知'}}</text> -->
  10. </view>
  11. <view class="user-detail" v-else>
  12. <text class="login-text" @click="navigateToLogin">登录/注册</text>
  13. </view>
  14. </view>
  15. </view>
  16. <!-- 地块信息 -->
  17. <view class="info-card">
  18. <view class="card-title">
  19. <text>我的地块</text>
  20. <text class="more" @click="navigateToPlots">查看更多 ></text>
  21. </view>
  22. <view class="plot-info">
  23. <view class="plot-item">
  24. <text class="number">{{ plotInfo.total }}</text>
  25. <text class="label">总地块数</text>
  26. </view>
  27. <view class="plot-item">
  28. <text class="number">{{ plotInfo.active }}</text>
  29. <text class="label">种植中</text>
  30. </view>
  31. <view class="plot-item">
  32. <text class="number">{{ plotInfo.idle }}</text>
  33. <text class="label">空闲</text>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 农业服务 -->
  38. <view class="info-card">
  39. <view class="card-title">
  40. <text>农业服务</text>
  41. </view>
  42. <view class="service-grid">
  43. <view
  44. class="service-item"
  45. v-for="(item, index) in serviceList"
  46. :key="index"
  47. @click="navigateToService(item)"
  48. >
  49. <view class="service-icon">
  50. <image v-if="item.iconSvg" class="icon-svg" :src="item.iconSvg"></image>
  51. <text v-else>{{ item.iconText }}</text>
  52. </view>
  53. <text class="service-name">{{ item.name }}</text>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 常用功能 -->
  58. <view class="info-card">
  59. <view class="function-list">
  60. <view class="function-item" @click="handleContact">
  61. <view class="left">
  62. <text>联系客服</text>
  63. </view>
  64. <text class="arrow">></text>
  65. </view>
  66. <view class="function-item" @click="navigateToSettings">
  67. <view class="left">
  68. <text>系统设置</text>
  69. </view>
  70. <text class="arrow">></text>
  71. </view>
  72. <view v-if="isLogin" class="function-item" @click="handleLogout">
  73. <view class="left">
  74. <!-- <text class="function-icon">退</text> -->
  75. <text>退出登录</text>
  76. </view>
  77. <text class="arrow">></text>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. import {
  85. logout, webLogout
  86. } from '@/api/services/connect.js';
  87. import {
  88. countUserPlots
  89. } from '@/api/services/field.js';
  90. import storage from "@/utils/storage.js";
  91. export default {
  92. data() {
  93. return {
  94. plotInfo: {
  95. total: 0,
  96. active: 0,
  97. idle: 0
  98. },
  99. serviceList: [
  100. {
  101. name: '农资商城',
  102. iconText: '商',
  103. iconSvg: '/static/icons/mall.png',
  104. path: '/pages/service/mall'
  105. },
  106. {
  107. name: '农品交易',
  108. iconText: '售',
  109. iconSvg: '/static/icons/sales.png',
  110. path: '/pages/service/sales'
  111. },
  112. {
  113. name: '专家咨询',
  114. iconText: '诊',
  115. iconSvg: '/static/icons/expert.png',
  116. path: '/pages/service/expert'
  117. },
  118. {
  119. name: '绿色认证',
  120. iconText: '证',
  121. iconSvg: '/static/icons/certification.png',
  122. path: '/pages/service/certification'
  123. },
  124. {
  125. name: '保险接入',
  126. iconText: '保',
  127. iconSvg: '/static/icons/insurance.png',
  128. path: '/pages/service/insurance'
  129. }
  130. ],
  131. userInfo: {
  132. nickName: '',
  133. id: '',
  134. avatar: '',
  135. sex:''
  136. },
  137. isLogin: false
  138. }
  139. },
  140. onShow() {
  141. this.checkLoginStatus();
  142. if(this.isLogin){
  143. this.userPlots();
  144. }
  145. },
  146. methods: {
  147. userPlots(){
  148. countUserPlots().then((res=>{
  149. if (res.data.code == 200) {
  150. const {plotsTotal,inUseCount,leiSureCount} = res.data.data
  151. this.plotInfo = {
  152. total: plotsTotal,
  153. active: inUseCount,
  154. idle: leiSureCount
  155. }
  156. } else{
  157. console.error("统计地块数量失败!")
  158. }
  159. }))
  160. },
  161. // 检查登录状态
  162. checkLoginStatus() {
  163. console.log("执行Show");
  164. if (storage.getHasLogin()) {
  165. this.isLogin = true;
  166. // 获取用户信息
  167. const userInfo = storage.getUserInfo();
  168. console.log("执行Show",userInfo);
  169. if (userInfo) {
  170. this.userInfo = {
  171. nickName: userInfo.username || '游客',
  172. avatar: userInfo.avatar || '/static/icons/user_icon.png',
  173. sex:userInfo.sex
  174. };
  175. }
  176. } else {
  177. this.isLogin = false;
  178. }
  179. },
  180. navigateToLogin() {
  181. uni.navigateTo({
  182. url: '/pages/login/index'
  183. });
  184. },
  185. navigateToPlots() {
  186. uni.navigateTo({
  187. url: '/pages/plots/list'
  188. })
  189. },
  190. navigateToService(item) {
  191. uni.navigateTo({ url: item.path })
  192. },
  193. handleContact() {
  194. uni.makePhoneCall({
  195. phoneNumber: '400-888-8888' // 替换为实际的客服电话
  196. })
  197. },
  198. navigateToAbout() {
  199. uni.navigateTo({
  200. url: '/pages/about/index'
  201. })
  202. },
  203. navigateToSettings() {
  204. uni.navigateTo({
  205. url: '/pages/settings/index'
  206. })
  207. },
  208. // 使用授权服务处理登出
  209. handleLogout() {
  210. uni.showModal({
  211. title: '提示',
  212. content: '确认退出登录?',
  213. success: (res) => {
  214. if (res.confirm) {
  215. // #ifdef H5
  216. webLogout().then(res=>{
  217. console.log("tuichu",res);
  218. storage.setAccessToken("");
  219. storage.setUserInfo({});
  220. storage.setHasLogin(false)
  221. storage.removeCurrentPlot()
  222. storage.removeUserPlots()
  223. this.isLogin = false;
  224. this.userInfo = {
  225. nickname: '游客',
  226. id: '',
  227. avatar: ''
  228. };
  229. this.plotInfo = {
  230. total: 0,
  231. active: 0,
  232. idle: 0
  233. }
  234. })
  235. // #endif
  236. // #ifdef APP-PLUS
  237. logout().then(() => {
  238. this.isLogin = false;
  239. this.userInfo = {
  240. nickname: '游客',
  241. id: '',
  242. avatar: '/static/icons/user_icon'
  243. };
  244. });
  245. // #endif
  246. }
  247. }
  248. })
  249. }
  250. }
  251. }
  252. </script>
  253. <style>
  254. .container {
  255. min-height: 100vh;
  256. background-color: #f5f5f5;
  257. padding: 20rpx;
  258. }
  259. .user-card {
  260. background-color: #4CAF50;
  261. border-radius: 16rpx;
  262. padding: 30rpx;
  263. margin-bottom: 20rpx;
  264. }
  265. .user-header {
  266. display: flex;
  267. align-items: center;
  268. }
  269. .avatar {
  270. width: 120rpx;
  271. height: 120rpx;
  272. border-radius: 60rpx;
  273. /* border: 4rpx solid #fff; */
  274. }
  275. .user-detail {
  276. margin-left: 20rpx;
  277. color: #fff;
  278. }
  279. .nickname {
  280. font-size: 32rpx;
  281. font-weight: bold;
  282. margin-bottom: 10rpx;
  283. display: block;
  284. }
  285. .user-id {
  286. font-size: 24rpx;
  287. opacity: 0.8;
  288. }
  289. .info-card {
  290. background-color: #fff;
  291. border-radius: 16rpx;
  292. padding: 30rpx;
  293. margin-bottom: 20rpx;
  294. }
  295. .card-title {
  296. display: flex;
  297. justify-content: space-between;
  298. align-items: center;
  299. margin-bottom: 30rpx;
  300. font-size: 32rpx;
  301. font-weight: bold;
  302. }
  303. .more {
  304. color: #666;
  305. font-size: 24rpx;
  306. font-weight: normal;
  307. }
  308. .plot-info {
  309. display: flex;
  310. justify-content: space-around;
  311. }
  312. .plot-item {
  313. text-align: center;
  314. }
  315. .number {
  316. font-size: 36rpx;
  317. font-weight: bold;
  318. color: #4CAF50;
  319. display: block;
  320. }
  321. .label {
  322. font-size: 24rpx;
  323. color: #666;
  324. margin-top: 10rpx;
  325. display: block;
  326. }
  327. .service-grid {
  328. display: grid;
  329. grid-template-columns: repeat(4, 1fr);
  330. gap: 30rpx;
  331. padding: 10rpx 0;
  332. }
  333. .service-item {
  334. display: flex;
  335. flex-direction: column;
  336. align-items: center;
  337. }
  338. .service-icon {
  339. width: 88rpx;
  340. height: 88rpx;
  341. background-color: #E8F5E9;
  342. border-radius: 16rpx;
  343. display: flex;
  344. align-items: center;
  345. justify-content: center;
  346. margin-bottom: 16rpx;
  347. }
  348. .service-icon text {
  349. font-size: 32rpx;
  350. color: #4CAF50;
  351. font-weight: bold;
  352. }
  353. .icon-svg {
  354. width: 48rpx;
  355. height: 48rpx;
  356. display: block;
  357. }
  358. .service-name {
  359. font-size: 28rpx;
  360. color: #666;
  361. text-align: center;
  362. }
  363. .function-list {
  364. width: 100%;
  365. }
  366. .function-item {
  367. display: flex;
  368. justify-content: space-between;
  369. align-items: center;
  370. padding: 30rpx 0;
  371. border-bottom: 1rpx solid #f5f5f5;
  372. }
  373. .function-item:last-child {
  374. border-bottom: none;
  375. }
  376. .function-item .left {
  377. display: flex;
  378. align-items: center;
  379. }
  380. .function-icon {
  381. width: 44rpx;
  382. height: 44rpx;
  383. background-color: #E8F5E9;
  384. color: #4CAF50;
  385. font-size: 28rpx;
  386. font-weight: bold;
  387. border-radius: 8rpx;
  388. display: flex;
  389. align-items: center;
  390. justify-content: center;
  391. margin-right: 20rpx;
  392. }
  393. .function-item text {
  394. font-size: 28rpx;
  395. color: #333;
  396. }
  397. .arrow {
  398. color: #999;
  399. font-size: 24rpx;
  400. }
  401. .login-text {
  402. font-size: 32rpx;
  403. font-weight: bold;
  404. color: #fff;
  405. background-color: rgba(255, 255, 255, 0.2);
  406. padding: 10rpx 30rpx;
  407. border-radius: 30rpx;
  408. }
  409. </style>