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
Unverified
Commit
8d88f420
authored
Feb 28, 2024
by
芋道源码
Committed by
Gitee
Feb 28, 2024
Browse files
Options
Browse Files
Download
Plain Diff
!395 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
Merge pull request !395 from puhui999/dev-crm
parents
9e86e47c
1694827c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
7 deletions
+20
-7
src/api/infra/file/index.ts
+5
-0
src/components/UploadFile/src/useUpload.ts
+15
-7
No files found.
src/api/infra/file/index.ts
View file @
8d88f420
...
@@ -38,3 +38,8 @@ export const getFilePresignedUrl = (path: string) => {
...
@@ -38,3 +38,8 @@ export const getFilePresignedUrl = (path: string) => {
export
const
createFile
=
(
data
:
any
)
=>
{
export
const
createFile
=
(
data
:
any
)
=>
{
return
request
.
post
({
url
:
'/infra/file/create'
,
data
})
return
request
.
post
({
url
:
'/infra/file/create'
,
data
})
}
}
// 上传文件
export
const
updateFile
=
(
data
:
any
)
=>
{
return
request
.
upload
({
url
:
'/infra/file/upload'
,
data
})
}
src/components/UploadFile/src/useUpload.ts
View file @
8d88f420
import
{
getAccessToken
,
getTenantId
}
from
'@/utils/auth'
import
*
as
FileApi
from
'@/api/infra/file'
import
*
as
FileApi
from
'@/api/infra/file'
import
CryptoJS
from
'crypto-js'
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
{
ajaxUpload
}
from
'element-plus/es/components/upload/src/ajax'
import
axios
from
'axios'
import
axios
from
'axios'
export
const
useUpload
=
()
=>
{
export
const
useUpload
=
()
=>
{
...
@@ -26,11 +24,21 @@ export const useUpload = () => {
...
@@ -26,11 +24,21 @@ export const useUpload = () => {
return
{
data
:
presignedInfo
.
url
}
return
{
data
:
presignedInfo
.
url
}
})
})
}
else
{
}
else
{
// 模式二:后端上传(需要增加后端身份认证请求头)
// 模式二:后端上传
options
.
headers
[
'Authorization'
]
=
'Bearer '
+
getAccessToken
()
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
options
.
headers
[
'tenant-id'
]
=
getTenantId
()
return
new
Promise
((
resolve
,
reject
)
=>
{
// 使用 ElUpload 的上传方法
FileApi
.
updateFile
({
file
:
options
.
file
})
return
ajaxUpload
(
options
)
.
then
((
res
)
=>
{
if
(
res
.
code
===
0
)
{
resolve
(
res
)
}
else
{
reject
(
res
)
}
})
.
catch
((
res
)
=>
{
reject
(
res
)
})
})
}
}
}
}
...
...
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