diff --git a/shared/index.tsx b/shared/index.tsx index 86cadedc..a1cce942 100644 --- a/shared/index.tsx +++ b/shared/index.tsx @@ -84,6 +84,7 @@ export { // model export { fetchAvailableServices } from './model/common'; +export { fetchGlobalConfig } from './model/config'; export { createDMConverse, appendDMConverseMembers, diff --git a/shared/model/config.ts b/shared/model/config.ts index 26617875..295e11a0 100644 --- a/shared/model/config.ts +++ b/shared/model/config.ts @@ -1,6 +1,4 @@ import { request } from '../api/request'; -import { t } from '../i18n'; -import { showErrorToasts } from '../manager/ui'; /** * 后端的全局设置 @@ -23,7 +21,7 @@ export function getGlobalConfig() { }; } -export async function fetchConfig() { +export async function fetchGlobalConfig(): Promise { const { data: config } = await request.get('/api/config/global'); globalConfig = { @@ -33,11 +31,3 @@ export async function fetchConfig() { return config; } - -/** - * 加载时立即尝试执行 - */ -fetchConfig().catch((e) => { - showErrorToasts(t('全局配置加载失败')); - console.error('全局配置加载失败', e); -}); diff --git a/web/src/init.tsx b/web/src/init.tsx index 08f19505..65356e01 100644 --- a/web/src/init.tsx +++ b/web/src/init.tsx @@ -8,6 +8,9 @@ import { setStorage, setToasts, setTokenGetter, + showErrorToasts, + t, + fetchGlobalConfig, } from 'tailchat-shared'; import { getPopupContainer } from './utils/dom-helper'; import { getUserJWT } from './utils/jwt-helper'; @@ -50,3 +53,11 @@ setGlobalLoading((text) => { return hide; }); + +/** + * 初始化时加载全局配置 + */ +fetchGlobalConfig().catch((e) => { + showErrorToasts(t('全局配置加载失败')); + console.error('全局配置加载失败', e); +});