feat(miniprogram): 访客模式 + 长辈模式 + MCP 自动化脚本
访客模式: - 未登录用户可见首页(轮播图+健康资讯+登录引导)和"我的"页面 - 健康和消息 tab 显示 GuestGuard 登录拦截 - 登录页增加"暂不登录,先看看"跳过入口 - 401 拦截器增加 hasToken 检查,避免访客被重定向到登录页 - 退出登录后 reLaunch 到首页而非登录页 长辈模式: - 新增 stores/ui.ts 管理显示模式(标准/长辈) - 长辈模式放大字体 ×1.3、间距 ×1.2、按钮加大 - "我的 → 账号 → 长辈模式"切换页 - 设置持久化到 Storage 修复: - Health/Messages 页面 Hooks 顺序违规(条件 return 在 hooks 之间) 导致访客模式下页面白屏,所有 hooks 移到条件判断之前 工程: - scripts/mpsync.sh/ps1 自动清理残留 DevTools 进程 - project.config.json 默认关闭域名校验
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { View, Text } from '@tarojs/components';
|
||||
import { useState } from 'react';
|
||||
import { View, Text, Swiper, SwiperItem } from '@tarojs/components';
|
||||
import { useState, useCallback } from 'react';
|
||||
import Taro, { useDidShow, usePullDownRefresh } from '@tarojs/taro';
|
||||
import { useAuthStore } from '../../stores/auth';
|
||||
import { useUIStore } from '../../stores/ui';
|
||||
import { useHealthStore } from '../../stores/health';
|
||||
import ProgressRing from '../../components/ProgressRing';
|
||||
import Loading from '../../components/Loading';
|
||||
@@ -10,6 +11,7 @@ import * as appointmentApi from '@/services/appointment';
|
||||
import * as followupApi from '@/services/followup';
|
||||
import { listPendingSuggestions, type AiSuggestionItem } from '@/services/ai-analysis';
|
||||
import { notificationService } from '@/services/notification';
|
||||
import * as articleApi from '@/services/article';
|
||||
import './index.scss';
|
||||
|
||||
interface ReminderItem {
|
||||
@@ -19,7 +21,103 @@ interface ReminderItem {
|
||||
tag: string;
|
||||
}
|
||||
|
||||
export default function Index() {
|
||||
// ─── 访客首页 ───
|
||||
|
||||
const CAROUSEL_SLIDES = [
|
||||
{ id: 'slide-1', title: '专业血透中心', desc: '三甲级医护团队全程守护' },
|
||||
{ id: 'slide-2', title: '智慧健康管理', desc: 'AI 驱动个性化健康方案' },
|
||||
{ id: 'slide-3', title: '温馨就医环境', desc: '舒适安全的治疗体验' },
|
||||
];
|
||||
|
||||
function GuestHome({ modeClass }: { modeClass: string }) {
|
||||
const [articles, setArticles] = useState<articleApi.Article[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useDidShow(() => {
|
||||
loadArticles();
|
||||
trackPageView('guest-home');
|
||||
});
|
||||
|
||||
const loadArticles = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await articleApi.listArticles({ page: 1, page_size: 4 });
|
||||
setArticles(res.data || []);
|
||||
} catch {
|
||||
// 文章加载失败不阻塞
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<View className={`guest-page ${modeClass}`}>
|
||||
{/* 轮播图 */}
|
||||
<Swiper
|
||||
className='guest-swiper'
|
||||
indicatorDots
|
||||
indicatorColor='rgba(255,255,255,0.4)'
|
||||
indicatorActiveColor='#FFFFFF'
|
||||
autoplay
|
||||
circular
|
||||
interval={4000}
|
||||
duration={500}
|
||||
>
|
||||
{CAROUSEL_SLIDES.map((slide) => (
|
||||
<SwiperItem key={slide.id}>
|
||||
<View className='guest-slide'>
|
||||
<View className='guest-slide-bg guest-slide-bg--1' />
|
||||
<View className='guest-slide-content'>
|
||||
<Text className='guest-slide-title'>{slide.title}</Text>
|
||||
<Text className='guest-slide-desc'>{slide.desc}</Text>
|
||||
</View>
|
||||
</View>
|
||||
</SwiperItem>
|
||||
))}
|
||||
</Swiper>
|
||||
|
||||
{/* 健康资讯 */}
|
||||
<View className='guest-section'>
|
||||
<Text className='guest-section-title'>健康资讯</Text>
|
||||
{loading ? (
|
||||
<Loading />
|
||||
) : articles.length > 0 ? (
|
||||
<View className='guest-articles'>
|
||||
{articles.map((a) => (
|
||||
<View
|
||||
key={a.id}
|
||||
className='guest-article-card'
|
||||
onClick={() => Taro.navigateTo({ url: `/pages/article/detail/index?id=${a.id}` })}
|
||||
>
|
||||
<Text className='guest-article-title'>{a.title}</Text>
|
||||
{a.summary && <Text className='guest-article-summary'>{a.summary}</Text>}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
) : (
|
||||
<View className='guest-empty'>
|
||||
<Text className='guest-empty-text'>暂无文章</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* 底部登录引导 */}
|
||||
<View className='guest-login-prompt'>
|
||||
<Text className='guest-login-text'>登录后即可使用完整健康管理服务</Text>
|
||||
<View
|
||||
className='guest-login-btn'
|
||||
onClick={() => Taro.navigateTo({ url: '/pages/login/index' })}
|
||||
>
|
||||
<Text className='guest-login-btn-text'>立即登录</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── 登录后首页 ───
|
||||
|
||||
function HomeDashboard({ modeClass }: { modeClass: string }) {
|
||||
const { user, currentPatient } = useAuthStore();
|
||||
const { todaySummary, loading, refreshToday } = useHealthStore();
|
||||
const [reminders, setReminders] = useState<ReminderItem[]>([]);
|
||||
@@ -55,7 +153,6 @@ export default function Index() {
|
||||
setRemindersLoading(true);
|
||||
try {
|
||||
const items: ReminderItem[] = [];
|
||||
|
||||
const [apptRes, taskRes, suggestRes] = await Promise.allSettled([
|
||||
appointmentApi.listAppointments(patientId, 1),
|
||||
followupApi.listTasks(patientId, 'pending'),
|
||||
@@ -64,15 +161,9 @@ export default function Index() {
|
||||
|
||||
if (suggestRes.status === 'fulfilled') {
|
||||
for (const s of suggestRes.value.data.slice(0, 1)) {
|
||||
items.push({
|
||||
id: s.id,
|
||||
text: buildSuggestionText(s),
|
||||
type: 'ai',
|
||||
tag: 'AI 建议',
|
||||
});
|
||||
items.push({ id: s.id, text: buildSuggestionText(s), type: 'ai', tag: 'AI 建议' });
|
||||
}
|
||||
}
|
||||
|
||||
if (apptRes.status === 'fulfilled') {
|
||||
for (const a of apptRes.value.data.slice(0, 1)) {
|
||||
if (a.status === 'pending' || a.status === 'confirmed') {
|
||||
@@ -85,7 +176,6 @@ export default function Index() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (taskRes.status === 'fulfilled') {
|
||||
for (const t of taskRes.value.data.slice(0, 1)) {
|
||||
items.push({
|
||||
@@ -96,7 +186,6 @@ export default function Index() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setReminders(items.slice(0, 3));
|
||||
} catch {
|
||||
setReminders([]);
|
||||
@@ -110,12 +199,7 @@ export default function Index() {
|
||||
const displayName = user?.display_name || currentPatient?.name || '访客';
|
||||
|
||||
const summary = todaySummary || {};
|
||||
const indicators = [
|
||||
!!summary.blood_pressure,
|
||||
!!summary.heart_rate,
|
||||
!!summary.blood_sugar,
|
||||
!!summary.weight,
|
||||
];
|
||||
const indicators = [!!summary.blood_pressure, !!summary.heart_rate, !!summary.blood_sugar, !!summary.weight];
|
||||
const completedCount = indicators.filter(Boolean).length;
|
||||
const progressPercent = Math.round((completedCount / 4) * 100);
|
||||
|
||||
@@ -140,7 +224,7 @@ export default function Index() {
|
||||
};
|
||||
|
||||
return (
|
||||
<View className='home-page'>
|
||||
<View className={`home-page ${modeClass}`}>
|
||||
{/* 问候区 */}
|
||||
<View className='greeting-section'>
|
||||
<View className='greeting-left'>
|
||||
@@ -149,20 +233,14 @@ export default function Index() {
|
||||
{new Date().toLocaleDateString('zh-CN', { month: 'long', day: 'numeric', weekday: 'short' })}
|
||||
</Text>
|
||||
</View>
|
||||
<View
|
||||
className='greeting-bell'
|
||||
onClick={() => Taro.switchTab({ url: '/pages/messages/index' })}
|
||||
>
|
||||
<View className='greeting-bell' onClick={() => Taro.switchTab({ url: '/pages/messages/index' })}>
|
||||
<Text className='greeting-bell-icon'>消</Text>
|
||||
{unreadCount > 0 && <View className='greeting-bell-dot' />}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 今日体征进度 */}
|
||||
<View
|
||||
className='checkin-card'
|
||||
onClick={() => Taro.switchTab({ url: '/pages/health/index' })}
|
||||
>
|
||||
<View className='checkin-card' onClick={() => Taro.switchTab({ url: '/pages/health/index' })}>
|
||||
<View className='checkin-left'>
|
||||
<ProgressRing percent={progressPercent} />
|
||||
</View>
|
||||
@@ -172,10 +250,7 @@ export default function Index() {
|
||||
</Text>
|
||||
<View className='checkin-capsules'>
|
||||
{indicatorCapsules.map((cap) => (
|
||||
<Text
|
||||
key={cap.label}
|
||||
className={`capsule ${cap.done ? 'capsule-done' : 'capsule-pending'}`}
|
||||
>
|
||||
<Text key={cap.label} className={`capsule ${cap.done ? 'capsule-done' : 'capsule-pending'}`}>
|
||||
{cap.done ? '✓ ' : ''}{cap.label}
|
||||
</Text>
|
||||
))}
|
||||
@@ -226,11 +301,8 @@ export default function Index() {
|
||||
key={r.id}
|
||||
className={`reminder-item ${i > 0 ? 'reminder-item-border' : ''}`}
|
||||
onClick={() => {
|
||||
if (r.type === 'appointment') {
|
||||
Taro.navigateTo({ url: '/pages/appointment/index' });
|
||||
} else if (r.type === 'followup') {
|
||||
Taro.navigateTo({ url: `/pages/followup/detail/index?id=${r.id}` });
|
||||
}
|
||||
if (r.type === 'appointment') Taro.navigateTo({ url: '/pages/appointment/index' });
|
||||
else if (r.type === 'followup') Taro.navigateTo({ url: `/pages/followup/detail/index?id=${r.id}` });
|
||||
}}
|
||||
>
|
||||
<Text className='reminder-tag'>{r.tag}</Text>
|
||||
@@ -243,16 +315,10 @@ export default function Index() {
|
||||
|
||||
{/* 快捷操作 */}
|
||||
<View className='action-section'>
|
||||
<View
|
||||
className='action-btn action-primary'
|
||||
onClick={() => Taro.switchTab({ url: '/pages/health/index' })}
|
||||
>
|
||||
<View className='action-btn action-primary' onClick={() => Taro.switchTab({ url: '/pages/health/index' })}>
|
||||
<Text className='action-btn-text'>记录体征</Text>
|
||||
</View>
|
||||
<View
|
||||
className='action-btn action-outline'
|
||||
onClick={() => Taro.navigateTo({ url: '/pages/appointment/create/index' })}
|
||||
>
|
||||
<View className='action-btn action-outline' onClick={() => Taro.navigateTo({ url: '/pages/appointment/create/index' })}>
|
||||
<Text className='action-btn-text'>预约挂号</Text>
|
||||
</View>
|
||||
</View>
|
||||
@@ -260,12 +326,21 @@ export default function Index() {
|
||||
);
|
||||
}
|
||||
|
||||
// ─── 首页入口:根据登录状态切换 ───
|
||||
|
||||
export default function Index() {
|
||||
const user = useAuthStore((s) => s.user);
|
||||
const mode = useUIStore((s) => s.mode);
|
||||
const modeClass = mode === 'elder' ? 'elder-mode' : '';
|
||||
|
||||
if (!user) {
|
||||
return <GuestHome modeClass={modeClass} />;
|
||||
}
|
||||
return <HomeDashboard modeClass={modeClass} />;
|
||||
}
|
||||
|
||||
function buildSuggestionText(s: AiSuggestionItem): string {
|
||||
const riskMap: Record<string, string> = {
|
||||
high: '高风险',
|
||||
medium: '中风险',
|
||||
low: '低风险',
|
||||
};
|
||||
const riskMap: Record<string, string> = { high: '高风险', medium: '中风险', low: '低风险' };
|
||||
const typeMap: Record<string, string> = {
|
||||
vital_sign_anomaly: '体征异常',
|
||||
lab_result_anomaly: '化验异常',
|
||||
|
||||
Reference in New Issue
Block a user