index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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 class="service-item" v-for="(item, index) in serviceList" :key="index"
  44. @click="navigateToService(item)">
  45. <view class="service-icon">
  46. <text>{{ item.iconText }}</text>
  47. </view>
  48. <text class="service-name">{{ item.name }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 常用功能 -->
  53. <view class="info-card">
  54. <view class="function-list">
  55. <view class="function-item" @click="handleContact">
  56. <view class="left">
  57. <text class="function-icon">客</text>
  58. <text>联系客服</text>
  59. </view>
  60. <text class="arrow">></text>
  61. </view>
  62. <view class="function-item" @click="navigateToAbout">
  63. <view class="left">
  64. <text class="function-icon">关</text>
  65. <text>关于我们</text>
  66. </view>
  67. <text class="arrow">></text>
  68. </view>
  69. <view class="function-item" @click="navigateToSettings">
  70. <view class="left">
  71. <text class="function-icon">设</text>
  72. <text>系统设置</text>
  73. </view>
  74. <text class="arrow">></text>
  75. </view>
  76. <view v-if="isLogin" class="function-item" @click="handleLogout">
  77. <view class="left">
  78. <text class="function-icon">退</text>
  79. <text>退出登录</text>
  80. </view>
  81. <text class="arrow">></text>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. import {
  89. logout, webLogout
  90. } from '@/api/services/connect.js';
  91. import {
  92. countUserPlots
  93. } from '@/api/services/field.js';
  94. import storage from "@/utils/storage.js";
  95. export default {
  96. data() {
  97. return {
  98. plotInfo: {
  99. total: 0,
  100. active: 0,
  101. idle: 0
  102. },
  103. serviceList: [{
  104. name: '农资商城',
  105. iconText: '商',
  106. path: '/pages/service/mall'
  107. },
  108. {
  109. name: '农产品销售',
  110. iconText: '售',
  111. path: '/pages/service/sales'
  112. },
  113. {
  114. name: '在线专家问诊',
  115. iconText: '诊',
  116. path: '/pages/service/expert'
  117. },
  118. {
  119. name: '绿色认证申请',
  120. iconText: '证',
  121. path: '/pages/service/certification'
  122. },
  123. {
  124. name: '保险接入',
  125. iconText: '保',
  126. path: '/pages/service/insurance'
  127. }
  128. ],
  129. userInfo: {
  130. nickName: '',
  131. id: '',
  132. avatar: '',
  133. sex:''
  134. },
  135. isLogin: false
  136. }
  137. },
  138. onShow() {
  139. this.checkLoginStatus();
  140. if(this.isLogin){
  141. this.userPlots();
  142. }
  143. },
  144. methods: {
  145. userPlots(){
  146. countUserPlots().then((res=>{
  147. if (res.data.code == 200) {
  148. const {plotsTotal,inUseCount,leiSureCount} = res.data.data
  149. this.plotInfo = {
  150. total: plotsTotal,
  151. active: inUseCount,
  152. idle: leiSureCount
  153. }
  154. } else{
  155. console.error("统计地块数量失败!")
  156. }
  157. }))
  158. },
  159. // 检查登录状态
  160. checkLoginStatus() {
  161. console.log("执行Show");
  162. if (storage.getHasLogin()) {
  163. this.isLogin = true;
  164. // 获取用户信息
  165. const userInfo = storage.getUserInfo();
  166. console.log("执行Show",userInfo);
  167. if (userInfo) {
  168. this.userInfo = {
  169. nickName: userInfo.username || '游客',
  170. avatar: userInfo.avatar || '/static/icons/user_icon.png',
  171. sex:userInfo.sex
  172. };
  173. }
  174. } else {
  175. this.isLogin = false;
  176. }
  177. },
  178. navigateToLogin() {
  179. uni.navigateTo({
  180. url: '/pages/login/index'
  181. });
  182. },
  183. navigateToPlots() {
  184. uni.navigateTo({
  185. url: '/pages/plots/list'
  186. })
  187. },
  188. navigateToService(item) {
  189. uni.navigateTo({
  190. url: item.path
  191. })
  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. .service-name {
  352. font-size: 28rpx;
  353. color: #666;
  354. text-align: center;
  355. }
  356. .function-list {
  357. width: 100%;
  358. }
  359. .function-item {
  360. display: flex;
  361. justify-content: space-between;
  362. align-items: center;
  363. padding: 30rpx 0;
  364. border-bottom: 1rpx solid #f5f5f5;
  365. }
  366. .function-item:last-child {
  367. border-bottom: none;
  368. }
  369. .function-item .left {
  370. display: flex;
  371. align-items: center;
  372. }
  373. .function-icon {
  374. width: 44rpx;
  375. height: 44rpx;
  376. background-color: #E8F5E9;
  377. color: #4CAF50;
  378. font-size: 28rpx;
  379. font-weight: bold;
  380. border-radius: 8rpx;
  381. display: flex;
  382. align-items: center;
  383. justify-content: center;
  384. margin-right: 20rpx;
  385. }
  386. .function-item text {
  387. font-size: 28rpx;
  388. color: #333;
  389. }
  390. .arrow {
  391. color: #999;
  392. font-size: 24rpx;
  393. }
  394. .login-text {
  395. font-size: 32rpx;
  396. font-weight: bold;
  397. color: #fff;
  398. background-color: rgba(255, 255, 255, 0.2);
  399. padding: 10rpx 30rpx;
  400. border-radius: 30rpx;
  401. }
  402. </style>