index.ts 2.7 KB

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