| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <template>
- <navigation-bar title="个人中心"></navigation-bar>
- <image src="/static/images/user-bg.png" mode="widthFix" class="bg" />
- <block v-if="user && user.mobilePhone">
- <view class="container" :style="containerStyle">
- <view class="header">
- <view class="phone fs-34 color-fff">{{ user.mobilePhoneFormat }}</view>
- </view>
- <!-- 钱包余额主卡 -->
- <view
- class="panel pressable"
- hover-class="pressed"
- hover-stay-time="80"
- @click="toPage(-1)"
- >
- <view class="flex-column">
- <view class="fs-24" style="color: #8c9997">钱包余额(元)</view>
- <view class="fs-56 fw-600 mt-8 balance-num">{{ user.balance }}</view>
- </view>
- <view class="recharge-btn flex-center fs-26 fw-500">充值</view>
- </view>
- <!-- 功能菜单分组 -->
- <view class="menu-group" v-for="(group, gi) in menuGroups" :key="gi">
- <template v-for="idx in group" :key="idx">
- <view
- class="menu flex-align-center pressable"
- hover-class="pressed"
- hover-stay-time="80"
- v-if="idx !== menu.length - 1 || user.mobilePhone === '15986907592'"
- @click="toPage(idx)"
- >
- <view class="menu-icon">
- <uni-icons
- v-if="menu[idx].iconType"
- :type="menu[idx].iconType"
- size="26"
- color="rgba(28,43,41,0.65)"
- ></uni-icons>
- <image v-else :src="menu[idx].icon" mode="aspectFit"></image>
- </view>
- <view class="menu-content flex-column flex-grow">
- <view class="menu-title fs-28">{{ menu[idx].title }}</view>
- <view class="menu-desc fs-22 mt-4" v-if="menu[idx].desc">{{
- menu[idx].desc
- }}</view>
- </view>
- <view class="ml-auto">
- <uni-icons
- type="right"
- size="12"
- color="rgba(28,43,41,0.3)"
- ></uni-icons>
- </view>
- </view>
- </template>
- </view>
- <view style="height: 40rpx"></view>
- </view>
- </block>
- <block v-else>
- <view class="container" :style="containerStyle">
- <view class="guest flex-column flex-align-center">
- <image
- class="guest-logo"
- src="/static/images/map-logo.png"
- mode="aspectFit"
- />
- <view class="fs-28 mt-40" style="color: #5c6b69"
- >登录后查看更多功能</view
- >
- <button class="login-btn mt-48" @click="goToLogin">登录/注册</button>
- </view>
- </view>
- </block>
- </template>
- <script setup lang="ts">
- import { fetchContact } from "@/api";
- import { fetchProfile } from "@/api/user";
- import { isAuthenticated, requireAuth } from "@/utils/auth";
- import { onLoad, onShow } from "@dcloudio/uni-app";
- import { computed, ref } from "vue";
- const containerStyle = ref({});
- const user = ref<any>({});
- const service = ref("");
- const menu = ref([
- {
- title: "我的卡包",
- path: "/pages-charge/card/card",
- icon: "/static/images/user/0.png",
- },
- {
- title: "充电订单",
- path: "/pages-charge/orders/orders",
- icon: "/static/images/user/1.png",
- },
- {
- title: "发票抬头",
- path: "/pages-user/invoice-title",
- iconType: "compose",
- },
- {
- title: "我的收藏",
- path: "/pages-user/collect/collect",
- icon: "/static/images/user/2.png",
- },
- {
- title: "个人信息",
- path: "/pages-user/profile/profile",
- icon: "/static/images/user/3.png",
- },
- {
- title: "联系我们",
- desc: "工作时间 7:00-24:00",
- path: "",
- icon: "/static/images/user/4.png",
- },
- {
- title: "常见问题",
- path: "/pages-common/faq/faq",
- icon: "/static/images/user/5.png",
- },
- {
- title: "充电站列表",
- path: "/pages/list/list",
- icon: "/static/images/user/1.png",
- },
- ]);
- // 菜单分组渲染:资产/订单 + 服务;索引与 menu 对应(toPage/鉴权依赖原索引)
- const menuGroups = computed(() => [
- [0, 1, menu.value.length - 1],
- [2, 3, 4, 5, 6],
- ]);
- const AUTH_REQUIRED_INDICES = [0, 1, 2, 3, 4];
- const goToLogin = () => {
- requireAuth("/pages/user/user");
- };
- const toPage = (index: number) => {
- if (index < 0) {
- if (!requireAuth("/pages-user/wallet/wallet")) return;
- uni.navigateTo({
- url: "/pages-user/wallet/wallet",
- });
- return;
- }
- const item = menu.value[index];
- if (!item.path) {
- uni.makePhoneCall({
- phoneNumber: service.value,
- });
- return;
- }
- if (AUTH_REQUIRED_INDICES.includes(index) && !requireAuth(item.path)) {
- return;
- }
- uni.navigateTo({
- url: item.path + (item.title === "常见问题" ? `?service=${service.value}` : ""),
- });
- };
- onLoad(() => {
- const bound = uni.getMenuButtonBoundingClientRect();
- containerStyle.value = {
- top: `${bound.bottom + 10}px`,
- };
- fetchContact().then((res) => {
- if (res && res.mobile) {
- service.value = res.mobile;
- }
- });
- });
- onShow(() => {
- if (!isAuthenticated()) {
- return;
- }
- fetchProfile().then((res) => {
- res.mobilePhoneFormat =
- res.mobilePhone.slice(0, 3) + "****" + res.mobilePhone.slice(7);
- user.value = res;
- });
- });
- </script>
- <style lang="scss">
- @use "../../styles/dialog.scss";
- .bg {
- position: absolute;
- left: 0;
- top: 0;
- width: 100%;
- height: 660rpx;
- }
- .container {
- position: absolute;
- left: 0;
- top: 0;
- height: 100vh;
- width: 100%;
- overflow-y: auto;
- padding: 0 30rpx;
- box-sizing: border-box;
- }
- .header {
- height: 160rpx;
- display: flex;
- align-items: flex-end;
- padding-bottom: 32rpx;
- }
- .panel {
- display: flex;
- align-items: center;
- background: #ffffff;
- border-radius: 20rpx;
- padding: 36rpx 40rpx;
- box-shadow: 0 4rpx 16rpx rgba(28, 43, 41, 0.05);
- .balance-num {
- color: #1c2b29;
- line-height: normal;
- }
- .recharge-btn {
- flex-shrink: 0;
- width: 128rpx;
- height: 56rpx;
- border-radius: 28rpx;
- background: var(--color-primary);
- color: #ffffff;
- transition: background-color 0.15s cubic-bezier(0.22, 1, 0.36, 1);
- }
- &:active .recharge-btn {
- background: var(--color-primary-deep);
- }
- }
- .menu-group {
- background: #ffffff;
- border-radius: 20rpx;
- margin-top: 20rpx;
- padding: 0 30rpx;
- .menu {
- height: 112rpx;
- border-bottom: 1rpx solid var(--divider);
- &:last-child {
- border-bottom: none;
- }
- }
- .menu-icon {
- width: 52rpx;
- height: 52rpx;
- margin-right: 24rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- flex-shrink: 0;
- image {
- width: 52rpx;
- height: 52rpx;
- }
- }
- .menu-title {
- color: #1c2b29;
- line-height: 34rpx;
- }
- .menu-desc {
- color: #8c9997;
- line-height: 28rpx;
- }
- }
- .guest {
- padding-top: 200rpx;
- }
- .guest-logo {
- width: 160rpx;
- height: 160rpx;
- }
- .login-btn {
- width: 400rpx;
- height: 88rpx;
- background: var(--color-primary);
- color: #fff;
- font-size: 30rpx;
- font-weight: 500;
- border-radius: 44rpx;
- line-height: 88rpx;
- transition: background-color 0.15s cubic-bezier(0.22, 1, 0.36, 1);
- }
- .login-btn:active {
- background: var(--color-primary-deep);
- }
- </style>
|