178 lines
4.0 KiB
Vue
178 lines
4.0 KiB
Vue
<template>
|
||
<view class="page">
|
||
<!-- 顶部用户信息 -->
|
||
<view class="user-card">
|
||
<view class="row avatar-row">
|
||
<text class="label">头像 </text>
|
||
<!-- <image class="avatar" :src="userInfo.avatar" mode="aspectFill" /> -->
|
||
<uni-icons type="contact" size="40" color="#ccc"></uni-icons>
|
||
</view>
|
||
<view class="row">
|
||
<text class="label">昵称</text>
|
||
<text class="value">{{ userInfo.nickname }}</text>
|
||
</view>
|
||
<view class="row">
|
||
<text class="label">手机号</text>
|
||
<text class="value">{{ userInfo.phone }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 中间功能入口(循环渲染) -->
|
||
<view class="menu-card">
|
||
<view
|
||
class="menu-item"
|
||
v-for="(item, index) in menuList"
|
||
:key="index"
|
||
@click="handleMenuClick(item)"
|
||
>
|
||
<text class="label">{{ item.label }}</text>
|
||
<uni-icons type="right" size="14" color="#ccc"></uni-icons>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 底部退出按钮 -->
|
||
<text class="logout-btn" @click="handleLogout">退出登录</text>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, onMounted } from "vue";
|
||
import { getLoginUserPhone } from "@/request/api/LoginApi";
|
||
import { checkToken } from "@/hooks/useGoLogin";
|
||
|
||
// 假数据
|
||
const userInfo = ref({
|
||
avatar: "/static/default-avatar.png",
|
||
nickname: "微信用户",
|
||
phone: "",
|
||
});
|
||
|
||
// 功能菜单列表(带 type 区分操作类型)
|
||
const menuList = ref([
|
||
// { label: '修改手机号', type: 'navigate', url: '/pages/change-phone/change-phone' },
|
||
{
|
||
label: "账号注销",
|
||
type: "navigate",
|
||
url: "/pages/cancel-account/cancel-account",
|
||
},
|
||
// { label: '营业资质&协议', type: 'navigate', url: '/pages/agreement/agreement' },
|
||
{ label: "联系客服", type: "action", action: "contactService" },
|
||
{ label: "订阅消息", type: "action", action: "subscribeMessage" },
|
||
]);
|
||
|
||
// 生命周期钩子
|
||
onMounted(() => {
|
||
checkToken().then(() => {
|
||
getLoginUserPhoneInfo();
|
||
});
|
||
});
|
||
|
||
const getLoginUserPhoneInfo = async () => {
|
||
const res = await getLoginUserPhone();
|
||
|
||
if (res.code === 0) {
|
||
userInfo.value.phone = res.data;
|
||
}
|
||
};
|
||
|
||
// 处理菜单点击
|
||
const handleMenuClick = (item) => {
|
||
if (item.type === "navigate" && item.url) {
|
||
uni.navigateTo({ url: item.url });
|
||
} else if (item.type === "action") {
|
||
if (item.action === "contactService") {
|
||
uni.showToast({ title: "联系客服功能待实现", icon: "none" });
|
||
} else if (item.action === "subscribeMessage") {
|
||
uni.requestSubscribeMessage({
|
||
tmplIds: ["fMIt1q9GgM3Ep0DJSNgVPm4C3lCpQdz2TediETcv3iM"],
|
||
success(res) {
|
||
console.log(res);
|
||
},
|
||
});
|
||
}
|
||
}
|
||
};
|
||
|
||
// 退出登录
|
||
const handleLogout = () => {
|
||
uni.showModal({
|
||
title: "温馨提示",
|
||
content: "确定要退出登录吗?",
|
||
success: (res) => {
|
||
if (res.confirm) {
|
||
uni.clearStorageSync();
|
||
uni.reLaunch({ url: "/pages/login/index" });
|
||
}
|
||
},
|
||
});
|
||
};
|
||
</script>
|
||
|
||
<style scoped>
|
||
.page {
|
||
padding: 24rpx;
|
||
background-color: #f6f6f6;
|
||
min-height: 100vh;
|
||
}
|
||
|
||
.user-card,
|
||
.menu-card {
|
||
background-color: #fff;
|
||
border-radius: 12rpx;
|
||
padding-left: 24rpx;
|
||
margin-bottom: 20rpx;
|
||
}
|
||
|
||
.row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 28rpx 24rpx 28rpx 0;
|
||
border-bottom: 1px solid #f0f0f0;
|
||
}
|
||
|
||
.row:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.avatar-row .avatar {
|
||
width: 80rpx;
|
||
height: 80rpx;
|
||
border-radius: 50%;
|
||
}
|
||
|
||
.label {
|
||
font-size: 28rpx;
|
||
color: #333;
|
||
}
|
||
|
||
.value {
|
||
font-size: 28rpx;
|
||
color: #666;
|
||
}
|
||
|
||
.menu-item {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 28rpx 24rpx 28rpx 0;
|
||
border-bottom: 1px solid #f0f0f0;
|
||
}
|
||
|
||
.menu-item:last-child {
|
||
border-bottom: none;
|
||
}
|
||
|
||
.logout-btn {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
height: 42px;
|
||
margin-top: 40px;
|
||
background-color: #fff;
|
||
color: #333;
|
||
border-radius: 8rpx;
|
||
border: none;
|
||
}
|
||
</style>
|