| | |
| | | import type { GlobEnvConfig } from '/#/config'; |
| | | /* |
| | | * @Description: file content |
| | | * @Author: your name |
| | | * @version: |
| | | * @Date: 2024-06-17 14:51:26 |
| | | * @LastEditors: your name |
| | | * @LastEditTime: 2024-06-17 15:54:10 |
| | | */ |
| | | import type { GlobEnvConfig } from '#/config'; |
| | | import pkg from '../../package.json'; |
| | | |
| | | const getVariableName = (title: string) => { |
| | | return `__PRODUCTION__${title.replace(/\s/g, '_').replace(/-/g, '_') || '__APP'}__CONF__` |
| | | .toUpperCase() |
| | | .replace(/\s/g, ''); |
| | | }; |
| | | import { API_ADDRESS } from '@/enums/cacheEnum'; |
| | | |
| | | export function getCommonStoragePrefix() { |
| | | const { VITE_GLOB_APP_TITLE } = getAppEnvConfig(); |
| | |
| | | return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase(); |
| | | } |
| | | |
| | | const getVariableName = (title: string) => { |
| | | function strToHex(str: string) { |
| | | const result: string[] = []; |
| | | for (let i = 0; i < str.length; ++i) { |
| | | const hex = str.charCodeAt(i).toString(16); |
| | | result.push(('000' + hex).slice(-4)); |
| | | } |
| | | return result.join('').toUpperCase(); |
| | | } |
| | | return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, ''); |
| | | }; |
| | | |
| | | export function getAppEnvConfig() { |
| | | const ENV_NAME = getVariableName(import.meta.env.VITE_GLOB_APP_TITLE); |
| | | |
| | | const ENV = (import.meta.env.DEV |
| | | const ENV = import.meta.env.DEV |
| | | ? // Get the global configuration (the configuration will be extracted independently when packaging) |
| | | (import.meta.env as unknown as GlobEnvConfig) |
| | | : window[ENV_NAME as any]) as unknown as GlobEnvConfig; |
| | | |
| | | const { |
| | | VITE_GLOB_APP_TITLE, |
| | | VITE_GLOB_API_URL, |
| | | : (window[ENV_NAME] as unknown as GlobEnvConfig); |
| | | const { VITE_GLOB_APP_TITLE, VITE_GLOB_API_URL_PREFIX, VITE_GLOB_UPLOAD_URL, |
| | | VITE_GLOB_SYS_API_URL, |
| | | VITE_GLOB_API_URL_PREFIX, |
| | | VITE_GLOB_UPLOAD_URL, |
| | | VITE_GLOB_MAP_KEY, |
| | | VITE_GLOB_TSK_API_URL, |
| | | VITE_GLOB_DOWNLOAD_URL, |
| | | VITE_USE_ORG, |
| | | } = ENV; |
| | | |
| | | VITE_USE_ORG, } = ENV; |
| | | let { VITE_GLOB_API_URL } = ENV; |
| | | if (localStorage.getItem(API_ADDRESS)) { |
| | | const address = JSON.parse(localStorage.getItem(API_ADDRESS) || '{}'); |
| | | if (address?.key) VITE_GLOB_API_URL = address?.val; |
| | | } |
| | | return { |
| | | VITE_GLOB_APP_TITLE, |
| | | VITE_GLOB_API_URL, |
| | | VITE_GLOB_SYS_API_URL, |
| | | VITE_GLOB_TSK_API_URL, |
| | | VITE_GLOB_API_URL_PREFIX, |
| | | VITE_GLOB_UPLOAD_URL, |
| | | VITE_GLOB_SYS_API_URL, |
| | | VITE_GLOB_MAP_KEY, |
| | | VITE_GLOB_TSK_API_URL, |
| | | VITE_GLOB_DOWNLOAD_URL, |
| | | VITE_USE_ORG, |
| | | }; |