index.vue 8.0 KB

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