index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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/images/default-avatar.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="this.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 storage from "@/utils/storage.js";
  92. export default {
  93. data() {
  94. return {
  95. plotInfo: {
  96. total: 3,
  97. active: 2,
  98. idle: 1
  99. },
  100. serviceList: [{
  101. name: '农资商城',
  102. iconText: '商',
  103. path: '/pages/service/mall'
  104. },
  105. {
  106. name: '农产品销售',
  107. iconText: '售',
  108. path: '/pages/service/sales'
  109. },
  110. {
  111. name: '在线专家问诊',
  112. iconText: '诊',
  113. path: '/pages/service/expert'
  114. },
  115. {
  116. name: '绿色认证申请',
  117. iconText: '证',
  118. path: '/pages/service/certification'
  119. },
  120. {
  121. name: '保险接入',
  122. iconText: '保',
  123. path: '/pages/service/insurance'
  124. }
  125. ],
  126. userInfo: {
  127. nickName: '游客',
  128. id: '',
  129. avatar: '/static/images/icon.png'
  130. },
  131. isLogin: false
  132. }
  133. },
  134. onShow() {
  135. this.checkLoginStatus();
  136. },
  137. methods: {
  138. // 检查登录状态
  139. checkLoginStatus() {
  140. console.log("执行Show");
  141. if (storage.getHasLogin()) {
  142. this.isLogin = true;
  143. // 获取用户信息
  144. const userInfo = storage.getUserInfo();
  145. console.log("执行Show",userInfo);
  146. if (userInfo) {
  147. this.userInfo = userInfo;
  148. }
  149. } else {
  150. this.isLogin = false;
  151. }
  152. },
  153. navigateToLogin() {
  154. uni.navigateTo({
  155. url: '/pages/login/index'
  156. });
  157. },
  158. navigateToPlots() {
  159. uni.navigateTo({
  160. url: '/pages/plots/list'
  161. })
  162. },
  163. navigateToService(item) {
  164. uni.navigateTo({
  165. url: item.path
  166. })
  167. },
  168. handleContact() {
  169. uni.makePhoneCall({
  170. phoneNumber: '400-xxx-xxxx' // 替换为实际的客服电话
  171. })
  172. },
  173. navigateToAbout() {
  174. uni.navigateTo({
  175. url: '/pages/about/index'
  176. })
  177. },
  178. navigateToSettings() {
  179. uni.navigateTo({
  180. url: '/pages/settings/index'
  181. })
  182. },
  183. // 使用授权服务处理登出
  184. handleLogout() {
  185. uni.showModal({
  186. title: '提示',
  187. content: '确认退出登录?',
  188. success: (res) => {
  189. if (res.confirm) {
  190. logout().then(() => {
  191. this.isLogin = false;
  192. this.userInfo = {
  193. nickname: '游客',
  194. id: '',
  195. avatar: '/static/images/icon.png'
  196. };
  197. });
  198. }
  199. }
  200. })
  201. }
  202. }
  203. }
  204. </script>
  205. <style>
  206. .container {
  207. min-height: 100vh;
  208. background-color: #f5f5f5;
  209. padding: 20rpx;
  210. }
  211. .user-card {
  212. background-color: #4CAF50;
  213. border-radius: 16rpx;
  214. padding: 30rpx;
  215. margin-bottom: 20rpx;
  216. }
  217. .user-header {
  218. display: flex;
  219. align-items: center;
  220. }
  221. .avatar {
  222. width: 120rpx;
  223. height: 120rpx;
  224. border-radius: 60rpx;
  225. /* border: 4rpx solid #fff; */
  226. }
  227. .user-detail {
  228. margin-left: 20rpx;
  229. color: #fff;
  230. }
  231. .nickname {
  232. font-size: 32rpx;
  233. font-weight: bold;
  234. margin-bottom: 10rpx;
  235. display: block;
  236. }
  237. .user-id {
  238. font-size: 24rpx;
  239. opacity: 0.8;
  240. }
  241. .info-card {
  242. background-color: #fff;
  243. border-radius: 16rpx;
  244. padding: 30rpx;
  245. margin-bottom: 20rpx;
  246. }
  247. .card-title {
  248. display: flex;
  249. justify-content: space-between;
  250. align-items: center;
  251. margin-bottom: 30rpx;
  252. font-size: 32rpx;
  253. font-weight: bold;
  254. }
  255. .more {
  256. color: #666;
  257. font-size: 24rpx;
  258. font-weight: normal;
  259. }
  260. .plot-info {
  261. display: flex;
  262. justify-content: space-around;
  263. }
  264. .plot-item {
  265. text-align: center;
  266. }
  267. .number {
  268. font-size: 36rpx;
  269. font-weight: bold;
  270. color: #4CAF50;
  271. display: block;
  272. }
  273. .label {
  274. font-size: 24rpx;
  275. color: #666;
  276. margin-top: 10rpx;
  277. display: block;
  278. }
  279. .service-grid {
  280. display: grid;
  281. grid-template-columns: repeat(4, 1fr);
  282. gap: 30rpx;
  283. padding: 10rpx 0;
  284. }
  285. .service-item {
  286. display: flex;
  287. flex-direction: column;
  288. align-items: center;
  289. }
  290. .service-icon {
  291. width: 88rpx;
  292. height: 88rpx;
  293. background-color: #E8F5E9;
  294. border-radius: 16rpx;
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. margin-bottom: 16rpx;
  299. }
  300. .service-icon text {
  301. font-size: 32rpx;
  302. color: #4CAF50;
  303. font-weight: bold;
  304. }
  305. .service-name {
  306. font-size: 28rpx;
  307. color: #666;
  308. text-align: center;
  309. }
  310. .function-list {
  311. width: 100%;
  312. }
  313. .function-item {
  314. display: flex;
  315. justify-content: space-between;
  316. align-items: center;
  317. padding: 30rpx 0;
  318. border-bottom: 1rpx solid #f5f5f5;
  319. }
  320. .function-item:last-child {
  321. border-bottom: none;
  322. }
  323. .function-item .left {
  324. display: flex;
  325. align-items: center;
  326. }
  327. .function-icon {
  328. width: 44rpx;
  329. height: 44rpx;
  330. background-color: #E8F5E9;
  331. color: #4CAF50;
  332. font-size: 28rpx;
  333. font-weight: bold;
  334. border-radius: 8rpx;
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. margin-right: 20rpx;
  339. }
  340. .function-item text {
  341. font-size: 28rpx;
  342. color: #333;
  343. }
  344. .arrow {
  345. color: #999;
  346. font-size: 24rpx;
  347. }
  348. .login-text {
  349. font-size: 32rpx;
  350. font-weight: bold;
  351. color: #fff;
  352. background-color: rgba(255, 255, 255, 0.2);
  353. padding: 10rpx 30rpx;
  354. border-radius: 30rpx;
  355. }
  356. </style>