user.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <navigation-bar title="个人中心"></navigation-bar>
  3. <image src="/static/images/user-bg.png" mode="widthFix" class="bg" />
  4. <block v-if="user && user.mobilePhone">
  5. <view class="container" :style="containerStyle">
  6. <view class="header">
  7. <view class="phone fs-34 color-fff">{{ user.mobilePhoneFormat }}</view>
  8. </view>
  9. <!-- 钱包余额主卡 -->
  10. <view
  11. class="panel pressable"
  12. hover-class="pressed"
  13. hover-stay-time="80"
  14. @click="toPage(-1)"
  15. >
  16. <view class="flex-column">
  17. <view class="fs-24" style="color: #8c9997">钱包余额(元)</view>
  18. <view class="fs-56 fw-600 mt-8 balance-num">{{ user.balance }}</view>
  19. </view>
  20. <view class="recharge-btn flex-center fs-26 fw-500">充值</view>
  21. </view>
  22. <!-- 功能菜单分组 -->
  23. <view class="menu-group" v-for="(group, gi) in menuGroups" :key="gi">
  24. <template v-for="idx in group" :key="idx">
  25. <view
  26. class="menu flex-align-center pressable"
  27. hover-class="pressed"
  28. hover-stay-time="80"
  29. v-if="idx !== menu.length - 1 || user.mobilePhone === '15986907592'"
  30. @click="toPage(idx)"
  31. >
  32. <view class="menu-icon">
  33. <uni-icons
  34. v-if="menu[idx].iconType"
  35. :type="menu[idx].iconType"
  36. size="26"
  37. color="rgba(28,43,41,0.65)"
  38. ></uni-icons>
  39. <image v-else :src="menu[idx].icon" mode="aspectFit"></image>
  40. </view>
  41. <view class="menu-content flex-column flex-grow">
  42. <view class="menu-title fs-28">{{ menu[idx].title }}</view>
  43. <view class="menu-desc fs-22 mt-4" v-if="menu[idx].desc">{{
  44. menu[idx].desc
  45. }}</view>
  46. </view>
  47. <view class="ml-auto">
  48. <uni-icons
  49. type="right"
  50. size="12"
  51. color="rgba(28,43,41,0.3)"
  52. ></uni-icons>
  53. </view>
  54. </view>
  55. </template>
  56. </view>
  57. <view style="height: 40rpx"></view>
  58. </view>
  59. </block>
  60. <block v-else>
  61. <view class="container" :style="containerStyle">
  62. <view class="guest flex-column flex-align-center">
  63. <image
  64. class="guest-logo"
  65. src="/static/images/map-logo.png"
  66. mode="aspectFit"
  67. />
  68. <view class="fs-28 mt-40" style="color: #5c6b69"
  69. >登录后查看更多功能</view
  70. >
  71. <button class="login-btn mt-48" @click="goToLogin">登录/注册</button>
  72. </view>
  73. </view>
  74. </block>
  75. </template>
  76. <script setup lang="ts">
  77. import { fetchContact } from "@/api";
  78. import { fetchProfile } from "@/api/user";
  79. import { isAuthenticated, requireAuth } from "@/utils/auth";
  80. import { onLoad, onShow } from "@dcloudio/uni-app";
  81. import { computed, ref } from "vue";
  82. const containerStyle = ref({});
  83. const user = ref<any>({});
  84. const service = ref("");
  85. const menu = ref([
  86. {
  87. title: "我的卡包",
  88. path: "/pages-charge/card/card",
  89. icon: "/static/images/user/0.png",
  90. },
  91. {
  92. title: "充电订单",
  93. path: "/pages-charge/orders/orders",
  94. icon: "/static/images/user/1.png",
  95. },
  96. {
  97. title: "发票抬头",
  98. path: "/pages-user/invoice-title",
  99. iconType: "compose",
  100. },
  101. {
  102. title: "我的收藏",
  103. path: "/pages-user/collect/collect",
  104. icon: "/static/images/user/2.png",
  105. },
  106. {
  107. title: "个人信息",
  108. path: "/pages-user/profile/profile",
  109. icon: "/static/images/user/3.png",
  110. },
  111. {
  112. title: "联系我们",
  113. desc: "工作时间 7:00-24:00",
  114. path: "",
  115. icon: "/static/images/user/4.png",
  116. },
  117. {
  118. title: "常见问题",
  119. path: "/pages-common/faq/faq",
  120. icon: "/static/images/user/5.png",
  121. },
  122. {
  123. title: "充电站列表",
  124. path: "/pages/list/list",
  125. icon: "/static/images/user/1.png",
  126. },
  127. ]);
  128. // 菜单分组渲染:资产/订单 + 服务;索引与 menu 对应(toPage/鉴权依赖原索引)
  129. const menuGroups = computed(() => [
  130. [0, 1, menu.value.length - 1],
  131. [2, 3, 4, 5, 6],
  132. ]);
  133. const AUTH_REQUIRED_INDICES = [0, 1, 2, 3, 4];
  134. const goToLogin = () => {
  135. requireAuth("/pages/user/user");
  136. };
  137. const toPage = (index: number) => {
  138. if (index < 0) {
  139. if (!requireAuth("/pages-user/wallet/wallet")) return;
  140. uni.navigateTo({
  141. url: "/pages-user/wallet/wallet",
  142. });
  143. return;
  144. }
  145. const item = menu.value[index];
  146. if (!item.path) {
  147. uni.makePhoneCall({
  148. phoneNumber: service.value,
  149. });
  150. return;
  151. }
  152. if (AUTH_REQUIRED_INDICES.includes(index) && !requireAuth(item.path)) {
  153. return;
  154. }
  155. uni.navigateTo({
  156. url: item.path + (item.title === "常见问题" ? `?service=${service.value}` : ""),
  157. });
  158. };
  159. onLoad(() => {
  160. const bound = uni.getMenuButtonBoundingClientRect();
  161. containerStyle.value = {
  162. top: `${bound.bottom + 10}px`,
  163. };
  164. fetchContact().then((res) => {
  165. if (res && res.mobile) {
  166. service.value = res.mobile;
  167. }
  168. });
  169. });
  170. onShow(() => {
  171. if (!isAuthenticated()) {
  172. return;
  173. }
  174. fetchProfile().then((res) => {
  175. res.mobilePhoneFormat =
  176. res.mobilePhone.slice(0, 3) + "****" + res.mobilePhone.slice(7);
  177. user.value = res;
  178. });
  179. });
  180. </script>
  181. <style lang="scss">
  182. @use "../../styles/dialog.scss";
  183. .bg {
  184. position: absolute;
  185. left: 0;
  186. top: 0;
  187. width: 100%;
  188. height: 660rpx;
  189. }
  190. .container {
  191. position: absolute;
  192. left: 0;
  193. top: 0;
  194. height: 100vh;
  195. width: 100%;
  196. overflow-y: auto;
  197. padding: 0 30rpx;
  198. box-sizing: border-box;
  199. }
  200. .header {
  201. height: 160rpx;
  202. display: flex;
  203. align-items: flex-end;
  204. padding-bottom: 32rpx;
  205. }
  206. .panel {
  207. display: flex;
  208. align-items: center;
  209. background: #ffffff;
  210. border-radius: 20rpx;
  211. padding: 36rpx 40rpx;
  212. box-shadow: 0 4rpx 16rpx rgba(28, 43, 41, 0.05);
  213. .balance-num {
  214. color: #1c2b29;
  215. line-height: normal;
  216. }
  217. .recharge-btn {
  218. flex-shrink: 0;
  219. width: 128rpx;
  220. height: 56rpx;
  221. border-radius: 28rpx;
  222. background: var(--color-primary);
  223. color: #ffffff;
  224. transition: background-color 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  225. }
  226. &:active .recharge-btn {
  227. background: var(--color-primary-deep);
  228. }
  229. }
  230. .menu-group {
  231. background: #ffffff;
  232. border-radius: 20rpx;
  233. margin-top: 20rpx;
  234. padding: 0 30rpx;
  235. .menu {
  236. height: 112rpx;
  237. border-bottom: 1rpx solid var(--divider);
  238. &:last-child {
  239. border-bottom: none;
  240. }
  241. }
  242. .menu-icon {
  243. width: 52rpx;
  244. height: 52rpx;
  245. margin-right: 24rpx;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. flex-shrink: 0;
  250. image {
  251. width: 52rpx;
  252. height: 52rpx;
  253. }
  254. }
  255. .menu-title {
  256. color: #1c2b29;
  257. line-height: 34rpx;
  258. }
  259. .menu-desc {
  260. color: #8c9997;
  261. line-height: 28rpx;
  262. }
  263. }
  264. .guest {
  265. padding-top: 200rpx;
  266. }
  267. .guest-logo {
  268. width: 160rpx;
  269. height: 160rpx;
  270. }
  271. .login-btn {
  272. width: 400rpx;
  273. height: 88rpx;
  274. background: var(--color-primary);
  275. color: #fff;
  276. font-size: 30rpx;
  277. font-weight: 500;
  278. border-radius: 44rpx;
  279. line-height: 88rpx;
  280. transition: background-color 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  281. }
  282. .login-btn:active {
  283. background: var(--color-primary-deep);
  284. }
  285. </style>