index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <template>
  2. <view class="page-container">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-navbar" :style="{paddingTop: statusBarHeight + 'px'}">
  5. <view class="navbar-content">
  6. <view class="navbar-title">
  7. <uv-icon name="account-fill" color="#FFFFFF" size="20"></uv-icon>
  8. <text class="title-text">我的</text>
  9. </view>
  10. </view>
  11. </view>
  12. <!-- 页面内容区域 -->
  13. <scroll-view class="content-scroll" scroll-y="true">
  14. <custom-service></custom-service>
  15. <!-- 用户信息与钱包合并卡片 -->
  16. <view class="user-wallet-card">
  17. <!-- 用户信息区域 -->
  18. <view class="user-section" @click="handleUserClick">
  19. <view class="user-avatar-wrapper">
  20. <image class="user-avatar" src='/static/iconfont/me.svg'></image>
  21. </view>
  22. <text class="user-phone">{{ user.mobilePhone || '未登录' }}</text>
  23. </view>
  24. <!-- 分割线 -->
  25. <view class="divider"></view>
  26. <!-- 钱包信息区域 -->
  27. <view class="wallet-section" @click="toPage({path: '/pages-user/wallet/index'})">
  28. <view class="wallet-header">
  29. <view class="wallet-title">
  30. <uv-icon name="red-packet" size="22" color="#C6171E"></uv-icon>
  31. <text class="wallet-title-text">钱包余额</text>
  32. </view>
  33. <uv-icon name="arrow-right" size="14" color="#C0C4CC"></uv-icon>
  34. </view>
  35. <view class="wallet-body">
  36. <view class="wallet-balance">
  37. <view class="balance-value">
  38. <text class="balance-symbol">¥</text>
  39. <text class="balance-amount">{{ ((user.balance || 0) / 100).toFixed(2) }}</text>
  40. <text class="balance-unit">元</text>
  41. </view>
  42. </view>
  43. <view class="wallet-actions">
  44. <view class="action-btn action-recharge" @click.stop="toPage({path: '/pages-user/wallet/recharge'})">
  45. <text>充值</text>
  46. </view>
  47. <view class="action-btn action-detail" @click.stop="toPage({path: '/pages-user/wallet/index'})">
  48. <text>明细</text>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- 功能菜单列表 -->
  55. <view class="menu-section">
  56. <view class="section-title">
  57. <view class="title-dot"></view>
  58. <text>功能服务</text>
  59. </view>
  60. <view class="menu-list">
  61. <view
  62. class="menu-item"
  63. v-for="(item, index) in menu"
  64. :key="index"
  65. @click="toPage(item)"
  66. >
  67. <view class="menu-left">
  68. <view class="menu-icon-box" :class="'menu-icon-box--' + item.color">
  69. <image v-if="item.iconType === 'image'" class="menu-icon" :src="item.icon" mode="aspectFit"></image>
  70. <uv-icon v-else :name="item.icon" size="22" :color="item.iconColor || '#C6171E'"></uv-icon>
  71. </view>
  72. <text class="menu-text">{{ item.title }}</text>
  73. </view>
  74. <uv-icon name="arrow-right" size="16" color="#C0C4CC"></uv-icon>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 退出登录按钮 -->
  79. <view class="logout-wrapper" v-if="isLogin">
  80. <view class="logout-btn" @click="logoutUser">
  81. <text>退出登录</text>
  82. </view>
  83. </view>
  84. <!-- 底部占位 -->
  85. <view style="height: 140rpx;"></view>
  86. </scroll-view>
  87. <!-- 底部导航栏 -->
  88. <tab-bar :index="2"/>
  89. </view>
  90. </template>
  91. <script setup lang="ts">
  92. import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
  93. import {ref} from "vue";
  94. import TabBar from "@/components/tab-bar/index.vue";
  95. import {checkLogin, clearToken, loadUserInfo} from "@/utils/auth"
  96. import {get} from "@/utils/https";
  97. const statusBarHeight = ref(0)
  98. const user = ref<any>({
  99. id: 0,
  100. avatar: "",
  101. mobilePhoneFormat: '',
  102. balance: 0,
  103. });
  104. const isLogin = ref(false)
  105. const menu = ref([
  106. {
  107. title: "绑定车辆",
  108. path: "/pages-user/profile/index",
  109. icon: '/static/iconfont/car.svg',
  110. iconType: 'image',
  111. color: 'red',
  112. },
  113. {
  114. title: "我的订单",
  115. path: "/pages-order/list/index",
  116. icon: 'order',
  117. iconColor: '#C6171E',
  118. color: 'red',
  119. },
  120. // {
  121. // title: "联系我们",
  122. // path: "/pages-user/contact/index",
  123. // icon: '/static/user/contact.png'
  124. // },
  125. {
  126. title: "洗车指导",
  127. path: "/pages-user/faq/index",
  128. icon: 'question-circle',
  129. iconColor: '#C6171E',
  130. color: 'red',
  131. },
  132. {
  133. title: "故障反馈",
  134. path: "/pages-user/feedback/index",
  135. icon: 'warning',
  136. iconColor: '#C6171E',
  137. color: 'red',
  138. },
  139. ]);
  140. const toPage = (item: any) => {
  141. checkLogin().then(() => {
  142. uni.navigateTo({
  143. url: item.path,
  144. });
  145. }).catch(e => {
  146. console.error("handleMenuClick 校验,跳转登录页", e)
  147. uni.navigateTo({
  148. url: '/pages-user/login/index'
  149. })
  150. })
  151. };
  152. const handleUserClick = () => {
  153. if (!isLogin.value) {
  154. uni.navigateTo({
  155. url: '/pages-user/login/index'
  156. })
  157. }
  158. };
  159. const logoutUser = () => {
  160. uni.showModal({
  161. title: "温馨提示",
  162. content: "确定退出登录吗?",
  163. confirmColor: "#C6171E",
  164. confirmText: "确定退出",
  165. cancelText: "手滑了",
  166. success: (res) => {
  167. if (res.confirm) {
  168. uni.showLoading({
  169. title: "退出中",
  170. });
  171. get(`/user/logout`).then(() => {
  172. uni.hideLoading();
  173. uni.showToast({
  174. icon: "success",
  175. title: "已退出",
  176. });
  177. isLogin.value = false;
  178. getApp<any>().globalData.user = {};
  179. getApp<any>().globalData.manualLogout = true;
  180. clearToken();
  181. setTimeout(() => {
  182. uni.exitMiniProgram()
  183. }, 1500);
  184. })
  185. }
  186. },
  187. });
  188. };
  189. onLoad(() => {
  190. const systemInfo = uni.getSystemInfoSync();
  191. statusBarHeight.value = systemInfo.statusBarHeight || 0;
  192. });
  193. const addListener = () => {
  194. uni.$on('login', function (data) {
  195. isLogin.value = data.isLogin;
  196. if (data.isLogin) {
  197. user.value = getApp<any>().globalData.user;
  198. }
  199. })
  200. uni.$on('logout', function (data) {
  201. isLogin.value = false;
  202. user.value = {}
  203. })
  204. }
  205. const removeListener = () => {
  206. uni.$off('logout');
  207. uni.$off('login');
  208. }
  209. onShow(() => {
  210. let gd = getApp<any>().globalData;
  211. if (gd.refresh) {
  212. if (gd.user?.id) {
  213. refreshUserProfile()
  214. }
  215. } else {
  216. if (gd.user?.id) {
  217. if (new Date().getTime() - new Date(gd.user.lastLoginTime).getTime() > 300 * 1000) {
  218. refreshUserProfile()
  219. } else {
  220. isLogin.value = true;
  221. user.value = gd.user;
  222. }
  223. }
  224. }
  225. addListener();
  226. });
  227. const refreshUserProfile = () => {
  228. isLogin.value = true;
  229. loadUserInfo().then(val => {
  230. if (val && val.id) {
  231. user.value = val;
  232. }
  233. getApp<any>().globalData.refresh = false;
  234. })
  235. }
  236. onHide(() => {
  237. removeListener();
  238. })
  239. </script>
  240. <style lang="scss" scoped>
  241. page {
  242. background: $uni-bg-color-page;
  243. }
  244. .page-container {
  245. width: 100vw;
  246. height: 100vh;
  247. background: linear-gradient(180deg, $uni-color-primary 0%, $uni-color-primary-light 25%, $uni-bg-color-page 45%);
  248. display: flex;
  249. flex-direction: column;
  250. }
  251. // 自定义导航栏
  252. .custom-navbar {
  253. position: relative;
  254. z-index: 100;
  255. .navbar-content {
  256. height: 88rpx;
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. .navbar-title {
  261. display: flex;
  262. align-items: center;
  263. gap: 12rpx;
  264. .title-text {
  265. color: $uni-text-color-inverse;
  266. font-size: 36rpx;
  267. font-weight: $uni-font-weight-semibold;
  268. letter-spacing: 2rpx;
  269. }
  270. }
  271. }
  272. }
  273. // 内容滚动区域
  274. .content-scroll {
  275. flex: 1;
  276. height: 100%;
  277. width: 100%;
  278. }
  279. // 用户信息与钱包合并卡片
  280. .user-wallet-card {
  281. margin: 30rpx 30rpx 24rpx;
  282. @include card-interactive(24rpx);
  283. overflow: hidden;
  284. // 用户信息区域
  285. .user-section {
  286. padding: 24rpx 32rpx;
  287. display: flex;
  288. align-items: center;
  289. gap: 20rpx;
  290. .user-avatar-wrapper {
  291. flex-shrink: 0;
  292. .user-avatar {
  293. width: 80rpx;
  294. height: 80rpx;
  295. border-radius: 50%;
  296. background: rgba($uni-color-primary, 0.08);
  297. padding: 10rpx;
  298. box-sizing: border-box;
  299. }
  300. }
  301. .user-phone {
  302. font-size: 30rpx;
  303. font-weight: $uni-font-weight-semibold;
  304. color: $uni-text-color;
  305. }
  306. }
  307. // 分割线
  308. .divider {
  309. height: 1rpx;
  310. background: $uni-border-color-light;
  311. margin: 0 32rpx;
  312. }
  313. // 钱包区域
  314. .wallet-section {
  315. padding: 28rpx 32rpx 24rpx;
  316. .wallet-header {
  317. display: flex;
  318. justify-content: space-between;
  319. align-items: center;
  320. margin-bottom: 20rpx;
  321. .wallet-title {
  322. display: flex;
  323. align-items: center;
  324. gap: 8rpx;
  325. font-size: 26rpx;
  326. font-weight: $uni-font-weight-semibold;
  327. color: $uni-text-color;
  328. .wallet-title-text {
  329. font-size: 30rpx;
  330. }
  331. }
  332. }
  333. .wallet-body {
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. }
  338. .wallet-balance {
  339. .balance-value {
  340. display: flex;
  341. align-items: baseline;
  342. gap: 4rpx;
  343. .balance-symbol {
  344. font-size: 28rpx;
  345. color: $uni-text-color-dark;
  346. font-weight: $uni-font-weight-semibold;
  347. }
  348. .balance-amount {
  349. font-size: 44rpx;
  350. color: $uni-text-color-dark;
  351. font-weight: $uni-font-weight-bold;
  352. line-height: 1;
  353. }
  354. .balance-unit {
  355. font-size: 24rpx;
  356. color: $uni-text-color-hint;
  357. margin-left: 2rpx;
  358. }
  359. }
  360. }
  361. .wallet-actions {
  362. display: flex;
  363. gap: 16rpx;
  364. flex-shrink: 0;
  365. .action-btn {
  366. padding: 12rpx 36rpx;
  367. border-radius: 40rpx;
  368. font-size: 24rpx;
  369. font-weight: $uni-font-weight-medium;
  370. text-align: center;
  371. &.action-recharge {
  372. background: $uni-color-primary;
  373. color: #fff;
  374. }
  375. &.action-detail {
  376. background: rgba($uni-color-primary, 0.08);
  377. color: $uni-color-primary;
  378. }
  379. }
  380. }
  381. }
  382. }
  383. // 菜单区域
  384. .menu-section {
  385. margin: 0 30rpx 24rpx;
  386. .section-title {
  387. display: flex;
  388. align-items: center;
  389. gap: 12rpx;
  390. padding: 0 12rpx;
  391. margin-bottom: 20rpx;
  392. font-size: 28rpx;
  393. font-weight: $uni-font-weight-semibold;
  394. color: $uni-text-color;
  395. .title-dot {
  396. width: 10rpx;
  397. height: 10rpx;
  398. background: $uni-color-primary;
  399. border-radius: 50%;
  400. }
  401. }
  402. .menu-list {
  403. @include card-interactive(24rpx);
  404. overflow: hidden;
  405. }
  406. .menu-item {
  407. display: flex;
  408. justify-content: space-between;
  409. align-items: center;
  410. padding: 24rpx 32rpx;
  411. border-bottom: 1rpx solid $uni-border-color-light;
  412. &:last-child {
  413. border-bottom: none;
  414. }
  415. .menu-left {
  416. display: flex;
  417. align-items: center;
  418. gap: 24rpx;
  419. .menu-icon-box {
  420. width: 72rpx;
  421. height: 72rpx;
  422. border-radius: 16rpx;
  423. display: flex;
  424. align-items: center;
  425. justify-content: center;
  426. .menu-icon {
  427. width: 42rpx;
  428. height: 42rpx;
  429. }
  430. &--red {
  431. background: rgba($uni-color-primary, 0.08);
  432. }
  433. &--blue {
  434. background: rgba(33, 150, 243, 0.08);
  435. }
  436. &--green {
  437. background: rgba(76, 175, 80, 0.08);
  438. }
  439. &--orange {
  440. background: rgba(255, 152, 0, 0.08);
  441. }
  442. }
  443. .menu-text {
  444. font-size: 28rpx;
  445. color: $uni-text-color;
  446. }
  447. }
  448. }
  449. }
  450. // 退出按钮
  451. .logout-wrapper {
  452. margin: 40rpx 30rpx;
  453. .logout-btn {
  454. display: flex;
  455. align-items: center;
  456. justify-content: center;
  457. height: 88rpx;
  458. @include card-interactive(44rpx);
  459. font-size: 28rpx;
  460. color: $uni-color-error;
  461. font-weight: $uni-font-weight-semibold;
  462. }
  463. }
  464. </style>