diff --git a/frontend/src/layout/index.vue b/frontend/src/layout/index.vue index 1991ee4b9..40ce76d41 100644 --- a/frontend/src/layout/index.vue +++ b/frontend/src/layout/index.vue @@ -24,6 +24,7 @@ import { useI18n } from 'vue-i18n'; import { useTheme } from '@/hooks/use-theme'; import { getLicense, getSettingInfo, getSystemAvailable } from '@/api/modules/setting'; import { useRoute, useRouter } from 'vue-router'; +import { initFavicon, resetXSetting } from '@/utils/xpack'; useResize(); const router = useRouter(); @@ -99,21 +100,14 @@ const loadDataFromXDB = async () => { globalStore.themeConfig.logoWithText = res.data.logoWithText; globalStore.themeConfig.favicon = res.data.favicon; } else { - resetSetting(); + resetXSetting(); } } else { - resetSetting(); + resetXSetting(); } initFavicon(); }; -const resetSetting = () => { - globalStore.themeConfig.title = ''; - globalStore.themeConfig.logo = ''; - globalStore.themeConfig.logoWithText = ''; - globalStore.themeConfig.favicon = ''; -}; - const loadProductProFromDB = async () => { const res = await getLicense(); if (!res.data) { @@ -143,15 +137,6 @@ const updateDarkMode = async (event: MediaQueryListEvent) => { switchDark(); }; -const initFavicon = () => { - let favicon = globalStore.themeConfig.favicon; - const link = (document.querySelector("link[rel*='icon']") || document.createElement('link')) as HTMLLinkElement; - link.type = 'image/x-icon'; - link.rel = 'shortcut icon'; - link.href = favicon ? '/api/v1/images/favicon' : '/public/favicon.png'; - document.getElementsByTagName('head')[0].appendChild(link); -}; - const loadStatus = async () => { loading.value = globalStore.isLoading; loadingText.value = globalStore.loadingText; diff --git a/frontend/src/utils/xpack.ts b/frontend/src/utils/xpack.ts new file mode 100644 index 000000000..86d737815 --- /dev/null +++ b/frontend/src/utils/xpack.ts @@ -0,0 +1,18 @@ +import { GlobalStore } from '@/store'; +const globalStore = GlobalStore(); + +export function resetXSetting() { + globalStore.themeConfig.title = ''; + globalStore.themeConfig.logo = ''; + globalStore.themeConfig.logoWithText = ''; + globalStore.themeConfig.favicon = ''; +} + +export function initFavicon() { + let favicon = globalStore.themeConfig.favicon; + const link = (document.querySelector("link[rel*='icon']") || document.createElement('link')) as HTMLLinkElement; + link.type = 'image/x-icon'; + link.rel = 'shortcut icon'; + link.href = favicon ? '/api/v1/images/favicon' : '/public/favicon.png'; + document.getElementsByTagName('head')[0].appendChild(link); +} diff --git a/frontend/src/views/login/components/login-form.vue b/frontend/src/views/login/components/login-form.vue index 069510b68..c74e84e79 100644 --- a/frontend/src/views/login/components/login-form.vue +++ b/frontend/src/views/login/components/login-form.vue @@ -157,6 +157,8 @@ import { GlobalStore, MenuStore, TabsStore } from '@/store'; import i18n from '@/lang'; import { MsgSuccess } from '@/utils/message'; import { useI18n } from 'vue-i18n'; +import { getLicense } from '@/api/modules/setting'; +import { initFavicon } from '@/utils/xpack'; const globalStore = GlobalStore(); const menuStore = MenuStore(); @@ -273,6 +275,7 @@ const login = (formEl: FormInstance | undefined) => { menuStore.setMenuList([]); tabsStore.removeAllTabs(); MsgSuccess(i18n.global.t('commons.msg.loginSuccess')); + loadProductProFromDB(); router.push({ name: 'home' }); } catch (error) { loginVerify(); @@ -299,6 +302,7 @@ const mfaLogin = async (auto: boolean) => { menuStore.setMenuList([]); tabsStore.removeAllTabs(); MsgSuccess(i18n.global.t('commons.msg.loginSuccess')); + loadProductProFromDB(); router.push({ name: 'home' }); } }; @@ -322,19 +326,29 @@ const loadLanguage = async () => { } catch (error) {} }; -const loadFavicon = () => { - let favicon = globalStore.themeConfig.favicon; - const link = (document.querySelector("link[rel*='icon']") || document.createElement('link')) as HTMLLinkElement; - link.type = 'image/x-icon'; - link.rel = 'shortcut icon'; - link.href = favicon ? '/api/v1/images/favicon' : '/public/favicon.png'; - document.getElementsByTagName('head')[0].appendChild(link); +const loadProductProFromDB = async () => { + const res = await getLicense(); + if (!res.data) { + globalStore.isProductPro = false; + return; + } + globalStore.isProductPro = + res.data.status === 'Enable' || res.data.status === 'Lost01' || res.data.status === 'Lost02'; + + if (globalStore.isProductPro) { + globalStore.productProExpires = Number(res.data.productPro); + } else { + globalStore.themeConfig.title = ''; + globalStore.themeConfig.logo = ''; + globalStore.themeConfig.logoWithText = ''; + globalStore.themeConfig.favicon = ''; + } }; onMounted(() => { globalStore.isOnRestart = false; loginVerify(); - loadFavicon(); + initFavicon(); loadLanguage(); document.title = globalStore.themeConfig.panelName; loginForm.agreeLicense = globalStore.agreeLicense; diff --git a/frontend/src/views/login/entrance/index.vue b/frontend/src/views/login/entrance/index.vue index 9a8350f96..f1dd1e3bf 100644 --- a/frontend/src/views/login/entrance/index.vue +++ b/frontend/src/views/login/entrance/index.vue @@ -50,6 +50,7 @@ import ErrDomain from '@/components/error-message/err_domain.vue'; import ErrFound from '@/components/error-message/404.vue'; import { ref, onMounted } from 'vue'; import { GlobalStore } from '@/store'; +import { initFavicon, resetXSetting } from '@/utils/xpack'; const globalStore = GlobalStore(); const screenWidth = ref(null); @@ -91,7 +92,7 @@ const getStatus = async () => { } globalStore.entrance = code; errStatus.value = ''; - loading.value = false; + loadDataFromXDB(); }) .catch((errRes) => { pageCode.value = pageCode.value || '200'; @@ -114,6 +115,34 @@ const getStatus = async () => { }); }; +const loadDataFromXDB = async () => { + const xpackModules = import.meta.globEager('../../../xpack/api/modules/*.ts'); + if (xpackModules['../../../xpack/api/modules/setting.ts']) { + const searchXSetting = xpackModules['../../../xpack/api/modules/setting.ts'].searchXSetting; + if (searchXSetting) { + await searchXSetting() + .then((res) => { + globalStore.themeConfig.title = res.data.title; + globalStore.themeConfig.logo = res.data.logo; + globalStore.themeConfig.logoWithText = res.data.logoWithText; + globalStore.themeConfig.favicon = res.data.favicon; + }) + .catch(() => { + loading.value = false; + resetXSetting(); + }); + } else { + loading.value = false; + resetXSetting(); + } + } else { + loading.value = false; + resetXSetting(); + } + loading.value = false; + initFavicon(); +}; + onMounted(() => { globalStore.isOnRestart = false; getStatus(); diff --git a/frontend/src/views/login/index.vue b/frontend/src/views/login/index.vue index 7bbc7e904..723cfc0eb 100644 --- a/frontend/src/views/login/index.vue +++ b/frontend/src/views/login/index.vue @@ -1,10 +1,10 @@