mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 16:29:17 +08:00
feat: 登陆时加载许可证状态 (#4520)
This commit is contained in:
parent
b8a52ae707
commit
735fc75e35
@ -24,6 +24,7 @@ import { useI18n } from 'vue-i18n';
|
|||||||
import { useTheme } from '@/hooks/use-theme';
|
import { useTheme } from '@/hooks/use-theme';
|
||||||
import { getLicense, getSettingInfo, getSystemAvailable } from '@/api/modules/setting';
|
import { getLicense, getSettingInfo, getSystemAvailable } from '@/api/modules/setting';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
import { initFavicon, resetXSetting } from '@/utils/xpack';
|
||||||
useResize();
|
useResize();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -99,21 +100,14 @@ const loadDataFromXDB = async () => {
|
|||||||
globalStore.themeConfig.logoWithText = res.data.logoWithText;
|
globalStore.themeConfig.logoWithText = res.data.logoWithText;
|
||||||
globalStore.themeConfig.favicon = res.data.favicon;
|
globalStore.themeConfig.favicon = res.data.favicon;
|
||||||
} else {
|
} else {
|
||||||
resetSetting();
|
resetXSetting();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resetSetting();
|
resetXSetting();
|
||||||
}
|
}
|
||||||
initFavicon();
|
initFavicon();
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetSetting = () => {
|
|
||||||
globalStore.themeConfig.title = '';
|
|
||||||
globalStore.themeConfig.logo = '';
|
|
||||||
globalStore.themeConfig.logoWithText = '';
|
|
||||||
globalStore.themeConfig.favicon = '';
|
|
||||||
};
|
|
||||||
|
|
||||||
const loadProductProFromDB = async () => {
|
const loadProductProFromDB = async () => {
|
||||||
const res = await getLicense();
|
const res = await getLicense();
|
||||||
if (!res.data) {
|
if (!res.data) {
|
||||||
@ -143,15 +137,6 @@ const updateDarkMode = async (event: MediaQueryListEvent) => {
|
|||||||
switchDark();
|
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 () => {
|
const loadStatus = async () => {
|
||||||
loading.value = globalStore.isLoading;
|
loading.value = globalStore.isLoading;
|
||||||
loadingText.value = globalStore.loadingText;
|
loadingText.value = globalStore.loadingText;
|
||||||
|
18
frontend/src/utils/xpack.ts
Normal file
18
frontend/src/utils/xpack.ts
Normal 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);
|
||||||
|
}
|
@ -157,6 +157,8 @@ import { GlobalStore, MenuStore, TabsStore } from '@/store';
|
|||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { MsgSuccess } from '@/utils/message';
|
import { MsgSuccess } from '@/utils/message';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { getLicense } from '@/api/modules/setting';
|
||||||
|
import { initFavicon } from '@/utils/xpack';
|
||||||
|
|
||||||
const globalStore = GlobalStore();
|
const globalStore = GlobalStore();
|
||||||
const menuStore = MenuStore();
|
const menuStore = MenuStore();
|
||||||
@ -273,6 +275,7 @@ const login = (formEl: FormInstance | undefined) => {
|
|||||||
menuStore.setMenuList([]);
|
menuStore.setMenuList([]);
|
||||||
tabsStore.removeAllTabs();
|
tabsStore.removeAllTabs();
|
||||||
MsgSuccess(i18n.global.t('commons.msg.loginSuccess'));
|
MsgSuccess(i18n.global.t('commons.msg.loginSuccess'));
|
||||||
|
loadProductProFromDB();
|
||||||
router.push({ name: 'home' });
|
router.push({ name: 'home' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
loginVerify();
|
loginVerify();
|
||||||
@ -299,6 +302,7 @@ const mfaLogin = async (auto: boolean) => {
|
|||||||
menuStore.setMenuList([]);
|
menuStore.setMenuList([]);
|
||||||
tabsStore.removeAllTabs();
|
tabsStore.removeAllTabs();
|
||||||
MsgSuccess(i18n.global.t('commons.msg.loginSuccess'));
|
MsgSuccess(i18n.global.t('commons.msg.loginSuccess'));
|
||||||
|
loadProductProFromDB();
|
||||||
router.push({ name: 'home' });
|
router.push({ name: 'home' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -322,19 +326,29 @@ const loadLanguage = async () => {
|
|||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadFavicon = () => {
|
const loadProductProFromDB = async () => {
|
||||||
let favicon = globalStore.themeConfig.favicon;
|
const res = await getLicense();
|
||||||
const link = (document.querySelector("link[rel*='icon']") || document.createElement('link')) as HTMLLinkElement;
|
if (!res.data) {
|
||||||
link.type = 'image/x-icon';
|
globalStore.isProductPro = false;
|
||||||
link.rel = 'shortcut icon';
|
return;
|
||||||
link.href = favicon ? '/api/v1/images/favicon' : '/public/favicon.png';
|
}
|
||||||
document.getElementsByTagName('head')[0].appendChild(link);
|
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(() => {
|
onMounted(() => {
|
||||||
globalStore.isOnRestart = false;
|
globalStore.isOnRestart = false;
|
||||||
loginVerify();
|
loginVerify();
|
||||||
loadFavicon();
|
initFavicon();
|
||||||
loadLanguage();
|
loadLanguage();
|
||||||
document.title = globalStore.themeConfig.panelName;
|
document.title = globalStore.themeConfig.panelName;
|
||||||
loginForm.agreeLicense = globalStore.agreeLicense;
|
loginForm.agreeLicense = globalStore.agreeLicense;
|
||||||
|
@ -50,6 +50,7 @@ import ErrDomain from '@/components/error-message/err_domain.vue';
|
|||||||
import ErrFound from '@/components/error-message/404.vue';
|
import ErrFound from '@/components/error-message/404.vue';
|
||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import { GlobalStore } from '@/store';
|
import { GlobalStore } from '@/store';
|
||||||
|
import { initFavicon, resetXSetting } from '@/utils/xpack';
|
||||||
const globalStore = GlobalStore();
|
const globalStore = GlobalStore();
|
||||||
|
|
||||||
const screenWidth = ref(null);
|
const screenWidth = ref(null);
|
||||||
@ -91,7 +92,7 @@ const getStatus = async () => {
|
|||||||
}
|
}
|
||||||
globalStore.entrance = code;
|
globalStore.entrance = code;
|
||||||
errStatus.value = '';
|
errStatus.value = '';
|
||||||
loading.value = false;
|
loadDataFromXDB();
|
||||||
})
|
})
|
||||||
.catch((errRes) => {
|
.catch((errRes) => {
|
||||||
pageCode.value = pageCode.value || '200';
|
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(() => {
|
onMounted(() => {
|
||||||
globalStore.isOnRestart = false;
|
globalStore.isOnRestart = false;
|
||||||
getStatus();
|
getStatus();
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="login-background">
|
<div class="login-background" v-loading="loading">
|
||||||
<div class="login-wrapper">
|
<div class="login-wrapper">
|
||||||
<div :class="screenWidth > 1110 ? 'left inline-block' : ''">
|
<div :class="screenWidth > 1110 ? 'left inline-block' : ''">
|
||||||
<div class="login-title">
|
<div class="login-title">
|
||||||
<span>{{ globalStore.themeConfig.title || $t('setting.description') }}</span>
|
<span>{{ gStore.themeConfig.title || $t('setting.description') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<img src="@/assets/images/1panel-login.png" alt="" v-if="screenWidth > 1110" />
|
<img src="@/assets/images/1panel-login.png" alt="" v-if="screenWidth > 1110" />
|
||||||
</div>
|
</div>
|
||||||
@ -24,16 +24,55 @@ import LoginForm from './components/login-form.vue';
|
|||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import router from '@/routers';
|
import router from '@/routers';
|
||||||
import { GlobalStore } from '@/store';
|
import { GlobalStore } from '@/store';
|
||||||
|
import { initFavicon, resetXSetting } from '@/utils/xpack';
|
||||||
|
|
||||||
const globalStore = GlobalStore();
|
const gStore = GlobalStore();
|
||||||
|
const loading = ref();
|
||||||
|
|
||||||
const screenWidth = ref(null);
|
const screenWidth = ref(null);
|
||||||
|
|
||||||
const getStatus = async () => {
|
const getStatus = async () => {
|
||||||
const res = await checkIsSafety(globalStore.entrance);
|
loading.value = true;
|
||||||
if (res.data === 'unpass') {
|
await checkIsSafety(gStore.entrance)
|
||||||
router.replace({ name: 'entrance', params: { code: globalStore.entrance } });
|
.then((res) => {
|
||||||
|
if (res.data === 'unpass') {
|
||||||
|
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(() => {
|
onMounted(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user