fix(miniprogram): 深度审查修复多个功能问题
Some checks failed
CI / security-audit (push) Has been cancelled
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled

- settings: 清除缓存不再错误读取明文 token,改由 auth store restore 恢复
- appointment: 移除多余的 detail_cache Storage 写入
- reports: 未选择就诊人时显示引导提示而非空白
- health/input: 血压录入验证舒张压必填
- followups: tab 切换时不再清空列表导致闪烁
This commit is contained in:
iven
2026-04-24 18:36:56 +08:00
parent 81cc84e4b2
commit a63043f447
5 changed files with 32 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
import React, { useState, useCallback, useRef } from 'react'; import React, { useState, useCallback, useRef } from 'react';
import { View, Text } from '@tarojs/components'; import { View, Text } from '@tarojs/components';
import Taro, { useDidShow, useReachBottom, usePullDownRefresh } from '@tarojs/taro'; import Taro, { useDidShow, useReachBottom, usePullDownRefresh } from '@tarojs/taro';
import { listAppointments, cancelAppointment } from '../../services/appointment'; import { listAppointments } from '../../services/appointment';
import type { Appointment } from '../../services/appointment'; import type { Appointment } from '../../services/appointment';
import EmptyState from '../../components/EmptyState'; import EmptyState from '../../components/EmptyState';
import Loading from '../../components/Loading'; import Loading from '../../components/Loading';
@@ -64,10 +64,6 @@ export default function AppointmentList() {
}; };
const goDetail = (id: string) => { const goDetail = (id: string) => {
const item = appointments.find((a) => a.id === id);
if (item) {
Taro.setStorageSync('appointment_detail_cache', item);
}
Taro.navigateTo({ url: `/pages/appointment/detail/index?id=${id}` }); Taro.navigateTo({ url: `/pages/appointment/detail/index?id=${id}` });
}; };

View File

@@ -51,13 +51,25 @@ export default function HealthInput() {
const currentIndicator = INDICATORS[indicatorIdx].value; const currentIndicator = INDICATORS[indicatorIdx].value;
if (currentIndicator === 'blood_pressure') {
if (!systolic || !diastolic) {
Taro.showToast({ title: '请填写收缩压和舒张压', icon: 'none' });
return;
}
} else {
if (!value) {
Taro.showToast({ title: '请输入数值', icon: 'none' });
return;
}
}
const input = currentIndicator === 'blood_pressure' const input = currentIndicator === 'blood_pressure'
? { indicator_type: 'blood_pressure' as const, value: parseFloat(systolic), extra: { systolic: parseFloat(systolic), diastolic: parseFloat(diastolic) } } ? { indicator_type: 'blood_pressure' as const, value: parseFloat(systolic), extra: { systolic: parseFloat(systolic), diastolic: parseFloat(diastolic) } }
: { indicator_type: currentIndicator as any, value: parseFloat(value) }; : { indicator_type: currentIndicator as any, value: parseFloat(value) };
const result = vitalSignSchema.safeParse(input); const result = vitalSignSchema.safeParse(input);
if (!result.success) { if (!result.success) {
Taro.showToast({ title: result.error.errors[0].message, icon: 'none' }); Taro.showToast({ title: result.error.issues[0].message, icon: 'none' });
return; return;
} }
@@ -77,7 +89,7 @@ export default function HealthInput() {
}); });
clearCache(); clearCache();
Taro.showToast({ title: '录入成功', icon: 'success' }); Taro.showToast({ title: '录入成功', icon: 'success' });
trackEvent('health_data_input', { type: indicatorType }); trackEvent('health_data_input', { type: currentIndicator });
setTimeout(() => Taro.navigateBack(), 1000); setTimeout(() => Taro.navigateBack(), 1000);
} catch (e: unknown) { } catch (e: unknown) {
const msg = e instanceof Error ? e.message : '录入失败'; const msg = e instanceof Error ? e.message : '录入失败';

View File

@@ -35,7 +35,6 @@ export default function MyFollowUps() {
const handleTabChange = (key: string) => { const handleTabChange = (key: string) => {
setActiveTab(key); setActiveTab(key);
setTasks([]);
fetchTasks(key); fetchTasks(key);
}; };

View File

@@ -6,8 +6,6 @@ import EmptyState from '../../../components/EmptyState';
import Loading from '../../../components/Loading'; import Loading from '../../../components/Loading';
import './index.scss'; import './index.scss';
const PAGE_SIZE = 20;
export default function MyReports() { export default function MyReports() {
const [reports, setReports] = useState<LabReport[]>([]); const [reports, setReports] = useState<LabReport[]>([]);
const [page, setPage] = useState(1); const [page, setPage] = useState(1);
@@ -16,7 +14,10 @@ export default function MyReports() {
const fetchData = useCallback(async (p: number, append = false) => { const fetchData = useCallback(async (p: number, append = false) => {
const patientId = Taro.getStorageSync('current_patient_id') || ''; const patientId = Taro.getStorageSync('current_patient_id') || '';
if (!patientId) return; if (!patientId) {
setReports([]);
return;
}
setLoading(true); setLoading(true);
try { try {
const res = await listReports(patientId, p); const res = await listReports(patientId, p);
@@ -80,7 +81,7 @@ export default function MyReports() {
</View> </View>
{reports.length === 0 && !loading && ( {reports.length === 0 && !loading && (
<EmptyState text='暂无报告记录' /> <EmptyState text={Taro.getStorageSync('current_patient_id') ? '暂无报告记录' : '请先在就诊人管理中选择就诊人'} />
)} )}
{loading && ( {loading && (

View File

@@ -13,23 +13,21 @@ export default function Settings() {
content: '确定要清除本地缓存数据吗?不会影响账号信息。', content: '确定要清除本地缓存数据吗?不会影响账号信息。',
}).then((res) => { }).then((res) => {
if (res.confirm) { if (res.confirm) {
// 保留登录态和核心设置 // 保留登录态和核心设置(使用明确的 key 列表,不依赖明文 token
const token = Taro.getStorageSync('access_token'); const preservedKeys = ['user', 'current_patient', 'current_patient_id', 'tenant_id', 'wechat_openid'];
const refreshToken = Taro.getStorageSync('refresh_token'); const preservedData: Record<string, unknown> = {};
const user = Taro.getStorageSync('user'); for (const key of preservedKeys) {
const currentPatient = Taro.getStorageSync('current_patient'); const val = Taro.getStorageSync(key);
const currentPatientId = Taro.getStorageSync('current_patient_id'); if (val) preservedData[key] = val;
const tenantId = Taro.getStorageSync('tenant_id'); }
Taro.clearStorageSync(); Taro.clearStorageSync();
// 恢复登录态 // 恢复非敏感数据
if (token) Taro.setStorageSync('access_token', token); for (const [key, val] of Object.entries(preservedData)) {
if (refreshToken) Taro.setStorageSync('refresh_token', refreshToken); Taro.setStorageSync(key, val);
if (user) Taro.setStorageSync('user', user); }
if (currentPatient) Taro.setStorageSync('current_patient', currentPatient); // 安全存储的 token 由 auth store restore() 在下次页面显示时自动恢复
if (currentPatientId) Taro.setStorageSync('current_patient_id', currentPatientId);
if (tenantId) Taro.setStorageSync('tenant_id', tenantId);
Taro.showToast({ title: '缓存已清除', icon: 'success' }); Taro.showToast({ title: '缓存已清除', icon: 'success' });
} }