1111
This commit is contained in:
@@ -0,0 +1,638 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { Button as VanButton, showConfirmDialog, showToast } from 'vant'
|
||||
import AppTabBar from '../components/AppTabBar.vue'
|
||||
import { clearTokens } from '../services/auth'
|
||||
import { healthApi, type Dashboard, type HealthAssessmentOutput } from '../services/health'
|
||||
|
||||
const router = useRouter()
|
||||
const loading = ref(true)
|
||||
const dashboard = ref<Dashboard>()
|
||||
const assessment = ref<HealthAssessmentOutput>()
|
||||
|
||||
async function loadData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const [dashRes, assessRes] = await Promise.all([
|
||||
healthApi.dashboard(),
|
||||
healthApi.getAssessment().catch(() => undefined)
|
||||
])
|
||||
dashboard.value = dashRes
|
||||
assessment.value = assessRes
|
||||
} catch (err) {
|
||||
showToast(err instanceof Error ? err.message : '加载失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const bmiDisplay = computed(() => {
|
||||
if (dashboard.value?.bmi) {
|
||||
return {
|
||||
val: dashboard.value.bmi,
|
||||
status: dashboard.value.bmiStatus || '正常'
|
||||
}
|
||||
}
|
||||
if (assessment.value?.bmi) {
|
||||
return {
|
||||
val: assessment.value.bmi,
|
||||
status: assessment.value.bmiStatus || '正常'
|
||||
}
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
const ageDisplay = computed(() => {
|
||||
const raw = dashboard.value?.profile?.birthday || assessment.value?.basicInfo.birthday
|
||||
if (!raw) return undefined
|
||||
const birthday = new Date(raw)
|
||||
const today = new Date()
|
||||
let age = today.getFullYear() - birthday.getFullYear()
|
||||
if (today < new Date(today.getFullYear(), birthday.getMonth(), birthday.getDate())) age--
|
||||
return age
|
||||
})
|
||||
|
||||
// 根据评估答案提取体质标签
|
||||
const profileTags = computed(() => {
|
||||
const ans = assessment.value?.answers
|
||||
if (!ans || !assessment.value?.hasCompletedAssessment) return []
|
||||
|
||||
const list: { label: string; desc: string; type: 'gold' | 'blue' | 'green' | 'purple' }[] = []
|
||||
|
||||
if (ans.temperaturePreference === 'heat_fear') {
|
||||
list.push({ label: '体感燥热偏温', desc: '除湿机清爽48% · 床垫低档加热', type: 'blue' })
|
||||
} else if (ans.temperaturePreference === 'cold_fear') {
|
||||
list.push({ label: '体质畏寒怕冷', desc: '除湿机温润58% · 床垫加强加热', type: 'gold' })
|
||||
} else {
|
||||
list.push({ label: '冷热适中平衡', desc: '标准舒适温湿度', type: 'green' })
|
||||
}
|
||||
|
||||
if (ans.fallingAsleepSpeed === 'hard') {
|
||||
list.push({ label: '睡前敏感易失眠', desc: '2200K超暖暗光 · 音箱睡眠模式', type: 'purple' })
|
||||
} else if (ans.fallingAsleepSpeed === 'fast') {
|
||||
list.push({ label: '快速深度睡眠', desc: '自然转场柔光', type: 'green' })
|
||||
}
|
||||
|
||||
if (ans.muscleFatigueArea === 'waist_back' || ans.muscleFatigueArea === 'back_neck') {
|
||||
list.push({ label: '脊柱腰背劳损', desc: '床垫启用智能腰托模式', type: 'gold' })
|
||||
}
|
||||
|
||||
if (ans.lateNightEating === 'often' || ans.lateNightEating === 'sometimes' || ans.flavorPreference === 'heavy') {
|
||||
list.push({ label: '晚间进食空气净化', desc: '除湿机UV紫外消杀已启用', type: 'purple' })
|
||||
}
|
||||
|
||||
return list
|
||||
})
|
||||
|
||||
function handleLogout() {
|
||||
showConfirmDialog({
|
||||
title: '确认退出',
|
||||
message: '确定要退出当前账号登录吗?'
|
||||
}).then(() => {
|
||||
clearTokens()
|
||||
showToast('已安全退出')
|
||||
router.replace('/auth')
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="profile-page">
|
||||
<!-- 顶部用户卡片 -->
|
||||
<header class="profile-header">
|
||||
<div class="user-row">
|
||||
<div class="avatar-box">
|
||||
<span>{{ (dashboard?.user.displayName || '客').slice(0, 1) }}</span>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<h2>{{ dashboard?.user.displayName || '尊贵会员' }}</h2>
|
||||
<p class="phone-text">{{ dashboard?.user.phone || '健康管理账号' }}</p>
|
||||
<span class="user-badge">常青树 · 智能健康睡眠会员</span>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="profile-content">
|
||||
<!-- 身体指标基线档案 -->
|
||||
<section class="profile-card">
|
||||
<div class="card-head">
|
||||
<h3>身体基线档案</h3>
|
||||
<button class="edit-btn" @click="router.push('/assessment')">编辑指标</button>
|
||||
</div>
|
||||
|
||||
<div class="metrics-grid">
|
||||
<div class="metric-item">
|
||||
<span class="m-label">性别</span>
|
||||
<strong class="m-val">{{ dashboard?.profile?.gender || assessment?.basicInfo.gender || '已保密' }}</strong>
|
||||
</div>
|
||||
<div class="metric-item">
|
||||
<span class="m-label">身高</span>
|
||||
<strong class="m-val">{{ dashboard?.profile?.heightCm || assessment?.basicInfo.heightCm || '--' }} <small>cm</small></strong>
|
||||
</div>
|
||||
<div class="metric-item">
|
||||
<span class="m-label">年龄</span>
|
||||
<strong class="m-val">{{ ageDisplay ?? '--' }} <small>岁</small></strong>
|
||||
</div>
|
||||
<div class="metric-item">
|
||||
<span class="m-label">体重</span>
|
||||
<strong class="m-val">{{ dashboard?.profile?.weightKg || assessment?.basicInfo.weightKg || '--' }} <small>kg</small></strong>
|
||||
</div>
|
||||
<div class="metric-item">
|
||||
<span class="m-label">BMI 指数</span>
|
||||
<strong class="m-val" :class="{ highlight: bmiDisplay }">
|
||||
{{ bmiDisplay?.val || '--' }}
|
||||
</strong>
|
||||
<span class="m-status-tag" v-if="bmiDisplay">{{ bmiDisplay.status }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 专属评估画像标签 -->
|
||||
<section class="profile-card">
|
||||
<div class="card-head">
|
||||
<h3>健康评估画像与专属策略</h3>
|
||||
<span class="status-indicator" :class="{ done: assessment?.hasCompletedAssessment }">
|
||||
{{ assessment?.hasCompletedAssessment ? '已完成评估' : '未评估' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="assessment?.hasCompletedAssessment && profileTags.length > 0" class="tags-container">
|
||||
<div
|
||||
v-for="(tag, idx) in profileTags"
|
||||
:key="idx"
|
||||
class="profile-tag-item"
|
||||
:class="'theme-' + tag.type"
|
||||
>
|
||||
<div class="tag-title">{{ tag.label }}</div>
|
||||
<div class="tag-desc">{{ tag.desc }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
<p>您尚未完成身体健康评估,全屋智能家具当前使用出厂默认参数运行。</p>
|
||||
<VanButton
|
||||
type="primary"
|
||||
size="small"
|
||||
round
|
||||
color="#0c5045"
|
||||
@click="router.push('/assessment')"
|
||||
>
|
||||
立即进行健康评估
|
||||
</VanButton>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 当前健康方案 -->
|
||||
<section class="profile-card" v-if="dashboard?.currentPlan">
|
||||
<div class="card-head">
|
||||
<h3>当前执行方案</h3>
|
||||
<span class="version-tag">版本 v{{ dashboard.currentPlan.version }}.0</span>
|
||||
</div>
|
||||
<p class="plan-summary-text">{{ dashboard.currentPlan.summary }}</p>
|
||||
|
||||
<div class="plan-items-list">
|
||||
<div
|
||||
v-for="(item, i) in dashboard.currentPlan.items"
|
||||
:key="i"
|
||||
class="plan-row"
|
||||
>
|
||||
<div class="plan-row-head">
|
||||
<span class="dot"></span>
|
||||
<strong>{{ item.title }}</strong>
|
||||
</div>
|
||||
<p class="plan-target">目标:{{ item.target }}</p>
|
||||
<p class="plan-advice">指导:{{ item.advice }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 快捷功能入口与操作菜单 -->
|
||||
<section class="action-card-menu">
|
||||
<div class="menu-item" @click="router.push('/assessment')">
|
||||
<div class="menu-left">
|
||||
<div class="menu-icon icon-assess">
|
||||
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
||||
<polyline points="14 2 14 8 20 8" />
|
||||
<line x1="16" y1="13" x2="8" y2="13" />
|
||||
<line x1="16" y1="17" x2="8" y2="17" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="menu-text">
|
||||
<strong>重新进行健康评估</strong>
|
||||
<small>更新身体指标,重新智能推导家具启动参数</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="arrow">></span>
|
||||
</div>
|
||||
|
||||
<div class="menu-item" @click="router.push('/device-control')">
|
||||
<div class="menu-left">
|
||||
<div class="menu-icon icon-device">
|
||||
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<rect x="4" y="4" width="16" height="16" rx="2" />
|
||||
<rect x="9" y="9" width="6" height="6" />
|
||||
<line x1="9" y1="1" x2="9" y2="4" />
|
||||
<line x1="15" y1="1" x2="15" y2="4" />
|
||||
<line x1="9" y1="20" x2="9" y2="23" />
|
||||
<line x1="15" y1="20" x2="15" y2="23" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="menu-text">
|
||||
<strong>设备详情与参数调节</strong>
|
||||
<small>查看7台设备状态、独立开关与精细参数设置</small>
|
||||
</div>
|
||||
</div>
|
||||
<span class="arrow">></span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 退出登录按钮 -->
|
||||
<div class="logout-wrap">
|
||||
<button class="logout-btn" @click="handleLogout">
|
||||
退出登录
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- 固定底部导航栏 -->
|
||||
<AppTabBar />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.profile-page {
|
||||
padding-bottom: 90px;
|
||||
background: #f2f0e9;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.profile-header {
|
||||
background: linear-gradient(135deg, #0c5045, #123d36);
|
||||
color: #fff;
|
||||
padding: 34px 20px 28px;
|
||||
border-radius: 0 0 32px 32px;
|
||||
box-shadow: 0 10px 30px rgba(12, 80, 69, 0.12);
|
||||
}
|
||||
|
||||
.user-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.avatar-box {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #d6a657, #b88636);
|
||||
color: #fff;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-size: 26px;
|
||||
font-family: serif;
|
||||
font-weight: 700;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
border: 2px solid rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.user-info h2 {
|
||||
margin: 0 0 4px;
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.phone-text {
|
||||
margin: 0 0 6px;
|
||||
font-size: 12px;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
|
||||
.user-badge {
|
||||
display: inline-block;
|
||||
font-size: 11px;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
color: #ffe6ba;
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.profile-content {
|
||||
padding: 16px 14px;
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20px;
|
||||
padding: 18px 16px;
|
||||
margin-bottom: 14px;
|
||||
box-shadow: 0 4px 18px rgba(18, 63, 55, 0.04);
|
||||
border: 1px solid rgba(18, 63, 55, 0.06);
|
||||
}
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.card-head h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
color: #123f37;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.edit-btn {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #0c5045;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
font-size: 11px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 10px;
|
||||
background: #f0f0ed;
|
||||
color: #88948e;
|
||||
}
|
||||
|
||||
.status-indicator.done {
|
||||
background: #eef6f3;
|
||||
color: #0c5045;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.metrics-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.metric-item {
|
||||
background: #f8f7f3;
|
||||
border-radius: 12px;
|
||||
padding: 10px 6px;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.m-label {
|
||||
font-size: 11px;
|
||||
color: #798a83;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.m-val {
|
||||
font-size: 15px;
|
||||
color: #173d36;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.m-val small {
|
||||
font-size: 10px;
|
||||
color: #8fa099;
|
||||
}
|
||||
|
||||
.m-val.highlight {
|
||||
color: #0c5045;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.m-status-tag {
|
||||
font-size: 10px;
|
||||
color: #0c5045;
|
||||
background: rgba(12, 80, 69, 0.1);
|
||||
padding: 1px 6px;
|
||||
border-radius: 8px;
|
||||
margin-top: 4px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* 标签列表 */
|
||||
.tags-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.profile-tag-item {
|
||||
border-radius: 12px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid;
|
||||
}
|
||||
|
||||
.profile-tag-item.theme-gold {
|
||||
background: #fcf9f2;
|
||||
border-color: rgba(214, 166, 87, 0.3);
|
||||
}
|
||||
|
||||
.profile-tag-item.theme-gold .tag-title {
|
||||
color: #9c6c19;
|
||||
}
|
||||
|
||||
.profile-tag-item.theme-blue {
|
||||
background: #f3f8fd;
|
||||
border-color: rgba(66, 153, 225, 0.3);
|
||||
}
|
||||
|
||||
.profile-tag-item.theme-blue .tag-title {
|
||||
color: #2b6cb0;
|
||||
}
|
||||
|
||||
.profile-tag-item.theme-green {
|
||||
background: #f1f8f5;
|
||||
border-color: rgba(12, 80, 69, 0.2);
|
||||
}
|
||||
|
||||
.profile-tag-item.theme-green .tag-title {
|
||||
color: #0c5045;
|
||||
}
|
||||
|
||||
.profile-tag-item.theme-purple {
|
||||
background: #f8f4fd;
|
||||
border-color: rgba(159, 122, 234, 0.3);
|
||||
}
|
||||
|
||||
.profile-tag-item.theme-purple .tag-title {
|
||||
color: #6b46c1;
|
||||
}
|
||||
|
||||
.tag-title {
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.tag-desc {
|
||||
font-size: 11px;
|
||||
color: #60736c;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 16px 10px;
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
margin: 0 0 12px;
|
||||
font-size: 12px;
|
||||
color: #84968f;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* 方案卡片 */
|
||||
.version-tag {
|
||||
font-size: 11px;
|
||||
color: #0c5045;
|
||||
background: #eef6f3;
|
||||
padding: 2px 8px;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.plan-summary-text {
|
||||
margin: 0 0 14px;
|
||||
font-size: 12px;
|
||||
color: #556c64;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.plan-items-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.plan-row {
|
||||
background: #f9f8f4;
|
||||
border-radius: 12px;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.plan-row-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.plan-row-head .dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: #0c5045;
|
||||
}
|
||||
|
||||
.plan-row-head strong {
|
||||
font-size: 13px;
|
||||
color: #173e37;
|
||||
}
|
||||
|
||||
.plan-target, .plan-advice {
|
||||
margin: 2px 0;
|
||||
font-size: 12px;
|
||||
color: #697c75;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* 菜单导航 */
|
||||
.action-card-menu {
|
||||
background: #ffffff;
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 16px;
|
||||
border: 1px solid rgba(18, 63, 55, 0.06);
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid rgba(18, 63, 55, 0.05);
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.menu-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.menu-item:active {
|
||||
background: #f8f7f3;
|
||||
}
|
||||
|
||||
.menu-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 10px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
.icon-assess {
|
||||
background: #eef7f3;
|
||||
color: #0c5045;
|
||||
}
|
||||
|
||||
.icon-device {
|
||||
background: #fbf5e8;
|
||||
color: #b07e26;
|
||||
}
|
||||
|
||||
.menu-text strong {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
color: #183e37;
|
||||
}
|
||||
|
||||
.menu-text small {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
color: #7b8e88;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
color: #b3bfb9;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.logout-wrap {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
width: 100%;
|
||||
padding: 13px 0;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgba(220, 70, 70, 0.25);
|
||||
background: #ffffff;
|
||||
color: #d64545;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
|
||||
}
|
||||
|
||||
.logout-btn:active {
|
||||
background: #fff5f5;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user