user.vue 7.4 KB

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