提交 | 用户 | age
|
fcee7d
|
1 |
import type { GlobEnvConfig } from '/#/config'; |
8a9ca4
|
2 |
import pkg from '../../package.json'; |
V |
3 |
|
f6cef1
|
4 |
export function getCommonStoragePrefix() { |
aedb8e
|
5 |
const { VITE_GLOB_APP_TITLE } = getAppEnvConfig(); |
V |
6 |
return `${VITE_GLOB_APP_TITLE.replace(/\s/g, '_')}__${getEnv()}`.toUpperCase(); |
144ab5
|
7 |
} |
bb3b8f
|
8 |
|
8a9ca4
|
9 |
// Generate cache key according to version |
V |
10 |
export function getStorageShortName() { |
f6cef1
|
11 |
return `${getCommonStoragePrefix()}${`__${pkg.version}`}__`.toUpperCase(); |
V |
12 |
} |
|
13 |
|
c99ef6
|
14 |
const getVariableName = (title: string) => { |
J |
15 |
function strToHex(str: string) { |
|
16 |
const result: string[] = []; |
|
17 |
for (let i = 0; i < str.length; ++i) { |
|
18 |
const hex = str.charCodeAt(i).toString(16); |
|
19 |
result.push(('000' + hex).slice(-4)); |
|
20 |
} |
|
21 |
return result.join('').toUpperCase(); |
|
22 |
} |
|
23 |
return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, ''); |
|
24 |
}; |
|
25 |
|
f6cef1
|
26 |
export function getAppEnvConfig() { |
aedb8e
|
27 |
const ENV_NAME = getVariableName(import.meta.env.VITE_GLOB_APP_TITLE); |
6fbc55
|
28 |
console.log(ENV_NAME); |
833b31
|
29 |
const ENV = import.meta.env.DEV |
f6cef1
|
30 |
? // Get the global configuration (the configuration will be extracted independently when packaging) |
00fca0
|
31 |
(import.meta.env as unknown as GlobEnvConfig) |
6fbc55
|
32 |
: (window[ENV_NAME] as unknown as GlobEnvConfig); |
J |
33 |
console.log(ENV); |
aedb8e
|
34 |
const { VITE_GLOB_APP_TITLE, VITE_GLOB_API_URL, VITE_GLOB_API_URL_PREFIX, VITE_GLOB_UPLOAD_URL } = |
V |
35 |
ENV; |
215d8b
|
36 |
|
b7ce74
|
37 |
return { |
V |
38 |
VITE_GLOB_APP_TITLE, |
|
39 |
VITE_GLOB_API_URL, |
|
40 |
VITE_GLOB_API_URL_PREFIX, |
|
41 |
VITE_GLOB_UPLOAD_URL, |
|
42 |
}; |
8a9ca4
|
43 |
} |
V |
44 |
|
2f6253
|
45 |
/** |
e8eefd
|
46 |
* @description: Development mode |
2f6253
|
47 |
*/ |
陈 |
48 |
export const devMode = 'development'; |
|
49 |
|
|
50 |
/** |
236575
|
51 |
* @description: Production mode |
2f6253
|
52 |
*/ |
陈 |
53 |
export const prodMode = 'production'; |
|
54 |
|
|
55 |
/** |
236575
|
56 |
* @description: Get environment variables |
2f6253
|
57 |
* @returns: |
陈 |
58 |
* @example: |
|
59 |
*/ |
144ab5
|
60 |
export function getEnv(): string { |
V |
61 |
return import.meta.env.MODE; |
|
62 |
} |
2f6253
|
63 |
|
陈 |
64 |
/** |
236575
|
65 |
* @description: Is it a development mode |
2f6253
|
66 |
* @returns: |
陈 |
67 |
* @example: |
|
68 |
*/ |
144ab5
|
69 |
export function isDevMode(): boolean { |
V |
70 |
return import.meta.env.DEV; |
|
71 |
} |
2f6253
|
72 |
|
陈 |
73 |
/** |
236575
|
74 |
* @description: Is it a production mode |
2f6253
|
75 |
* @returns: |
陈 |
76 |
* @example: |
|
77 |
*/ |
144ab5
|
78 |
export function isProdMode(): boolean { |
V |
79 |
return import.meta.env.PROD; |
|
80 |
} |