feat: 登陆时加载许可证状态 (#4520)

This commit is contained in:
ssongliu 2024-04-15 18:06:38 +08:00 committed by GitHub
parent b8a52ae707
commit 735fc75e35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 118 additions and 33 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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();

View File

@ -1,10 +1,10 @@
<template>
<div>
<div class="login-background">
<div class="login-background" v-loading="loading">
<div class="login-wrapper">
<div :class="screenWidth > 1110 ? 'left inline-block' : ''">
<div class="login-title">
<span>{{ globalStore.themeConfig.title || $t('setting.description') }}</span>
<span>{{ gStore.themeConfig.title || $t('setting.description') }}</span>
</div>
<img src="@/assets/images/1panel-login.png" alt="" v-if="screenWidth > 1110" />
</div>
@ -24,16 +24,55 @@ import LoginForm from './components/login-form.vue';
import { ref, onMounted } from 'vue';
import router from '@/routers';
import { GlobalStore } from '@/store';
import { initFavicon, resetXSetting } from '@/utils/xpack';
const globalStore = GlobalStore();
const gStore = GlobalStore();
const loading = ref();
const screenWidth = ref(null);
const getStatus = async () => {
const res = await checkIsSafety(globalStore.entrance);
loading.value = true;
await checkIsSafety(gStore.entrance)
.then((res) => {
if (res.data === 'unpass') {
router.replace({ name: 'entrance', params: { code: globalStore.entrance } });
loading.value = false;
router.replace({ name: 'entrance', params: { code: gStore.entrance } });
return;
}
loadDataFromXDB();
})
.catch(() => {
loading.value = false;
});
};
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((resItem) => {
gStore.themeConfig.title = resItem.data.title;
gStore.themeConfig.logo = resItem.data.logo;
gStore.themeConfig.logoWithText = resItem.data.logoWithText;
gStore.themeConfig.favicon = resItem.data.favicon;
})
.catch(() => {
loading.value = false;
resetXSetting();
});
} else {
loading.value = false;
resetXSetting();
}
} else {
loading.value = false;
resetXSetting();
}
loading.value = false;
initFavicon();
};
onMounted(() => {