index.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type { GlobConfig } from '/#/config';
  2. import { getAppEnvConfig } from '/@/utils/env';
  3. export const useGlobSetting = (): Readonly<GlobConfig> => {
  4. const {
  5. VITE_GLOB_APP_TITLE,
  6. VITE_GLOB_API_URL,
  7. VITE_GLOB_APP_SHORT_NAME,
  8. VITE_GLOB_API_URL_PREFIX,
  9. VITE_GLOB_APP_CAS_BASE_URL,
  10. VITE_GLOB_APP_OPEN_SSO,
  11. VITE_GLOB_DOMAIN_URL,
  12. VITE_GLOB_ONLINE_VIEW_URL,
  13. } = getAppEnvConfig();
  14. // if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
  15. // warn(
  16. // `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`
  17. // );
  18. // }
  19. // 短标题:替换shortName的下划线为空格
  20. const shortTitle = VITE_GLOB_APP_SHORT_NAME.replace(/_/g, ' ');
  21. // Take global configuration
  22. const glob: Readonly<GlobConfig> = {
  23. title: VITE_GLOB_APP_TITLE,
  24. domainUrl: VITE_GLOB_DOMAIN_URL,
  25. apiUrl: VITE_GLOB_API_URL,
  26. shortName: VITE_GLOB_APP_SHORT_NAME,
  27. shortTitle: shortTitle,
  28. openSso: VITE_GLOB_APP_OPEN_SSO,
  29. casBaseUrl: VITE_GLOB_APP_CAS_BASE_URL,
  30. urlPrefix: VITE_GLOB_API_URL_PREFIX,
  31. uploadUrl: VITE_GLOB_DOMAIN_URL,
  32. viewUrl: VITE_GLOB_ONLINE_VIEW_URL,
  33. // true: 新任务办理页面弹窗, false:旧的任务办理页面弹窗
  34. useNewTaskModal: true,
  35. };
  36. // 【JEECG作为乾坤子应用】乾坤子应用下,需要定义一下
  37. if (!window['_CONFIG']) {
  38. window['_CONFIG'] = {};
  39. }
  40. // 代码逻辑说明: 【QQYUN-10956】配置了自定义前缀,外部连接打不开,需要兼容处理
  41. let domainURL = VITE_GLOB_DOMAIN_URL;
  42. // 如果不是以http(s)开头的,也不是以域名开头的,那么就是拼接当前域名
  43. if (!/^http(s)?/.test(domainURL) && !/^(\/\/)?(.*\.)?.+\..+/.test(domainURL)) {
  44. if (!domainURL.startsWith('/')) {
  45. domainURL = '/' + domainURL;
  46. }
  47. domainURL = window.location.origin + domainURL;
  48. }
  49. // @ts-ignore
  50. window._CONFIG['domianURL'] = domainURL;
  51. return glob as Readonly<GlobConfig>;
  52. };