wz-uniapp/src/pages/my/index.vue

528 lines
12 KiB
Vue

<template>
<view class="profile-page">
<!-- <view class="safe-top"></view> -->
<view class="header">
<text class="header-title">个人中心</text>
<view class="header-actions">
<view class="action-item" @click="onAction('设置')">
<image src="@/static/icons/icon-setting.png" class="icon icon-3" />
</view>
<view class="action-item" @click="onAction('通知')">
<image
src="@/static/icons/icon-notification.png"
class="icon icon-3"
/>
</view>
</view>
</view>
<view class="user-card">
<view class="user-left">
<view class="avatar-wrap">
<view class="avatar">
<image
v-if="isLoggedIn && user.avatar"
:src="user.avatar"
class="avatar-image"
/>
<uni-icons v-else type="person-filled" :size="44" color="#8ca0be" />
</view>
<view class="verified" v-if="isLoggedIn">
<uni-icons type="medal-filled" :size="12" color="#ffffff" />
</view>
</view>
<view
class="user-info"
@click="isLoggedIn ? onAction('') : handleLogin"
>
<text class="user-name">{{ isLoggedIn ? user.name : "未登录" }}</text>
<view class="user-tags" v-if="isLoggedIn">
<text class="tag">{{ user.role }}</text>
<view class="vip-tag">
<uni-icons type="vip-filled" :size="12" color="#4a7c59" />
<text class="vip-text">{{ user.vipStatus }}</text>
</view>
</view>
<view class="login-tip" v-else @click="handleLogin">
<text class="login-text">请先登录查看个人信息</text>
</view>
</view>
</view>
<view class="primary-btn" @click="handlePrimaryAction">
{{ isLoggedIn ? "立即激活" : "去登录" }}
</view>
</view>
<view class="stats-card" v-if="isLoggedIn">
<view class="stat-item" v-for="stat in stats" :key="stat.label">
<text class="stat-value">{{ stat.value }}</text>
<text class="stat-label">{{ stat.label }}</text>
</view>
</view>
<view
class="section"
v-for="section in visibleSections"
:key="section.title"
>
<text class="section-title">{{ section.title }}</text>
<view class="section-body">
<view
class="row"
v-for="item in section.items"
:key="item.title"
@click="onMenuTap(item)"
>
<view class="row-left">
<view class="row-icon" :style="{ backgroundColor: item.bg }">
<uni-icons :type="item.icon" :size="16" color="#ffffff" />
</view>
<text class="row-title">{{ item.title }}</text>
</view>
<uni-icons type="arrow-right" :size="14" color="#c3cad6" />
</view>
</view>
</view>
<view class="logout-wrap">
<view class="logout-btn" v-if="isLoggedIn" @click="handleLogout">
退出登录
</view>
<text class="version">Version 2.4.1 (Build 20241021)</text>
</view>
</view>
</template>
<script>
import { STORAGE_KEYS } from "@/common/env";
const app = getApp();
const DEFAULT_USER = {
avatar: "",
name: "领航学子",
role: "普通用户",
vipStatus: "未激活会员",
};
export default {
data() {
return {
isLoggedIn: false,
user: { ...DEFAULT_USER },
stats: [
{ label: "志愿数量", value: "12" },
{ label: "全省排名", value: "342" },
{ label: "录取概率", value: "85%" },
],
sections: [
{
title: "核心服务",
items: [
{
title: "我的志愿表",
icon: "folder-add-filled",
bg: "#4a7c59",
requiresLogin: true,
},
{
title: "我的订单/缴费记录",
icon: "wallet-filled",
bg: "#3e8be4",
requiresLogin: true,
},
{
title: "成绩/排名记录",
icon: "medal-filled",
bg: "#f08a24",
requiresLogin: true,
},
{
title: "打印设置",
icon: "compose",
bg: "#7b6fe4",
requiresLogin: true,
},
],
},
{
title: "更多功能",
items: [
{
title: "激活会员卡",
icon: "vip-filled",
bg: "#ff8a33",
requiresLogin: true,
},
{ title: "商务合作", icon: "shop-filled", bg: "#4b9ce2" },
{ title: "填报指南/教程", icon: "compose", bg: "#6e7a8c" },
{
title: "联系老师/客服",
icon: "chatbubble-filled",
bg: "#8a5ae0",
},
{
title: "关于我们",
icon: "info-filled",
bg: "#6b7280",
path: "/pages/about/about",
},
],
},
],
};
},
computed: {
visibleSections() {
if (this.isLoggedIn) {
return this.sections;
}
return this.sections
.map((section) => {
const items = section.items.filter((item) => !item.requiresLogin);
return { ...section, items };
})
.filter((section) => section.items.length > 0);
},
},
onShow() {
const token = uni.getStorageSync(STORAGE_KEYS.TOKEN);
this.isLoggedIn = Boolean(token);
if (!this.isLoggedIn) {
this.user = { ...DEFAULT_USER };
return;
}
const userInfo = app.globalData.UserStorage.getUserInfo();
console.warn(userInfo);
if (userInfo) {
this.user.avatar = userInfo.avatarUrl || DEFAULT_USER.avatar;
this.user.name = userInfo.nickname || userInfo.name || this.user.name;
}
},
methods: {
onAction(label) {
uni.showToast({
title: `${label} 可点击`,
icon: "none",
});
},
onMenuTap(item) {
if (item.requiresLogin && !this.isLoggedIn) {
uni.showToast({
title: "请先登录",
icon: "none",
});
this.handleLogin();
return;
}
if (item.path) {
// #ifdef H5 || APP-PLUS
uni.navigateTo({ url: item.path });
// #endif
// #ifndef H5 || APP-PLUS
uni.showToast({
title: "当前端暂不支持",
icon: "none",
});
// #endif
return;
}
uni.showToast({
title: `${item.title} 可点击`,
icon: "none",
});
},
handlePrimaryAction() {
if (this.isLoggedIn) {
this.onAction("激活会员");
return;
}
this.handleLogin();
},
handleLogin() {
uni.navigateTo({ url: "/pages/login/index" });
},
handleLogout() {
uni.showModal({
title: "提示",
content: "确认退出登录吗?",
success: (res) => {
if (!res.confirm) return;
uni.removeStorageSync(STORAGE_KEYS.TOKEN);
uni.removeStorageSync(STORAGE_KEYS.USER_INFO);
uni.showToast({
title: "已退出登录",
icon: "none",
});
setTimeout(() => {
uni.switchTab({ url: "/pages/index/index" });
}, 300);
},
});
},
},
};
</script>
<style scoped>
.profile-page {
min-height: 100vh;
padding: 0 24rpx 140rpx;
background-color: #fdfaf6;
background-image:
radial-gradient(
circle at 20% 30%,
rgba(74, 124, 89, 0.08) 0%,
transparent 55%
),
radial-gradient(
circle at 80% 70%,
rgba(74, 124, 89, 0.05) 0%,
transparent 45%
);
}
.safe-top {
height: calc(var(--status-bar-height) + 12rpx);
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16rpx 0 16rpx;
}
.header-title {
font-size: 34rpx;
font-weight: 700;
color: #1f2d3d;
}
.header-actions {
display: flex;
align-items: center;
}
.action-item {
width: 56rpx;
height: 56rpx;
border-radius: 50%;
background: #ffffff;
margin-left: 16rpx;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 18rpx rgba(74, 124, 89, 0.1);
}
.user-card {
background: #ffffff;
border-radius: 28rpx;
padding: 24rpx;
display: flex;
align-items: center;
justify-content: space-between;
box-shadow: 0 16rpx 32rpx rgba(74, 124, 89, 0.1);
}
.user-left {
display: flex;
align-items: center;
}
.avatar-wrap {
position: relative;
}
.avatar {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
background: #f2f5f1;
display: flex;
align-items: center;
justify-content: center;
border: 4rpx solid rgba(74, 124, 89, 0.12);
}
.verified {
position: absolute;
right: 0;
bottom: 4rpx;
width: 32rpx;
height: 32rpx;
border-radius: 50%;
background: #4a7c59;
display: flex;
align-items: center;
justify-content: center;
border: 3rpx solid #ffffff;
}
.user-info {
margin-left: 20rpx;
}
.user-name {
display: block;
font-size: 30rpx;
font-weight: 700;
color: #243244;
}
.user-tags {
margin-top: 10rpx;
display: flex;
align-items: center;
}
.login-tip {
margin-top: 10rpx;
}
.login-text {
font-size: 22rpx;
color: #94a3b8;
}
.tag {
padding: 4rpx 12rpx;
background: #f1f5f9;
border-radius: 999rpx;
font-size: 20rpx;
font-weight: 600;
color: #64748b;
margin-right: 12rpx;
}
.vip-tag {
display: flex;
align-items: center;
background: rgba(74, 124, 89, 0.12);
padding: 4rpx 12rpx;
border-radius: 999rpx;
}
.vip-text {
font-size: 20rpx;
color: #4a7c59;
font-weight: 600;
margin-left: 6rpx;
}
.primary-btn {
padding: 12rpx 24rpx;
border-radius: 999rpx;
background: #4a7c59;
color: #ffffff;
font-size: 22rpx;
font-weight: 600;
}
.stats-card {
margin-top: 20rpx;
background: rgba(255, 255, 255, 0.9);
border-radius: 24rpx;
display: flex;
justify-content: space-between;
padding: 20rpx 12rpx;
box-shadow: 0 12rpx 24rpx rgba(74, 124, 89, 0.08);
}
.stat-item {
flex: 1;
text-align: center;
border-right: 1px solid #eef2f7;
}
.stat-item:last-child {
border-right: none;
}
.stat-value {
display: block;
font-size: 30rpx;
font-weight: 700;
color: #4a7c59;
}
.stat-label {
display: block;
margin-top: 6rpx;
font-size: 20rpx;
color: #94a3b8;
}
.section {
margin-top: 28rpx;
}
.section-title {
display: block;
font-size: 22rpx;
font-weight: 700;
color: #94a3b8;
letter-spacing: 2rpx;
margin-bottom: 12rpx;
}
.section-body {
background: #ffffff;
border-radius: 24rpx;
overflow: hidden;
box-shadow: 0 12rpx 24rpx rgba(74, 124, 89, 0.08);
}
.row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 20rpx;
border-bottom: 1px solid #f1f5f9;
}
.row:last-child {
border-bottom: none;
}
.row-left {
display: flex;
align-items: center;
}
.row-icon {
width: 64rpx;
height: 64rpx;
border-radius: 18rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16rpx;
}
.row-title {
font-size: 26rpx;
color: #1f2d3d;
}
.logout-wrap {
margin-top: 24rpx;
text-align: center;
}
.logout-btn {
background: rgba(255, 255, 255, 0.8);
border-radius: 20rpx;
padding: 20rpx 0;
font-size: 26rpx;
font-weight: 700;
color: #f87171;
box-shadow: 0 12rpx 24rpx rgba(74, 124, 89, 0.08);
}
.version {
display: block;
margin-top: 16rpx;
font-size: 20rpx;
color: #94a3b8;
}
</style>