refactor(chat + workspace): chat和workspace重构,子路由、懒加载等
This commit is contained in:
1 parent
0a647a0b79
commit
1f1f7236b0
57 files changed
+4356
-3798
No files matched your search
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* features/auth/composables/useLogin.ts
|
||||
* 登录页编排层:组合认证、公告展示与 OAuth 回调,provide 给 LoginView 子组件。
|
||||
*/
|
||||
import { onMounted, reactive } from 'vue';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { config } from '@/config';
|
||||
import { useTheme } from '@/composables/useTheme';
|
||||
import { useMessage } from '@/composables/useMessage';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import loginBg from '@/assets/login-bg.png';
|
||||
import { DEFAULT_POST_LOGIN_AGENT_ID } from '@/features/workspace/types/workspace.types';
|
||||
import { useWorkspaceLocale } from '@/features/workspace/composables/useWorkspaceLocale';
|
||||
import { useLoginAuth } from './useLoginAuth';
|
||||
import { useLoginLanding } from './useLoginLanding';
|
||||
|
||||
export function useLogin() {
|
||||
const { t, locale } = useI18n();
|
||||
const msg = useMessage();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const authStore = useAuthStore();
|
||||
const { setThemePreference, appliedTheme } = useTheme();
|
||||
|
||||
const deps = { t, locale, msg, router, route, setThemePreference, appliedTheme };
|
||||
const landing = useLoginLanding();
|
||||
|
||||
const completePasswordLogin = async () => {
|
||||
authStore.syncFromStorage();
|
||||
await router.replace(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
|
||||
};
|
||||
|
||||
const completeOAuthLogin = async () => {
|
||||
authStore.syncFromStorage();
|
||||
await router.replace('/workspace/applications');
|
||||
};
|
||||
|
||||
const loginAuth = useLoginAuth(deps, { completePasswordLogin, completeOAuthLogin });
|
||||
const localeApi = useWorkspaceLocale(deps);
|
||||
|
||||
const loginBackgroundStyle = {
|
||||
backgroundImage: `url(${loginBg})`,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
localeApi.loadLanguagePreference();
|
||||
void landing.fetchAnnouncements();
|
||||
|
||||
const handledCasdoor = await loginAuth.tryCasdoorCallbackLogin();
|
||||
if (handledCasdoor) return;
|
||||
|
||||
const handledWecom = await loginAuth.tryWecomCallbackLogin();
|
||||
if (handledWecom) return;
|
||||
|
||||
authStore.syncFromStorage();
|
||||
if (authStore.isLoggedIn) {
|
||||
await router.replace('/workspace/applications');
|
||||
return;
|
||||
}
|
||||
|
||||
await landing.fetchPublicAgents();
|
||||
landing.isLoading.value = false;
|
||||
});
|
||||
|
||||
return reactive({
|
||||
config,
|
||||
msg,
|
||||
loginBackgroundStyle,
|
||||
...localeApi,
|
||||
...landing,
|
||||
...loginAuth,
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user