- 新增 useNavigationState hook (saveDoctorPage/getDoctorLastPage) - 首页医生重定向使用 getDoctorLastPage 代替硬编码路径 - 医生端工作台入口自动保存最后访问路径 - 医生再次打开首页时自动回到上次使用的医生端页面
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { useCallback } from 'react';
|
|
import Taro from '@tarojs/taro';
|
|
import { useAuthStore } from '@/stores/auth';
|
|
|
|
const NAV_STATE_KEY = 'doctor_last_page';
|
|
|
|
const DOCTOR_PAGES = [
|
|
'/pages/pkg-doctor-core/index',
|
|
'/pages/pkg-doctor-core/patients/index',
|
|
'/pages/pkg-doctor-core/consultation/index',
|
|
'/pages/pkg-doctor-core/followup/index',
|
|
'/pages/pkg-doctor-core/action-inbox/index',
|
|
];
|
|
|
|
export function saveDoctorPage(path: string): void {
|
|
if (!path.startsWith('/pages/pkg-doctor')) return;
|
|
try {
|
|
Taro.setStorageSync(NAV_STATE_KEY, path);
|
|
} catch { /* ignore */ }
|
|
}
|
|
|
|
export function getDoctorLastPage(): string {
|
|
try {
|
|
const saved = Taro.getStorageSync(NAV_STATE_KEY);
|
|
if (saved && typeof saved === 'string' && saved.startsWith('/pages/pkg-doctor')) {
|
|
return saved;
|
|
}
|
|
} catch { /* ignore */ }
|
|
return DOCTOR_PAGES[0];
|
|
}
|
|
|
|
export function useNavigationState() {
|
|
const isDoctor = useAuthStore((s) => s.isDoctor);
|
|
|
|
const navigateToDoctorHome = useCallback(() => {
|
|
if (!isDoctor()) return false;
|
|
const lastPage = getDoctorLastPage();
|
|
Taro.navigateTo({ url: lastPage });
|
|
return true;
|
|
}, [isDoctor]);
|
|
|
|
return { navigateToDoctorHome, saveDoctorPage, getDoctorLastPage };
|
|
}
|