fix(mp): setTimeout 无清理修复 — useSafeTimeout hook + 10 页面接入
新增 useSafeTimeout hook,页面隐藏时自动清理所有定时器。 10 个页面接入:daily-monitoring、exchange、family-add、 health/input、prescription detail/create、dialysis detail/create、 appointment detail/create。所有 fire-and-forget setTimeout 替换为 safeSetTimeout,避免页面切走后定时器回调在错误上下文执行。
This commit is contained in:
@@ -8,6 +8,7 @@ import { trackEvent } from '@/services/analytics';
|
||||
import StepIndicator from '../../../components/StepIndicator';
|
||||
import WeekCalendar from '../../../components/WeekCalendar';
|
||||
import { useElderClass } from '../../../hooks/useElderClass';
|
||||
import { useSafeTimeout } from '@/hooks/useSafeTimeout';
|
||||
import './index.scss';
|
||||
|
||||
const DEPARTMENTS = [
|
||||
@@ -43,6 +44,7 @@ export default function AppointmentCreate() {
|
||||
const [timeSlot, setTimeSlot] = useState('');
|
||||
const [reason, setReason] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { safeSetTimeout } = useSafeTimeout();
|
||||
const [schedules, setSchedules] = useState<any[]>([]);
|
||||
const [timeSlots, setTimeSlots] = useState<TimeSlot[]>([]);
|
||||
const modeClass = useElderClass();
|
||||
@@ -127,7 +129,7 @@ export default function AppointmentCreate() {
|
||||
await (Taro.requestSubscribeMessage as any)({ tmplIds: [tmplId] });
|
||||
} catch { /* 用户拒绝 */ }
|
||||
}
|
||||
setTimeout(() => Taro.navigateBack(), 1500);
|
||||
safeSetTimeout(() => Taro.navigateBack(), 1500);
|
||||
} catch {
|
||||
Taro.showToast({ title: '预约失败', icon: 'none' });
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user