Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
26b025ac
authored
Sep 24, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【代码优化】全局:移除 VITE_UPLOAD_URL 环境变量,使用 getUploadUrl 方法替代
parent
74e04279
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
23 additions
and
24 deletions
+23
-24
.env.dev
+0
-2
.env.local
+0
-2
.env.prod
+0
-2
.env.stage
+0
-2
.env.test
+0
-2
src/components/Editor/src/Editor.vue
+3
-2
src/components/UploadFile/src/useUpload.ts
+20
-11
types/env.d.ts
+0
-1
No files found.
.env.dev
View file @
26b025ac
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://api-dashboard.yudao.iocoder.cn'
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://api-dashboard.yudao.iocoder.cn'
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
VITE_UPLOAD_TYPE=server
VITE_UPLOAD_TYPE=server
# 上传路径
VITE_UPLOAD_URL='http://api-dashboard.yudao.iocoder.cn/admin-api/infra/file/upload'
# 接口地址
# 接口地址
VITE_API_URL=/admin-api
VITE_API_URL=/admin-api
...
...
.env.local
View file @
26b025ac
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://localhost:48080'
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://localhost:48080'
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务
VITE_UPLOAD_TYPE=server
VITE_UPLOAD_TYPE=server
# 上传路径
VITE_UPLOAD_URL='http://localhost:48080/admin-api/infra/file/upload'
# 接口地址
# 接口地址
VITE_API_URL=/admin-api
VITE_API_URL=/admin-api
...
...
.env.prod
View file @
26b025ac
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://localhost:48080'
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://localhost:48080'
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
VITE_UPLOAD_TYPE=server
VITE_UPLOAD_TYPE=server
# 上传路径
VITE_UPLOAD_URL='http://localhost:48080/admin-api/infra/file/upload'
# 接口地址
# 接口地址
VITE_API_URL=/admin-api
VITE_API_URL=/admin-api
...
...
.env.stage
View file @
26b025ac
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://api-dashboard.yudao.iocoder.cn'
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://api-dashboard.yudao.iocoder.cn'
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
VITE_UPLOAD_TYPE=server
VITE_UPLOAD_TYPE=server
# 上传路径
VITE_UPLOAD_URL='http://api-dashboard.yudao.iocoder.cn/admin-api/infra/file/upload'
# 接口地址
# 接口地址
VITE_API_URL=/admin-api
VITE_API_URL=/admin-api
...
...
.env.test
View file @
26b025ac
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://localhost:48080'
...
@@ -8,8 +8,6 @@ VITE_BASE_URL='http://localhost:48080'
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
VITE_UPLOAD_TYPE
=
server
VITE_UPLOAD_TYPE
=
server
# 上传路径
VITE_UPLOAD_URL
=
'http://localhost:48080/admin-api/infra/file/upload'
# 接口地址
# 接口地址
VITE_API_URL
=/
admin
-
api
VITE_API_URL
=/
admin
-
api
...
...
src/components/Editor/src/Editor.vue
View file @
26b025ac
...
@@ -7,6 +7,7 @@ import { isNumber } from '@/utils/is'
...
@@ -7,6 +7,7 @@ import { isNumber } from '@/utils/is'
import
{
ElMessage
}
from
'element-plus'
import
{
ElMessage
}
from
'element-plus'
import
{
useLocaleStore
}
from
'@/store/modules/locale'
import
{
useLocaleStore
}
from
'@/store/modules/locale'
import
{
getAccessToken
,
getTenantId
}
from
'@/utils/auth'
import
{
getAccessToken
,
getTenantId
}
from
'@/utils/auth'
import
{
getUploadUrl
}
from
'@/components/UploadFile/src/useUpload'
defineOptions
({
name
:
'Editor'
})
defineOptions
({
name
:
'Editor'
})
...
@@ -88,7 +89,7 @@ const editorConfig = computed((): IEditorConfig => {
...
@@ -88,7 +89,7 @@ const editorConfig = computed((): IEditorConfig => {
scroll
:
true
,
scroll
:
true
,
MENU_CONF
:
{
MENU_CONF
:
{
[
'uploadImage'
]:
{
[
'uploadImage'
]:
{
server
:
import
.
meta
.
env
.
VITE_UPLOAD_URL
,
server
:
getUploadUrl
()
,
// 单个文件的最大体积限制,默认为 2M
// 单个文件的最大体积限制,默认为 2M
maxFileSize
:
5
*
1024
*
1024
,
maxFileSize
:
5
*
1024
*
1024
,
// 最多可上传几个文件,默认为 100
// 最多可上传几个文件,默认为 100
...
@@ -136,7 +137,7 @@ const editorConfig = computed((): IEditorConfig => {
...
@@ -136,7 +137,7 @@ const editorConfig = computed((): IEditorConfig => {
}
}
},
},
[
'uploadVideo'
]:
{
[
'uploadVideo'
]:
{
server
:
import
.
meta
.
env
.
VITE_UPLOAD_URL
,
server
:
getUploadUrl
()
,
// 单个文件的最大体积限制,默认为 10M
// 单个文件的最大体积限制,默认为 10M
maxFileSize
:
10
*
1024
*
1024
,
maxFileSize
:
10
*
1024
*
1024
,
// 最多可上传几个文件,默认为 100
// 最多可上传几个文件,默认为 100
...
...
src/components/UploadFile/src/useUpload.ts
View file @
26b025ac
...
@@ -3,9 +3,16 @@ import CryptoJS from 'crypto-js'
...
@@ -3,9 +3,16 @@ import CryptoJS from 'crypto-js'
import
{
UploadRawFile
,
UploadRequestOptions
}
from
'element-plus/es/components/upload/src/upload'
import
{
UploadRawFile
,
UploadRequestOptions
}
from
'element-plus/es/components/upload/src/upload'
import
axios
from
'axios'
import
axios
from
'axios'
/**
* 获得上传 URL
*/
export
const
getUploadUrl
=
():
string
=>
{
return
import
.
meta
.
env
.
VITE_BASE_URL
+
import
.
meta
.
env
.
VITE_API_URL
+
'/infra/file/upload'
}
export
const
useUpload
=
()
=>
{
export
const
useUpload
=
()
=>
{
// 后端上传地址
// 后端上传地址
const
uploadUrl
=
import
.
meta
.
env
.
VITE_UPLOAD_URL
const
uploadUrl
=
getUploadUrl
()
// 是否使用前端直连上传
// 是否使用前端直连上传
const
isClientUpload
=
UPLOAD_TYPE
.
CLIENT
===
import
.
meta
.
env
.
VITE_UPLOAD_TYPE
const
isClientUpload
=
UPLOAD_TYPE
.
CLIENT
===
import
.
meta
.
env
.
VITE_UPLOAD_TYPE
// 重写ElUpload上传方法
// 重写ElUpload上传方法
...
@@ -17,16 +24,18 @@ export const useUpload = () => {
...
@@ -17,16 +24,18 @@ export const useUpload = () => {
// 1.2 获取文件预签名地址
// 1.2 获取文件预签名地址
const
presignedInfo
=
await
FileApi
.
getFilePresignedUrl
(
fileName
)
const
presignedInfo
=
await
FileApi
.
getFilePresignedUrl
(
fileName
)
// 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持)
// 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持)
return
axios
.
put
(
presignedInfo
.
uploadUrl
,
options
.
file
,
{
return
axios
headers
:
{
.
put
(
presignedInfo
.
uploadUrl
,
options
.
file
,
{
'Content-Type'
:
options
.
file
.
type
,
headers
:
{
}
'Content-Type'
:
options
.
file
.
type
}).
then
(()
=>
{
}
// 1.4. 记录文件信息到后端(异步)
})
createFile
(
presignedInfo
,
fileName
,
options
.
file
)
.
then
(()
=>
{
// 通知成功,数据格式保持与后端上传的返回结果一致
// 1.4. 记录文件信息到后端(异步)
return
{
data
:
presignedInfo
.
url
}
createFile
(
presignedInfo
,
fileName
,
options
.
file
)
})
// 通知成功,数据格式保持与后端上传的返回结果一致
return
{
data
:
presignedInfo
.
url
}
})
}
else
{
}
else
{
// 模式二:后端上传
// 模式二:后端上传
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
...
...
types/env.d.ts
View file @
26b025ac
...
@@ -19,7 +19,6 @@ interface ImportMetaEnv {
...
@@ -19,7 +19,6 @@ interface ImportMetaEnv {
readonly
VITE_APP_DEFAULT_LOGIN_PASSWORD
:
string
readonly
VITE_APP_DEFAULT_LOGIN_PASSWORD
:
string
readonly
VITE_APP_DOCALERT_ENABLE
:
string
readonly
VITE_APP_DOCALERT_ENABLE
:
string
readonly
VITE_BASE_URL
:
string
readonly
VITE_BASE_URL
:
string
readonly
VITE_UPLOAD_URL
:
string
readonly
VITE_API_URL
:
string
readonly
VITE_API_URL
:
string
readonly
VITE_BASE_PATH
:
string
readonly
VITE_BASE_PATH
:
string
readonly
VITE_DROP_DEBUGGER
:
string
readonly
VITE_DROP_DEBUGGER
:
string
...
...
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