env.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import type { GlobEnvConfig } from '/#/config';
  2. // import { warn } from '/@/utils/log';
  3. import pkg from '../../package.json';
  4. import { getConfigFileName } from '../../build/getConfigFileName';
  5. import { ThemeModel } from '/@/layouts/default/layout.data';
  6. export function getCommonStoragePrefix() {
  7. const { VITE_GLOB_APP_SHORT_NAME } = getAppEnvConfig();
  8. return `${VITE_GLOB_APP_SHORT_NAME}__${getEnv()}`.toUpperCase();
  9. }
  10. // Generate cache key according to version
  11. export function getStorageShortName() {
  12. return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase();
  13. }
  14. export function getAppEnvConfig() {
  15. const ENV_NAME = getConfigFileName(import.meta.env);
  16. const ENV = (import.meta.env.DEV
  17. ? // Get the global configuration (the configuration will be extracted independently when packaging)
  18. (import.meta.env as unknown as GlobEnvConfig)
  19. : window[ENV_NAME as any]) as unknown as GlobEnvConfig;
  20. const {
  21. VITE_GLOB_APP_TITLE,
  22. VITE_GLOB_API_URL,
  23. VITE_USE_MOCK,
  24. VITE_GLOB_APP_SHORT_NAME,
  25. VITE_GLOB_API_URL_PREFIX,
  26. VITE_GLOB_APP_OPEN_SSO,
  27. VITE_GLOB_APP_OPEN_QIANKUN,
  28. VITE_GLOB_APP_CAS_BASE_URL,
  29. VITE_GLOB_DOMAIN_URL,
  30. VITE_GLOB_ONLINE_VIEW_URL,
  31. VITE_3D_MODAL_ARR,
  32. } = ENV;
  33. if (!/^[a-zA-Z\_]*$/.test(VITE_GLOB_APP_SHORT_NAME)) {
  34. // warn(
  35. // `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`
  36. // );
  37. }
  38. return {
  39. VITE_GLOB_APP_TITLE,
  40. VITE_GLOB_API_URL,
  41. VITE_USE_MOCK,
  42. VITE_GLOB_APP_SHORT_NAME,
  43. VITE_GLOB_API_URL_PREFIX,
  44. VITE_GLOB_APP_OPEN_SSO,
  45. VITE_GLOB_APP_OPEN_QIANKUN,
  46. VITE_GLOB_APP_CAS_BASE_URL,
  47. VITE_GLOB_DOMAIN_URL,
  48. VITE_GLOB_ONLINE_VIEW_URL,
  49. VITE_3D_MODAL_ARR,
  50. };
  51. }
  52. /**
  53. * @description: Development mode
  54. */
  55. export const devMode = 'development';
  56. /**
  57. * @description: Production mode
  58. */
  59. export const prodMode = 'production';
  60. /**
  61. * @description: Get environment variables
  62. * @returns:
  63. * @example:
  64. */
  65. export function getEnv(): string {
  66. return import.meta.env.MODE;
  67. }
  68. /**
  69. * @description: Is it a development mode
  70. * @returns:
  71. * @example:
  72. */
  73. export function isDevMode(): boolean {
  74. return import.meta.env.DEV;
  75. }
  76. /**
  77. * @description: Is it a production mode
  78. * @returns:
  79. * @example:
  80. */
  81. export function isProdMode(): boolean {
  82. return import.meta.env.PROD;
  83. }
  84. export function getHomePath(key): string {
  85. let homePath = '/micro-vent-3dModal/dashboard/analysis';
  86. switch (key) {
  87. case 'styleOne':
  88. // 显示6.0
  89. homePath = '/micro-vent-3dModal/dashboard/analysis';
  90. // switchTheme(ThemeModel.theme6_0);
  91. break;
  92. case 'styleTwo':
  93. // 显示5.5
  94. homePath = '/micro-vent-3dModal/modelchannel/model3D/home';
  95. switchTheme(ThemeModel.theme5_5);
  96. break;
  97. }
  98. return homePath;
  99. }
  100. function switchTheme(obj) {
  101. for (const key in obj) {
  102. document.getElementsByTagName('body')[0].style.setProperty(`--${key}`, obj[key]);
  103. }
  104. }