Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
bdc
/
bdcdj-web
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
e4ec2bfe
authored
2023-07-31 15:14:01 +0800
by
renchao@pashanhoo.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
style:图片上传
1 parent
fcf0c30a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
src/views/components/imagePreview.vue
src/views/components/imagePreview.vue
View file @
e4ec2bf
<!--
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-07-
28 14:59:55
* @LastEditTime: 2023-07-
31 15:12:08
-->
<
template
>
<div
class=
"rlPopup"
>
...
...
@@ -223,28 +223,20 @@
clickImage
()
{
this
.
showViewer
=
true
},
// 上传
/**
* @description: 上传
* @param {*} file
* @author: renchao
*/
beforeUpload
(
file
)
{
const
isJPEG
=
file
.
type
===
'image/jpeg'
const
isPNG
=
file
.
type
===
'image/png'
const
isJPG
=
file
.
type
===
'image/jpg'
const
isGIF
=
file
.
type
===
'image/gif'
const
isLt5M
=
file
.
size
/
1024
/
1024
<
5
if
(
!
isJPEG
&&
!
isGIF
&&
!
isPNG
&&
!
isJPG
&&
!
isGIF
)
{
this
.
$message
.
error
(
'请选择jpeg/png/jpg/bmp/gif格式的图片后重试'
)
this
.
loading
=
false
}
const
isLt5M
=
file
.
size
/
1024
/
1024
<
5
;
if
(
!
isLt5M
)
{
this
.
$message
.
error
(
'上传图片大小不能超过 5MB!'
)
this
.
loading
=
false
this
.
$message
.
error
(
'上传图片大小不能超过 5MB!'
)
;
return
false
;
}
this
.
imgHidden
=
(
isJPG
||
isJPEG
||
isPNG
||
isGIF
)
&&
isLt5M
return
this
.
imgHidden
// 所有条件满足时返回 true
return
true
;
},
/**
* @description: handleChange
...
...
@@ -253,17 +245,25 @@
* @author: renchao
*/
async
handleChange
(
file
,
fileList
)
{
if
(
!
this
.
beforeUpload
(
file
))
return
let
length
=
fileList
.
length
;
this
.
maxFileLength
=
Math
.
max
(
length
,
this
.
maxFileLength
)
console
.
log
(
fileList
,
this
.
maxFileLength
,
'this.maxFileLength'
);
var
formData
=
new
FormData
();
let
num
=
0
setTimeout
(()
=>
{
if
(
this
.
maxFileLength
!==
length
)
{
return
}
fileList
.
forEach
(
item
=>
{
if
(
!
[
'image/jpeg'
,
'image/png'
,
'image/jpg'
,
'image/gif'
].
includes
(
item
.
raw
.
type
))
{
num
++
}
formData
.
append
(
'file'
,
item
.
raw
)
})
if
(
num
>=
1
)
{
this
.
$message
.
error
(
"请选择jpeg/png/jpg/bmp/gif格式的图片后重试"
)
return
}
formData
.
append
(
"bsmSj"
,
this
.
previewImg
.
bsmSj
);
formData
.
append
(
"bsmSlsq"
,
this
.
previewImg
.
bsmSlsq
);
uploadBatch
(
formData
).
then
((
res
)
=>
{
...
...
Please
register
or
sign in
to post a comment