From d38b912d4d6e7ec3afc87d74f1a8eb643b254319 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 26 Apr 2022 20:47:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E9=85=8D=E7=BD=AE=E8=8E=B7=E5=8F=96=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/index.tsx | 1 + shared/model/config.ts | 12 +----------- web/src/init.tsx | 11 +++++++++++ 3 files changed, 13 insertions(+), 11 deletions(-) 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); +});