index.ts 2.7 KB

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