Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
topsun-baoshen-pc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
何远江
topsun-baoshen-pc
Commits
967b0d25
Commit
967b0d25
authored
Oct 25, 2023
by
何远江
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
axios 环境变量修改和添加
parent
bdd1b15b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
39 additions
and
59 deletions
+39
-59
.env
.env
+1
-1
.env.development
.env.development
+2
-8
.env.production
.env.production
+8
-0
index.html
index.html
+1
-1
index.ts
src/hooks/setting/index.ts
+1
-3
env.ts
src/utils/env.ts
+15
-35
config.d.ts
types/config.d.ts
+1
-1
vite.config.ts
vite.config.ts
+10
-10
No files found.
.env
View file @
967b0d25
# spa-title
VITE_GLOB_APP_TITLE = 宝绅
VITE_GLOB_APP_TITLE = 宝绅
EP系统
.env.development
View file @
967b0d25
# Whether to open mock
VITE_USE_MOCK = true
# public path
VITE_PUBLIC_PATH = /
# Basic interface address SPA
VITE_GLOB_API_URL=/api
# File upload address, optional
VITE_GLOB_UPLOAD_URL=/upload
VITE_GLOB_API_URL=
# Interface prefix
VITE_GLOB_API_URL_PREFIX=
VITE_GLOB_API_URL_PREFIX=
/api
.env.production
0 → 100644
View file @
967b0d25
# public path
VITE_PUBLIC_PATH = /
# Basic interface address SPA
VITE_GLOB_API_URL=
# Interface prefix
VITE_GLOB_API_URL_PREFIX=/api
\ No newline at end of file
index.html
View file @
967b0d25
...
...
@@ -4,7 +4,7 @@
<meta
charset=
"UTF-8"
>
<link
rel=
"icon"
href=
"/favicon.ico"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Vite App
</title>
<title>
%VITE_GLOB_APP_TITLE%
</title>
</head>
<body>
<div
id=
"app"
></div>
...
...
src/hooks/setting/index.ts
View file @
967b0d25
...
...
@@ -3,16 +3,14 @@ import type { GlobConfig } from '#/config';
import
{
getAppEnvConfig
}
from
'@/utils/env'
;
export
const
useGlobSetting
=
():
Readonly
<
GlobConfig
>
=>
{
const
{
VITE_GLOB_APP_TITLE
,
VITE_GLOB_API_URL
,
VITE_GLOB_API_URL_PREFIX
,
VITE_GLOB_UPLOAD_URL
}
=
const
{
VITE_GLOB_APP_TITLE
,
VITE_GLOB_API_URL
,
VITE_GLOB_API_URL_PREFIX
}
=
getAppEnvConfig
();
// Take global configuration
const
glob
:
Readonly
<
GlobConfig
>
=
{
title
:
VITE_GLOB_APP_TITLE
,
apiUrl
:
VITE_GLOB_API_URL
,
shortName
:
VITE_GLOB_APP_TITLE
.
replace
(
/
\s
/g
,
'_'
).
replace
(
/-/g
,
'_'
),
urlPrefix
:
VITE_GLOB_API_URL_PREFIX
,
uploadUrl
:
VITE_GLOB_UPLOAD_URL
,
};
return
glob
as
Readonly
<
GlobConfig
>
;
};
src/utils/env.ts
View file @
967b0d25
import
type
{
GlobEnvConfig
}
from
'#/config'
;
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
,
''
);
};
import
type
{
GlobEnvConfig
}
from
'#/config'
export
function
getAppEnvConfig
()
{
const
ENV_NAME
=
getVariableName
(
import
.
meta
.
env
.
VITE_GLOB_APP_TITLE
);
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
unknown
as
GlobEnvConfig
);
const
{
VITE_GLOB_APP_TITLE
,
VITE_GLOB_API_URL
,
VITE_GLOB_API_URL_PREFIX
,
VITE_GLOB_UPLOAD_URL
}
=
ENV
;
return
{
VITE_GLOB_APP_TITLE
,
VITE_GLOB_API_URL
,
VITE_GLOB_API_URL_PREFIX
,
VITE_GLOB_UPLOAD_URL
,
};
}
const
ENV
=
import
.
meta
.
env
as
unknown
as
GlobEnvConfig
const
{
VITE_GLOB_APP_TITLE
,
VITE_GLOB_API_URL
,
VITE_GLOB_API_URL_PREFIX
}
=
ENV
return
{
VITE_GLOB_APP_TITLE
,
VITE_GLOB_API_URL
,
VITE_GLOB_API_URL_PREFIX
}
}
/**
* @description: Development mode
*/
export
const
devMode
=
'development'
;
export
const
devMode
=
'development'
/**
* @description: Production mode
*/
export
const
prodMode
=
'production'
;
export
const
prodMode
=
'production'
/**
* @description: Get environment variables
...
...
@@ -47,7 +27,7 @@ export const prodMode = 'production';
* @example:
*/
export
function
getEnv
():
string
{
return
import
.
meta
.
env
.
MODE
;
return
import
.
meta
.
env
.
MODE
}
/**
...
...
@@ -56,7 +36,7 @@ export function getEnv(): string {
* @example:
*/
export
function
isDevMode
():
boolean
{
return
import
.
meta
.
env
.
DEV
;
return
import
.
meta
.
env
.
DEV
}
/**
...
...
@@ -65,5 +45,5 @@ export function isDevMode(): boolean {
* @example:
*/
export
function
isProdMode
():
boolean
{
return
import
.
meta
.
env
.
PROD
;
}
\ No newline at end of file
return
import
.
meta
.
env
.
PROD
}
types/config.d.ts
View file @
967b0d25
...
...
@@ -136,7 +136,7 @@ export interface GlobConfig {
// Service interface url prefix
urlPrefix
?:
string
;
// Project abbreviation
shortName
:
string
;
shortName
?
:
string
;
}
export
interface
GlobEnvConfig
{
// Site title
...
...
vite.config.ts
View file @
967b0d25
import
vue
from
'@vitejs/plugin-vue'
import
vueJsx
from
'@vitejs/plugin-vue-jsx'
import
{
defineConfig
}
from
'vite'
import
Components
from
'unplugin-vue-components/vite'
;
import
{
AntDesignVueResolver
}
from
'unplugin-vue-components/resolvers'
;
import
Components
from
'unplugin-vue-components/vite'
import
{
AntDesignVueResolver
}
from
'unplugin-vue-components/resolvers'
import
{
createStyleImportPlugin
,
VxeTableResolve
}
from
'vite-plugin-style-import'
import
path
from
'node:path'
...
...
@@ -15,29 +15,29 @@ export default defineConfig({
Components
({
resolvers
:
[
AntDesignVueResolver
({
importStyle
:
false
,
// css in js
})
,
]
,
importStyle
:
false
// css in js
})
]
}),
createStyleImportPlugin
({
resolves
:
[
VxeTableResolve
()]
,
resolves
:
[
VxeTableResolve
()]
})
],
server
:
{
port
:
3001
,
port
:
8089
,
host
:
'0.0.0.0'
,
proxy
:
{
'/api'
:
{
target
:
'http://192.168.66.1
2
5:8070'
,
target
:
'http://192.168.66.1
3
5:8070'
,
changeOrigin
:
true
,
rewrite
:
(
path
)
=>
path
.
replace
(
/^
\/
api/
,
''
)
}
}
}
},
resolve
:
{
alias
:
{
'@'
:
path
.
join
(
__dirname
,
'src'
),
'#'
:
path
.
join
(
__dirname
,
'types'
)
,
'#'
:
path
.
join
(
__dirname
,
'types'
)
}
}
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment