index.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. console.log(data.result,'88888888')
  25. if (data.result['systemTitle']) title = data.result['systemTitle'];
  26. if (data.result['logoIcon']) logoUrl = data.result['logoIcon'];
  27. if (data.result['sysOrgCode']) sysOrgCode = data.result['sysOrgCode'];
  28. if (data.result['dataType']) sysDataType = data.result['dataType'];
  29. // getHomePath是以前的代码,留下做兼容,获取到一个默认的首页路径
  30. // 然后正常按配置走,默认使用上面的首页路径
  31. const homePathKey = data.result['defaultTheme'] ? data.result['defaultTheme'] : '';
  32. homePath = data.result['systemHome'] ? data.result['systemHome'] : getHomePath(homePathKey);
  33. const faviconIcon = document.getElementById('faviconIcon');
  34. if (faviconIcon) {
  35. faviconIcon.setAttribute('href', `${VUE_APP_URL.baseUrl}/sys/common/static/${logoUrl}`);
  36. }
  37. resolve(null);
  38. } else {
  39. reject();
  40. }
  41. });
  42. } catch (error) {
  43. reject(error);
  44. }
  45. });
  46. };
  47. export async function getRemoteSetting() {
  48. if (!title) {
  49. try {
  50. await getUrl();
  51. } catch (error) {}
  52. }
  53. }
  54. export const useGlobSetting = (): Readonly<GlobConfig> => {
  55. getUrl();
  56. if (!title) {
  57. try {
  58. getUrl();
  59. } catch (error) {}
  60. }
  61. const {
  62. VITE_GLOB_APP_TITLE,
  63. VITE_GLOB_API_URL,
  64. VITE_GLOB_APP_SHORT_NAME,
  65. VITE_GLOB_API_URL_PREFIX,
  66. VITE_GLOB_APP_CAS_BASE_URL,
  67. VITE_GLOB_APP_OPEN_SSO,
  68. VITE_GLOB_APP_OPEN_QIANKUN,
  69. VITE_GLOB_DOMAIN_URL,
  70. VITE_GLOB_ONLINE_VIEW_URL,
  71. VITE_3D_MODAL_ARR,
  72. } = getAppEnvConfig();
  73. if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
  74. // warn(
  75. // `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`
  76. // );
  77. }
  78. if (import.meta.env.DEV) {
  79. domainUrl = VUE_APP_URL.baseUrl;
  80. } else if (import.meta.env.PROD) {
  81. domainUrl = VUE_APP_URL.baseUrl;
  82. }
  83. // Take global configuration
  84. const glob: Readonly<GlobConfig> = {
  85. logoUrl: logoUrl,
  86. title: title,
  87. domainUrl: domainUrl,
  88. wsUrl: VUE_APP_URL.wsUrl,
  89. apiUrl: VITE_GLOB_API_URL,
  90. shortName: VITE_GLOB_APP_SHORT_NAME,
  91. // openSso: VITE_GLOB_APP_OPEN_SSO,
  92. openSso: VENT_PARAM.isoOpenSso || 'false',
  93. openQianKun: VITE_GLOB_APP_OPEN_QIANKUN,
  94. casBaseUrl: VITE_GLOB_APP_CAS_BASE_URL,
  95. urlPrefix: VITE_GLOB_API_URL_PREFIX,
  96. uploadUrl: domainUrl,
  97. viewUrl: VITE_GLOB_ONLINE_VIEW_URL,
  98. modalUrlArr: VITE_3D_MODAL_ARR,
  99. homePath: homePath,
  100. sysOrgCode: sysOrgCode,
  101. sysDataType: sysDataType,
  102. };
  103. return glob as Readonly<GlobConfig>;
  104. };