Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
imageboard-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Trirst
imageboard-web
Commits
7dfc6432
Commit
7dfc6432
authored
Jun 26, 2021
by
Trirst
Browse files
Options
Downloads
Patches
Plain Diff
Implement preview for image upload
parent
b7ab66a7
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#767
passed
Jun 28, 2021
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/ImageUpload.vue
+40
-25
40 additions, 25 deletions
src/components/ImageUpload.vue
with
40 additions
and
25 deletions
src/components/ImageUpload.vue
+
40
−
25
View file @
7dfc6432
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
@
dragover.prevent=
"$event.currentTarget.classList.add('bg-gray-200')"
@
dragover.prevent=
"$event.currentTarget.classList.add('bg-gray-200')"
@
dragleave.prevent=
"$event.currentTarget.classList.remove('bg-gray-200')"
@
dragleave.prevent=
"$event.currentTarget.classList.remove('bg-gray-200')"
>
>
<div
class=
"relative h-full
flex justify-center items-center
"
>
<div
class=
"relative h-full"
>
<input
<input
type=
"file"
type=
"file"
ref=
"imageInput"
ref=
"imageInput"
...
@@ -19,25 +19,38 @@
...
@@ -19,25 +19,38 @@
multiple
multiple
class=
"h-full w-full opacity-0 absolute z-10 cursor-pointer"
class=
"h-full w-full opacity-0 absolute z-10 cursor-pointer"
/>
/>
<span
class=
"font-semibold opacity-25 relative"
>
<div
v-show=
"!imageList.length"
class=
"
h-full
font-semibold
opacity-25
flex
justify-center
items-center
"
>
Drag and drop images here or click here to browse.
Drag and drop images here or click here to browse.
</span>
</div>
<div
v-show=
"imageList.length"
class=
"h-full flex flex-row flex-wrap content-start overflow-y-auto"
>
<img
v-for=
"(preview, index) in previews"
:key=
"index"
:src=
"preview.url"
@
click=
"removeImage(preview.image)"
alt=
""
class=
"max-h-28 relative z-10"
/>
</div>
</div>
</div>
</div>
</div>
<div
class=
"flex flex-col items-center m-4"
>
<div
class=
"flex flex-col items-center m-4"
>
<WarningBox
v-if=
"invalidType"
@
click=
"invalidType = false"
>
<WarningBox
v-if=
"invalidType"
@
click=
"invalidType = false"
>
Please upload PNG, JPEG or GIF image only.
Please upload PNG, JPEG or GIF image only.
</WarningBox>
</WarningBox>
<ul
v-if=
"imageList.length"
>
<li
v-for=
"(image, index) in imageList"
:key=
"index"
@
click=
"removeImage(imageList.indexOf(image))"
class=
"text-gray-600 hover:text-gray-700 font-semibold cursor-pointer"
>
{{
image
.
name
}}
</li>
</ul>
<button
<button
v-show=
"imageList.length"
v-show=
"imageList.length"
@
click=
"submitImage"
@
click=
"submitImage"
...
@@ -69,16 +82,24 @@ export default {
...
@@ -69,16 +82,24 @@ export default {
data
:
()
=>
{
data
:
()
=>
{
return
{
return
{
imageList
:
[],
imageList
:
[],
urls
:
[],
invalidType
:
false
,
invalidType
:
false
,
};
};
},
},
computed
:
{
computed
:
{
previews
:
function
()
{
let
tempArray
=
[];
this
.
imageList
.
forEach
((
image
)
=>
tempArray
.
push
({
url
:
URL
.
createObjectURL
(
image
),
image
})
);
return
tempArray
;
},
...
mapState
([
"
stateUser
"
]),
...
mapState
([
"
stateUser
"
]),
},
},
methods
:
{
methods
:
{
updateWrapper
(
event
)
{
updateWrapper
(
event
)
{
this
.
checkImageType
(
event
)
?
this
.
updateImageList
(
event
)
:
false
;
this
.
checkImageType
(
event
)
?
this
.
updateImageList
(
event
)
:
(
this
.
$refs
.
imageInput
.
value
=
""
);
},
},
updateImageList
(
event
)
{
updateImageList
(
event
)
{
this
.
imageList
=
this
.
imageList
.
concat
(
this
.
imageList
=
this
.
imageList
.
concat
(
...
@@ -99,8 +120,8 @@ export default {
...
@@ -99,8 +120,8 @@ export default {
this
.
invalidType
=
false
;
this
.
invalidType
=
false
;
return
true
;
return
true
;
},
},
removeImage
(
i
ndex
)
{
removeImage
(
i
mage
)
{
this
.
imageList
.
splice
(
index
,
1
);
this
.
imageList
.
splice
(
this
.
imageList
.
indexOf
(
image
)
,
1
);
},
},
submitImage
()
{
submitImage
()
{
let
formData
=
new
FormData
();
let
formData
=
new
FormData
();
...
@@ -121,7 +142,7 @@ export default {
...
@@ -121,7 +142,7 @@ export default {
},
},
body
:
fd
,
body
:
fd
,
};
};
const
response
=
await
fetch
(
"
..
/api/image
"
,
options
);
const
response
=
await
fetch
(
"
/api/image
"
,
options
);
const
data
=
await
response
.
json
();
const
data
=
await
response
.
json
();
this
.
addStateHashArray
(
data
.
hash
);
this
.
addStateHashArray
(
data
.
hash
);
}
catch
{
}
catch
{
...
@@ -132,9 +153,3 @@ export default {
...
@@ -132,9 +153,3 @@ export default {
},
},
};
};
</
script
>
</
script
>
\ No newline at end of file
<
style
scoped
>
[
v-cloak
]
{
display
:
none
;
}
</
style
>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment