index.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 + '/ventanaly-device/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. const homePathKey = data.result['defaultTheme'] ? data.result['defaultTheme'] : '';
  27. homePath = getHomePath(homePathKey);
  28. const faviconIcon = document.getElementById('faviconIcon');
  29. if (faviconIcon) {
  30. faviconIcon.setAttribute('href', `${VUE_APP_URL.baseUrl}/sys/common/static/${logoUrl}`);
  31. }
  32. resolve(null);
  33. } else {
  34. reject();
  35. }
  36. });
  37. } catch (error) {
  38. reject(error);
  39. }
  40. });
  41. };
  42. export async function getRemoteSetting() {
  43. if (!title) {
  44. try {
  45. await getUrl();
  46. } catch (error) {}
  47. }
  48. }
  49. export const useGlobSetting = (): Readonly<GlobConfig> => {
  50. if (!title) {
  51. try {
  52. getUrl();
  53. } catch (error) {}
  54. }
  55. const {
  56. VITE_GLOB_APP_TITLE,
  57. VITE_GLOB_API_URL,
  58. VITE_GLOB_APP_SHORT_NAME,
  59. VITE_GLOB_API_URL_PREFIX,
  60. VITE_GLOB_APP_CAS_BASE_URL,
  61. VITE_GLOB_APP_OPEN_SSO,
  62. VITE_GLOB_APP_OPEN_QIANKUN,
  63. VITE_GLOB_DOMAIN_URL,
  64. VITE_GLOB_ONLINE_VIEW_URL,
  65. VITE_3D_MODAL_ARR,
  66. } = getAppEnvConfig();
  67. if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) {
  68. // warn(
  69. // `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`
  70. // );
  71. }
  72. if (import.meta.env.DEV) {
  73. domainUrl = VUE_APP_URL.baseUrl;
  74. } else if (import.meta.env.PROD) {
  75. domainUrl = VUE_APP_URL.baseUrl;
  76. }
  77. // Take global configuration
  78. const glob: Readonly<GlobConfig> = {
  79. logoUrl: logoUrl,
  80. title: title,
  81. domainUrl: domainUrl,
  82. apiUrl: VITE_GLOB_API_URL,
  83. shortName: VITE_GLOB_APP_SHORT_NAME,
  84. // openSso: VITE_GLOB_APP_OPEN_SSO,
  85. openSso: VENT_PARAM.isoOpenSso || 'false',
  86. openQianKun: VITE_GLOB_APP_OPEN_QIANKUN,
  87. casBaseUrl: VITE_GLOB_APP_CAS_BASE_URL,
  88. urlPrefix: VITE_GLOB_API_URL_PREFIX,
  89. uploadUrl: domainUrl,
  90. viewUrl: VITE_GLOB_ONLINE_VIEW_URL,
  91. modalUrlArr: VITE_3D_MODAL_ARR,
  92. homePath: homePath,
  93. sysOrgCode: sysOrgCode,
  94. };
  95. return glob as Readonly<GlobConfig>;
  96. };