index.ts 3.2 KB

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