index.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import type { GlobConfig } from '/#/config';
  2. // import { VENT_PARAM } from '../../../public/js/config';
  3. import { getAppEnvConfig, getHomePath } from '/@/utils/env';
  4. // 读取ip地址
  5. let domainUrl = '',
  6. logoUrl = '',
  7. homePath = '',
  8. sysOrgCode = '',
  9. title = '',
  10. sysDataType = 'monitor';
  11. const getUrl = () => {
  12. return new Promise((resolve, reject) => {
  13. try {
  14. fetch(VUE_APP_URL.baseUrl + '/safety/orgParams/queryDefault', {
  15. method: 'GET',
  16. cache: 'no-cache',
  17. headers: {
  18. 'Content-Type': 'application/x-www-form-urlencoded',
  19. },
  20. })
  21. .then((response) => response.json())
  22. .then((data) => {
  23. if (data.result) {
  24. if (data.result['systemTitle']) title = data.result['systemTitle'];
  25. if (data.result['logoIcon']) logoUrl = data.result['logoIcon'];
  26. if (data.result['sysOrgCode']) sysOrgCode = data.result['sysOrgCode'];
  27. if (data.result['sysDataType']) sysDataType = data.result['sysDataType'];
  28. // getHomePath是以前的代码,留下做兼容,获取到一个默认的首页路径
  29. // 然后正常按配置走,默认使用上面的首页路径
  30. const homePathKey = data.result['defaultTheme'] ? data.result['defaultTheme'] : '';
  31. homePath = data.result['systemHome'] ? data.result['systemHome'] : getHomePath(homePathKey);
  32. const faviconIcon = document.getElementById('faviconIcon');
  33. if (faviconIcon) {
  34. faviconIcon.setAttribute('href', `${VUE_APP_URL.baseUrl}/sys/common/static/${logoUrl}`);
  35. }
  36. resolve(null);
  37. } else {
  38. reject();
  39. }
  40. });
  41. } catch (error) {
  42. reject(error);
  43. }
  44. });
  45. };
  46. export async function getRemoteSetting() {
  47. if (!title) {
  48. try {
  49. await getUrl();
  50. } catch (error) {}
  51. }
  52. }
  53. export const useGlobSetting = (): Readonly<GlobConfig> => {
  54. if (!title) {
  55. try {
  56. getUrl();
  57. } catch (error) {}
  58. }
  59. const {
  60. VITE_GLOB_APP_TITLE,
  61. VITE_GLOB_API_URL,
  62. VITE_GLOB_APP_SHORT_NAME,
  63. VITE_GLOB_API_URL_PREFIX,
  64. VITE_GLOB_APP_CAS_BASE_URL,
  65. VITE_GLOB_APP_OPEN_SSO,
  66. VITE_GLOB_APP_OPEN_QIANKUN,
  67. VITE_GLOB_DOMAIN_URL,
  68. VITE_GLOB_ONLINE_VIEW_URL,
  69. VITE_3D_MODAL_ARR,
  70. } = getAppEnvConfig();
  71. if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
  72. // warn(
  73. // `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`
  74. // );
  75. }
  76. if (import.meta.env.DEV) {
  77. domainUrl = VUE_APP_URL.baseUrl;
  78. } else if (import.meta.env.PROD) {
  79. domainUrl = VUE_APP_URL.baseUrl;
  80. }
  81. // Take global configuration
  82. const glob: Readonly<GlobConfig> = {
  83. logoUrl: logoUrl,
  84. title: title,
  85. domainUrl: domainUrl,
  86. wsUrl: VUE_APP_URL.wsUrl,
  87. apiUrl: VITE_GLOB_API_URL,
  88. shortName: VITE_GLOB_APP_SHORT_NAME,
  89. // openSso: VITE_GLOB_APP_OPEN_SSO,
  90. openSso: VENT_PARAM.isoOpenSso || 'false',
  91. openQianKun: VITE_GLOB_APP_OPEN_QIANKUN,
  92. casBaseUrl: VITE_GLOB_APP_CAS_BASE_URL,
  93. urlPrefix: VITE_GLOB_API_URL_PREFIX,
  94. uploadUrl: domainUrl,
  95. viewUrl: VITE_GLOB_ONLINE_VIEW_URL,
  96. modalUrlArr: VITE_3D_MODAL_ARR,
  97. homePath: homePath,
  98. sysOrgCode: sysOrgCode,
  99. sysDataType: sysDataType,
  100. };
  101. return glob as Readonly<GlobConfig>;
  102. };