2023-05-24 11:08:08 +08:00
|
|
|
|
<template>
|
|
|
|
|
<a-config-provider :locale="locale">
|
2024-07-10 21:45:33 +08:00
|
|
|
|
<router-view />
|
2023-09-04 11:59:50 +08:00
|
|
|
|
<!-- <global-setting /> -->
|
2023-05-24 11:08:08 +08:00
|
|
|
|
</a-config-provider>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-10-17 10:35:21 +08:00
|
|
|
|
import { useEventListener, useWindowSize } from '@vueuse/core';
|
2024-04-16 18:40:18 +08:00
|
|
|
|
import { Message } from '@arco-design/web-vue';
|
|
|
|
|
|
|
|
|
|
import MsSysUpgradeTip from '@/components/pure/ms-sys-upgrade-tip/index.vue';
|
2023-10-17 10:35:21 +08:00
|
|
|
|
|
|
|
|
|
import { saveBaseUrl } from '@/api/modules/setting/config';
|
|
|
|
|
import { GetPlatformIconUrl } from '@/api/requrls/setting/config';
|
2023-09-04 11:59:50 +08:00
|
|
|
|
// import GlobalSetting from '@/components/pure/global-setting/index.vue';
|
2023-05-24 11:08:08 +08:00
|
|
|
|
import useLocale from '@/locale/useLocale';
|
2024-05-22 17:04:47 +08:00
|
|
|
|
import { WHITE_LIST } from '@/router/constants';
|
2023-09-04 11:59:50 +08:00
|
|
|
|
import { useUserStore } from '@/store';
|
2023-08-02 14:18:24 +08:00
|
|
|
|
import useAppStore from '@/store/modules/app';
|
2023-08-18 15:55:25 +08:00
|
|
|
|
import useLicenseStore from '@/store/modules/setting/license';
|
2024-07-11 18:10:17 +08:00
|
|
|
|
import { getQueryVariable, getUrlParameterWidthRegExp } from '@/utils';
|
2024-07-11 16:18:49 +08:00
|
|
|
|
import { setLoginExpires, setLongType, setToken } from '@/utils/auth';
|
2023-09-04 11:59:50 +08:00
|
|
|
|
import { getLocalStorage, setLocalStorage } from '@/utils/local-storage';
|
2023-10-17 10:35:21 +08:00
|
|
|
|
import { setFavicon, watchStyle, watchTheme } from '@/utils/theme';
|
|
|
|
|
|
2024-07-10 20:16:28 +08:00
|
|
|
|
import { getLarkCallback, getLarkSuiteCallback, getPublicKeyRequest } from './api/modules/user';
|
2024-09-26 11:56:50 +08:00
|
|
|
|
import { hasAnyPermission } from './utils/permission';
|
2023-10-17 10:35:21 +08:00
|
|
|
|
import enUS from '@arco-design/web-vue/es/locale/lang/en-us';
|
|
|
|
|
import zhCN from '@arco-design/web-vue/es/locale/lang/zh-cn';
|
2023-08-02 14:18:24 +08:00
|
|
|
|
|
|
|
|
|
const appStore = useAppStore();
|
2023-08-23 11:24:26 +08:00
|
|
|
|
const userStore = useUserStore();
|
2023-08-18 15:55:25 +08:00
|
|
|
|
const licenseStore = useLicenseStore();
|
2023-05-24 11:08:08 +08:00
|
|
|
|
|
|
|
|
|
const { currentLocale } = useLocale();
|
|
|
|
|
const locale = computed(() => {
|
|
|
|
|
switch (currentLocale.value) {
|
|
|
|
|
case 'zh-CN':
|
|
|
|
|
return zhCN;
|
|
|
|
|
case 'en-US':
|
|
|
|
|
return enUS;
|
|
|
|
|
default:
|
|
|
|
|
return zhCN;
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-28 16:34:32 +08:00
|
|
|
|
|
2023-08-07 13:47:04 +08:00
|
|
|
|
// 初始化平台风格和主题色
|
|
|
|
|
watchStyle(appStore.pageConfig.style, appStore.pageConfig);
|
|
|
|
|
watchTheme(appStore.pageConfig.theme, appStore.pageConfig);
|
2023-08-08 16:28:44 +08:00
|
|
|
|
setFavicon(GetPlatformIconUrl);
|
2023-08-07 13:47:04 +08:00
|
|
|
|
|
2023-07-28 16:34:32 +08:00
|
|
|
|
onBeforeMount(async () => {
|
|
|
|
|
try {
|
2024-03-29 18:00:45 +08:00
|
|
|
|
appStore.initSystemVersion(); // 初始化系统版本
|
2024-09-26 11:56:50 +08:00
|
|
|
|
if (hasAnyPermission(['SYSTEM_PARAMETER_SETTING_BASE:READ'])) {
|
|
|
|
|
appStore.initFileSizeLimit(); // 初始化文件大小限制
|
|
|
|
|
}
|
2024-01-29 15:08:55 +08:00
|
|
|
|
// 企业版才校验license
|
2024-07-16 11:42:44 +08:00
|
|
|
|
if (appStore.getPackageType === 'enterprise') {
|
2024-01-29 15:08:55 +08:00
|
|
|
|
licenseStore.getValidateLicense();
|
|
|
|
|
}
|
2024-01-25 11:26:52 +08:00
|
|
|
|
if (licenseStore.hasLicense()) {
|
|
|
|
|
appStore.initPageConfig(); // 初始化页面配置
|
|
|
|
|
}
|
2023-08-02 14:18:24 +08:00
|
|
|
|
// 项目初始化时需要获取基础设置信息,看当前站点 url是否为系统内置默认地址,如果是需要替换为当前项目部署的 url 地址
|
2023-07-28 16:34:32 +08:00
|
|
|
|
const isInitUrl = getLocalStorage('isInitUrl'); // 是否已经初始化过 url
|
|
|
|
|
if (isInitUrl === 'true') return;
|
2023-09-15 17:57:35 +08:00
|
|
|
|
await saveBaseUrl(window.location.origin);
|
2023-08-24 16:01:55 +08:00
|
|
|
|
setLocalStorage('isInitUrl', 'true'); // 设置已经初始化过 url,避免重复初始化
|
2023-07-28 16:34:32 +08:00
|
|
|
|
} catch (error) {
|
2023-08-23 11:24:26 +08:00
|
|
|
|
// eslint-disable-next-line no-console
|
2023-07-28 16:34:32 +08:00
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-02-07 17:21:07 +08:00
|
|
|
|
|
2023-09-12 12:28:47 +08:00
|
|
|
|
// 获取公钥
|
|
|
|
|
const getPublicKey = async () => {
|
|
|
|
|
const publicKey = await getPublicKeyRequest();
|
|
|
|
|
setLocalStorage('salt', publicKey);
|
|
|
|
|
};
|
2023-09-11 17:40:56 +08:00
|
|
|
|
|
2024-03-29 18:00:45 +08:00
|
|
|
|
onBeforeMount(async () => {
|
2023-09-12 12:28:47 +08:00
|
|
|
|
await getPublicKey();
|
2024-07-23 18:20:35 +08:00
|
|
|
|
if (WHITE_LIST.find((el) => window.location.hash.split('#')[1].includes(el.path)) === undefined) {
|
2024-07-09 21:10:23 +08:00
|
|
|
|
const TOKEN = getQueryVariable('_token');
|
|
|
|
|
const CSRF = getQueryVariable('_csrf');
|
|
|
|
|
if (TOKEN !== null && TOKEN !== undefined && CSRF !== null && CSRF !== undefined) {
|
|
|
|
|
setToken(window.atob(TOKEN), CSRF);
|
2024-07-10 13:10:36 +08:00
|
|
|
|
setLoginExpires();
|
2024-07-09 21:10:23 +08:00
|
|
|
|
}
|
2024-07-10 20:16:28 +08:00
|
|
|
|
const state = ref('');
|
|
|
|
|
const code = getQueryVariable('code');
|
|
|
|
|
state.value = getQueryVariable('state') || '';
|
|
|
|
|
if (state.value.split('#')[0] === 'fit2cloud-lark-qr') {
|
|
|
|
|
try {
|
2024-07-11 16:18:49 +08:00
|
|
|
|
appStore.setLoginLoading(true);
|
2024-07-10 20:16:28 +08:00
|
|
|
|
const larkCallback = await getLarkCallback(code || '');
|
|
|
|
|
userStore.qrCodeLogin(larkCallback);
|
2024-07-11 16:18:49 +08:00
|
|
|
|
setLongType('LARK');
|
2024-07-10 20:16:28 +08:00
|
|
|
|
setLoginExpires();
|
|
|
|
|
} catch (err) {
|
2024-07-16 11:42:44 +08:00
|
|
|
|
// eslint-disable-next-line no-console
|
2024-07-10 20:16:28 +08:00
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (state.value.split('#')[0] === 'fit2cloud-lark-suite-qr') {
|
|
|
|
|
try {
|
2024-07-11 16:18:49 +08:00
|
|
|
|
appStore.setLoginLoading(true);
|
2024-07-10 20:16:28 +08:00
|
|
|
|
const larkCallback = await getLarkSuiteCallback(code || '');
|
|
|
|
|
userStore.qrCodeLogin(larkCallback);
|
2024-07-11 16:18:49 +08:00
|
|
|
|
setLongType('LARK_SUITE');
|
2024-07-10 20:16:28 +08:00
|
|
|
|
setLoginExpires();
|
|
|
|
|
} catch (err) {
|
2024-07-16 11:42:44 +08:00
|
|
|
|
// eslint-disable-next-line no-console
|
2024-07-10 20:16:28 +08:00
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-22 17:04:47 +08:00
|
|
|
|
await userStore.checkIsLogin();
|
2024-07-11 16:18:49 +08:00
|
|
|
|
appStore.setLoginLoading(false);
|
2023-09-11 17:40:56 +08:00
|
|
|
|
}
|
2024-07-11 18:10:17 +08:00
|
|
|
|
if (getQueryVariable('code') && getQueryVariable('state')) {
|
|
|
|
|
const currentUrl = window.location.href;
|
|
|
|
|
const url = new URL(currentUrl);
|
|
|
|
|
getUrlParameterWidthRegExp('code');
|
|
|
|
|
getUrlParameterWidthRegExp('state');
|
|
|
|
|
url.searchParams.delete('code');
|
|
|
|
|
url.searchParams.delete('state');
|
|
|
|
|
const newUrl = url.toString();
|
|
|
|
|
// 或者在不刷新页面的情况下更新URL(比如使用 History API)
|
|
|
|
|
window.history.replaceState({}, document.title, newUrl);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 18:54:24 +08:00
|
|
|
|
const { height } = useWindowSize();
|
|
|
|
|
appStore.innerHeight = height.value;
|
2024-06-20 09:55:08 +08:00
|
|
|
|
if (userStore.id) {
|
|
|
|
|
userStore.initLocalConfig(); // 获取本地执行配置
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-15 16:35:53 +08:00
|
|
|
|
// @desc: TODO待优化主要是为了拿到初始化配置的项目模块方便接下来过滤菜单权限 解决刷新菜单空白问题
|
|
|
|
|
appStore.getProjectInfos();
|
2023-09-13 18:54:24 +08:00
|
|
|
|
});
|
2024-04-16 18:40:18 +08:00
|
|
|
|
|
|
|
|
|
function showUpdateMessage() {
|
|
|
|
|
Message.clear();
|
|
|
|
|
Message.warning({
|
|
|
|
|
content: () => h(MsSysUpgradeTip),
|
|
|
|
|
duration: 0,
|
|
|
|
|
closable: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
window.onerror = (message) => {
|
|
|
|
|
if (typeof message === 'string' && message.includes('Failed to fetch dynamically imported')) {
|
|
|
|
|
showUpdateMessage();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.onunhandledrejection = (event: PromiseRejectionEvent) => {
|
|
|
|
|
if (
|
|
|
|
|
event &&
|
|
|
|
|
event.reason &&
|
|
|
|
|
event.reason.message &&
|
|
|
|
|
event.reason.message.includes('Failed to fetch dynamically imported')
|
|
|
|
|
) {
|
|
|
|
|
showUpdateMessage();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-13 18:54:24 +08:00
|
|
|
|
/** 屏幕大小改变时重新赋值innerHeight */
|
|
|
|
|
useEventListener(window, 'resize', () => {
|
|
|
|
|
const { height } = useWindowSize();
|
|
|
|
|
appStore.innerHeight = height.value;
|
2023-08-23 11:24:26 +08:00
|
|
|
|
});
|
2023-05-24 11:08:08 +08:00
|
|
|
|
</script>
|