Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pet-business-web
Project
Project
Details
Activity
Releases
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
刘怀志
pet-business-web
Commits
1ce859af
Commit
1ce859af
authored
Aug 22, 2023
by
陈明豪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug修改
parent
9af070a5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
16 deletions
+36
-16
config.js
src/api/system/config.js
+9
-0
index.vue
src/components/ImageUpload/index.vue
+27
-16
No files found.
src/api/system/config.js
View file @
1ce859af
...
...
@@ -66,3 +66,12 @@ export function uploadCommon(data) {
data
})
}
export
function
uploadMino
(
data
)
{
return
request
({
headers
:
{
'Content-Type'
:
'multipart/form-data'
},
url
:
'/business/common/uploadMinioPublic'
,
method
:
'post'
,
data
})
}
src/components/ImageUpload/index.vue
View file @
1ce859af
...
...
@@ -12,6 +12,7 @@
ref=
"imageUpload"
multiple
action
:accept=
"['.jpg', '.png', 'jpeg']"
list-type=
"picture-card"
:on-success=
"handleUploadSuccess"
:before-upload=
"handleBeforeUpload"
...
...
@@ -84,7 +85,7 @@
import
ImageCropperModal
from
'@/components/imageCropper/index'
import
{
getToken
}
from
'@/utils/auth'
import
{
upload
Common
}
from
'@/api/system/config'
import
{
upload
Mino
}
from
'@/api/system/config'
export
default
{
components
:
{
...
...
@@ -129,7 +130,7 @@ export default {
dialogVisible
:
false
,
hideUpload
:
false
,
baseUrl
:
process
.
env
.
VUE_APP_TEST_API
,
uploadImgUrl
:
process
.
env
.
VUE_APP_BASE_API
+
'/
common/upload
'
,
// 上传的图片服务器地址
uploadImgUrl
:
process
.
env
.
VUE_APP_BASE_API
+
'/
business/common/uploadMinioPublic
'
,
// 上传的图片服务器地址
headers
:
{
Authorization
:
'Bearer '
+
getToken
()
},
...
...
@@ -175,9 +176,16 @@ export default {
var
img
=
file
.
name
.
substring
(
file
.
name
.
lastIndexOf
(
'.'
)
+
1
)
const
suffix
=
img
===
'jpg'
||
img
===
'png'
||
img
===
'jpeg'
if
(
!
suffix
)
{
this
.
$message
.
error
(
`文件格式不正确, 请上传
${
this
.
fileType
.
join
(
'/'
)}
图片格式文件`
)
this
.
$message
.
error
(
'文件格式不正确, 请上传png/jpg/jpeg图片格式文件!'
)
return
false
}
if
(
this
.
fileSize
)
{
const
isLt
=
file
.
size
/
1024
/
1024
<
this
.
fileSize
if
(
!
isLt
)
{
this
.
$modal
.
msgError
(
`上传图片大小不能超过
${
this
.
fileSize
}
MB`
)
return
false
}
}
// URL.createObjectURL的参数只能是blob或者file类型
// 第一种方法用FileReader,URL.createObjectURL接收blob类型
const
reader
=
new
FileReader
()
...
...
@@ -207,22 +215,25 @@ export default {
// 第三个参数可以设定一些文件的属性,比如文件的MIME,最后更新时间等
const
file
=
new
File
([
blob
],
this
.
fileName
,
{
type
:
blob
.
type
,
lastModified
:
Date
.
now
()
})
file
.
uid
=
Date
.
now
()
form
.
append
(
'
f
ile'
,
file
)
form
.
append
(
'
multipartF
ile'
,
file
)
// 如果想在这里打印查看form的值,会发现它是空对象
// 解决办法,需要用form.get('键')的方法获取值
// console.log(form.get('file'))
// 这里调用接口,获取后端返给的图片地址
this
.
number
++
uploadCommon
(
form
).
then
(
res
=>
{
uploadMino
(
form
).
then
(
res
=>
{
console
.
log
(
'moni'
,
res
)
this
.
cropperVisible
=
false
if
(
res
.
code
===
200
)
{
this
.
uploadList
.
push
({
name
:
res
.
fileName
,
url
:
res
.
fileName
})
if
(
res
)
{
this
.
uploadList
.
push
({
name
:
res
,
url
:
res
})
console
.
log
(
'111'
)
this
.
uploadedSuccessfully
()
}
else
{
this
.
number
--
// this.$modal.closeLoading()
this
.
$modal
.
msgError
(
res
.
msg
)
//
this.$modal.msgError(res.msg)
this
.
$refs
.
imageUpload
.
handleRemove
(
file
)
console
.
log
(
'222'
)
this
.
uploadedSuccessfully
()
}
}).
catch
(
err
=>
{
...
...
@@ -257,13 +268,13 @@ export default {
}
if
(
!
isImg
)
{
this
.
$modal
.
msgError
(
`文件格式不正确, 请上传
${
this
.
fileType
.
join
(
'/'
)}
图片格式文件
!
`
)
this
.
$modal
.
msgError
(
`文件格式不正确, 请上传
${
this
.
fileType
.
join
(
'/'
)}
图片格式文件`
)
return
false
}
if
(
this
.
fileSize
)
{
const
isLt
=
file
.
size
/
1024
/
1024
<
=
this
.
fileSize
const
isLt
=
file
.
size
/
1024
/
1024
<
this
.
fileSize
if
(
!
isLt
)
{
this
.
$modal
.
msgError
(
`上传图片大小不能超过
${
this
.
fileSize
}
MB
!
`
)
this
.
$modal
.
msgError
(
`上传图片大小不能超过
${
this
.
fileSize
}
MB`
)
return
false
}
}
...
...
@@ -272,7 +283,7 @@ export default {
},
// 文件个数超出
handleExceed
()
{
this
.
$modal
.
msgError
(
`上传文件数量不能超过
${
this
.
limit
}
个
!
`
)
this
.
$modal
.
msgError
(
`上传文件数量不能超过
${
this
.
limit
}
个`
)
},
// 上传成功回调
handleUploadSuccess
(
res
,
file
)
{
...
...
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