index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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-xxx-xxxx' // 替换为实际的客服电话
  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. this.isLogin = false;
  222. this.userInfo = {
  223. nickname: '游客',
  224. id: '',
  225. avatar: ''
  226. };
  227. this.plotInfo = {
  228. total: 0,
  229. active: 0,
  230. idle: 0
  231. }
  232. })
  233. // #endif
  234. // #ifdef APP-PLUS
  235. logout().then(() => {
  236. this.isLogin = false;
  237. this.userInfo = {
  238. nickname: '游客',
  239. id: '',
  240. avatar: '/static/icons/user_icon'
  241. };
  242. });
  243. // #endif
  244. }
  245. }
  246. })
  247. }
  248. }
  249. }
  250. </script>
  251. <style>
  252. .container {
  253. min-height: 100vh;
  254. background-color: #f5f5f5;
  255. padding: 20rpx;
  256. }
  257. .user-card {
  258. background-color: #4CAF50;
  259. border-radius: 16rpx;
  260. padding: 30rpx;
  261. margin-bottom: 20rpx;
  262. }
  263. .user-header {
  264. display: flex;
  265. align-items: center;
  266. }
  267. .avatar {
  268. width: 120rpx;
  269. height: 120rpx;
  270. border-radius: 60rpx;
  271. /* border: 4rpx solid #fff; */
  272. }
  273. .user-detail {
  274. margin-left: 20rpx;
  275. color: #fff;
  276. }
  277. .nickname {
  278. font-size: 32rpx;
  279. font-weight: bold;
  280. margin-bottom: 10rpx;
  281. display: block;
  282. }
  283. .user-id {
  284. font-size: 24rpx;
  285. opacity: 0.8;
  286. }
  287. .info-card {
  288. background-color: #fff;
  289. border-radius: 16rpx;
  290. padding: 30rpx;
  291. margin-bottom: 20rpx;
  292. }
  293. .card-title {
  294. display: flex;
  295. justify-content: space-between;
  296. align-items: center;
  297. margin-bottom: 30rpx;
  298. font-size: 32rpx;
  299. font-weight: bold;
  300. }
  301. .more {
  302. color: #666;
  303. font-size: 24rpx;
  304. font-weight: normal;
  305. }
  306. .plot-info {
  307. display: flex;
  308. justify-content: space-around;
  309. }
  310. .plot-item {
  311. text-align: center;
  312. }
  313. .number {
  314. font-size: 36rpx;
  315. font-weight: bold;
  316. color: #4CAF50;
  317. display: block;
  318. }
  319. .label {
  320. font-size: 24rpx;
  321. color: #666;
  322. margin-top: 10rpx;
  323. display: block;
  324. }
  325. .service-grid {
  326. display: grid;
  327. grid-template-columns: repeat(4, 1fr);
  328. gap: 30rpx;
  329. padding: 10rpx 0;
  330. }
  331. .service-item {
  332. display: flex;
  333. flex-direction: column;
  334. align-items: center;
  335. }
  336. .service-icon {
  337. width: 88rpx;
  338. height: 88rpx;
  339. background-color: #E8F5E9;
  340. border-radius: 16rpx;
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. margin-bottom: 16rpx;
  345. }
  346. .service-icon text {
  347. font-size: 32rpx;
  348. color: #4CAF50;
  349. font-weight: bold;
  350. }
  351. .icon-svg {
  352. width: 48rpx;
  353. height: 48rpx;
  354. display: block;
  355. }
  356. .service-name {
  357. font-size: 28rpx;
  358. color: #666;
  359. text-align: center;
  360. }
  361. .function-list {
  362. width: 100%;
  363. }
  364. .function-item {
  365. display: flex;
  366. justify-content: space-between;
  367. align-items: center;
  368. padding: 30rpx 0;
  369. border-bottom: 1rpx solid #f5f5f5;
  370. }
  371. .function-item:last-child {
  372. border-bottom: none;
  373. }
  374. .function-item .left {
  375. display: flex;
  376. align-items: center;
  377. }
  378. .function-icon {
  379. width: 44rpx;
  380. height: 44rpx;
  381. background-color: #E8F5E9;
  382. color: #4CAF50;
  383. font-size: 28rpx;
  384. font-weight: bold;
  385. border-radius: 8rpx;
  386. display: flex;
  387. align-items: center;
  388. justify-content: center;
  389. margin-right: 20rpx;
  390. }
  391. .function-item text {
  392. font-size: 28rpx;
  393. color: #333;
  394. }
  395. .arrow {
  396. color: #999;
  397. font-size: 24rpx;
  398. }
  399. .login-text {
  400. font-size: 32rpx;
  401. font-weight: bold;
  402. color: #fff;
  403. background-color: rgba(255, 255, 255, 0.2);
  404. padding: 10rpx 30rpx;
  405. border-radius: 30rpx;
  406. }
  407. </style>