123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import type { GlobConfig } from '/#/config';
- // import { VENT_PARAM } from '../../../public/js/config';
- import { getAppEnvConfig, getHomePath } from '/@/utils/env';
- // 读取ip地址
- let domainUrl = '',
- logoUrl = '',
- homePath = '',
- sysOrgCode = '',
- title = '',
- sysDataType = 'monitor';
- const getUrl = () => {
- return new Promise((resolve, reject) => {
- try {
- fetch(VUE_APP_URL.baseUrl + '/safety/orgParams/queryDefault', {
- method: 'GET',
- cache: 'no-cache',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- })
- .then((response) => response.json())
- .then((data) => {
- if (data.result) {
- if (data.result['systemTitle']) title = data.result['systemTitle'];
- if (data.result['logoIcon']) logoUrl = data.result['logoIcon'];
- if (data.result['sysOrgCode']) sysOrgCode = data.result['sysOrgCode'];
- if (data.result['sysDataType']) sysDataType = data.result['sysDataType'];
- // getHomePath是以前的代码,留下做兼容,获取到一个默认的首页路径
- // 然后正常按配置走,默认使用上面的首页路径
- const homePathKey = data.result['defaultTheme'] ? data.result['defaultTheme'] : '';
- homePath = data.result['systemHome'] ? data.result['systemHome'] : getHomePath(homePathKey);
- const faviconIcon = document.getElementById('faviconIcon');
- if (faviconIcon) {
- faviconIcon.setAttribute('href', `${VUE_APP_URL.baseUrl}/sys/common/static/${logoUrl}`);
- }
- resolve(null);
- } else {
- reject();
- }
- });
- } catch (error) {
- reject(error);
- }
- });
- };
- export async function getRemoteSetting() {
- if (!title) {
- try {
- await getUrl();
- } catch (error) {}
- }
- }
- export const useGlobSetting = (): Readonly<GlobConfig> => {
- if (!title) {
- try {
- getUrl();
- } catch (error) {}
- }
- const {
- VITE_GLOB_APP_TITLE,
- VITE_GLOB_API_URL,
- VITE_GLOB_APP_SHORT_NAME,
- VITE_GLOB_API_URL_PREFIX,
- VITE_GLOB_APP_CAS_BASE_URL,
- VITE_GLOB_APP_OPEN_SSO,
- VITE_GLOB_APP_OPEN_QIANKUN,
- VITE_GLOB_DOMAIN_URL,
- VITE_GLOB_ONLINE_VIEW_URL,
- VITE_3D_MODAL_ARR,
- } = getAppEnvConfig();
- if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
- // warn(
- // `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`
- // );
- }
- if (import.meta.env.DEV) {
- domainUrl = VUE_APP_URL.baseUrl;
- } else if (import.meta.env.PROD) {
- domainUrl = VUE_APP_URL.baseUrl;
- }
- // Take global configuration
- const glob: Readonly<GlobConfig> = {
- logoUrl: logoUrl,
- title: title,
- domainUrl: domainUrl,
- wsUrl: VUE_APP_URL.wsUrl,
- apiUrl: VITE_GLOB_API_URL,
- shortName: VITE_GLOB_APP_SHORT_NAME,
- // openSso: VITE_GLOB_APP_OPEN_SSO,
- openSso: VENT_PARAM.isoOpenSso || 'false',
- openQianKun: VITE_GLOB_APP_OPEN_QIANKUN,
- casBaseUrl: VITE_GLOB_APP_CAS_BASE_URL,
- urlPrefix: VITE_GLOB_API_URL_PREFIX,
- uploadUrl: domainUrl,
- viewUrl: VITE_GLOB_ONLINE_VIEW_URL,
- modalUrlArr: VITE_3D_MODAL_ARR,
- homePath: homePath,
- sysOrgCode: sysOrgCode,
- sysDataType: sysDataType,
- };
- return glob as Readonly<GlobConfig>;
- };
|