diff --git a/src/main.ts b/src/main.ts index ab45c37..f1805be 100644 --- a/src/main.ts +++ b/src/main.ts @@ -70,9 +70,10 @@ const parseCurrentOrgIdFromToken = (token: string | null): string | undefined => }; router.beforeEach(async (to, from , next) => { + try { document.title = to.meta.title as string; let { store, read, login, logout, chooseRole, getUnreadTongzhis, set_editing } = useUser(); - let { store: orgStore, loadMyOrgs, switchOrg, loadMyDepartments } = useOrg(); + let { store: orgStore, loadMyOrgs, switchOrg, loadMyDepartments, switchDepartment } = useOrg(); set_editing(false) store.unionid = (store.unionid || cookie.get(HtyUnionIDToken) || '').toString(); if (!store.current.hty_id) { @@ -173,8 +174,10 @@ router.beforeEach(async (to, from , next) => { if (currentAuthToken) { window.localStorage.setItem(HtySudoToken, currentAuthToken); } - // load departments after org switch (single-department transparent) await loadMyDepartments(); + if (orgStore.departments.length === 1 && orgStore.currentDepartmentId) { + await switchDepartment(orgStore.currentDepartmentId); + } } else if (organizations.length > 1) { await router.replace('/org/select'); next(); @@ -184,9 +187,11 @@ router.beforeEach(async (to, from , next) => { window.localStorage.setItem(CurrentOrgId, tokenOrgId); orgStore.currentOrgId = tokenOrgId; } - // load departments if not already loaded (after org context is established) if (orgStore.currentOrgId && orgStore.departments.length === 0) { await loadMyDepartments(); + if (orgStore.departments.length === 1 && orgStore.currentDepartmentId) { + await switchDepartment(orgStore.currentDepartmentId); + } } } @@ -197,7 +202,10 @@ router.beforeEach(async (to, from , next) => { } next(); + } catch (e: any) { + window.localStorage.setItem('__guardError', e?.message || String(e)); + next(); + } }) createApp(App).use(router).use(weixin).mount('#app') -