add upload page + new nav bar
This commit is contained in:
1 parent
fd71c0b7d6
commit
4dd8d74cea
2 files changed
+193
-49
No files matched your search
+83
-49
@@ -2,6 +2,7 @@
|
|||||||
import Home from './components/Home.vue'
|
import Home from './components/Home.vue'
|
||||||
import Gallery from './components/Gallery.vue';
|
import Gallery from './components/Gallery.vue';
|
||||||
import NotFound from './components/NotFound.vue'
|
import NotFound from './components/NotFound.vue'
|
||||||
|
import Upload from './components/Upload.vue'
|
||||||
import { defineComponent } from 'vue'
|
import { defineComponent } from 'vue'
|
||||||
import { api } from '@/http-api'
|
import { api } from '@/http-api'
|
||||||
import { ImageType, ImageClass } from './image';
|
import { ImageType, ImageClass } from './image';
|
||||||
@@ -9,16 +10,15 @@ import { ImageType, ImageClass } from './image';
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
const routes: { [key: string]: string } = {
|
const routes: { [key: string]: string } = {
|
||||||
'/': "Home",
|
'/': "Home",
|
||||||
'Gallery': "Gallery"
|
'Gallery': "Gallery",
|
||||||
}
|
'Upload': "Upload"
|
||||||
interface InputFileEvent extends Event {
|
|
||||||
target: HTMLInputElement;
|
|
||||||
}
|
}
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
Home,
|
Home,
|
||||||
Gallery,
|
Gallery,
|
||||||
NotFound
|
NotFound,
|
||||||
|
Upload
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -34,28 +34,13 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async submitImage() {
|
|
||||||
if (this.sent == true || this.file == null)
|
|
||||||
return;
|
|
||||||
let formData = new FormData();
|
|
||||||
formData.append('file', this.file[0]);
|
|
||||||
await api.createImage(formData);
|
|
||||||
this.sent = true;
|
|
||||||
(document.getElementById('fileUpload') as HTMLInputElement).value = "";
|
|
||||||
this.updateImageList(100);
|
|
||||||
},
|
|
||||||
handleFilesUpload(event: InputFileEvent) {
|
|
||||||
this.file = event.target.files;
|
|
||||||
this.sent = false;
|
|
||||||
},
|
|
||||||
async updateImageList(sleep: number) {
|
async updateImageList(sleep: number) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
api.getImageList().then((newImages) => {
|
api.getImageList().then((newImages) => {
|
||||||
const newImageList = new Map<number, ImageType>();
|
const newImageList = new Map<number, ImageType>();
|
||||||
for (const image of newImages.values()) {
|
for (const image of newImages.values())
|
||||||
newImageList.set(image.id, image);
|
newImageList.set(image.id, image);
|
||||||
}
|
this.images = newImageList;
|
||||||
this.images = newImageList; console.log(this.images);
|
|
||||||
})
|
})
|
||||||
}, sleep);
|
}, sleep);
|
||||||
},
|
},
|
||||||
@@ -63,6 +48,14 @@ export default defineComponent({
|
|||||||
api.deleteImage(id).then(() => {
|
api.deleteImage(id).then(() => {
|
||||||
this.updateImageList(100);
|
this.updateImageList(100);
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
isActive(route: string) {
|
||||||
|
if (route === undefined) {
|
||||||
|
if (this.currentPath === "")
|
||||||
|
return 'router active';
|
||||||
|
route = "/";
|
||||||
|
}
|
||||||
|
return this.currentPath.endsWith(route) ? 'router active' : 'router';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@@ -74,38 +67,79 @@ export default defineComponent({
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div v-for="route in routes" class="button">
|
<header>
|
||||||
<a :href="'#' + (routes[route] || '/')"> {{ route }}</a>
|
<div class="navi">
|
||||||
</div>
|
<nav>
|
||||||
<div>
|
<ul>
|
||||||
<label>Files
|
<li v-for="route in routes" :class="isActive(routes[route])">
|
||||||
<input id="fileUpload" type="file" @change="handleFilesUpload($event as InputFileEvent)" />
|
<a :href="'#' + (routes[route] || '/')"> <span>{{ route }}</span></a>
|
||||||
</label>
|
</li>
|
||||||
<button :class="sent ? 'green' : 'normal'" @click="submitImage()">{{ sent ? 'Sent' : 'Submit' }}</button>
|
</ul>
|
||||||
</div>
|
</nav>
|
||||||
<component :is="currentView" :key="sent" :images="images" @delete="deleteFile" />
|
</div>
|
||||||
|
</header>
|
||||||
|
<component :is="currentView" :key="sent" :images="images" @delete="deleteFile"
|
||||||
|
@updateImageList="updateImageList(100)" />
|
||||||
</template>
|
</template>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.button {
|
.navi {
|
||||||
display: inline-block;
|
/* reduce size of children */
|
||||||
color: #444;
|
display: flex;
|
||||||
border: 1px solid #CCC;
|
flex-direction: row-reverse;
|
||||||
background: #DDD;
|
|
||||||
box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.2);
|
|
||||||
cursor: pointer;
|
|
||||||
vertical-align: middle;
|
|
||||||
max-width: 100px;
|
|
||||||
padding: 5px;
|
|
||||||
text-align: center;
|
|
||||||
margin: 5px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:active {
|
header {
|
||||||
color: red;
|
display: block;
|
||||||
box-shadow: 0 0 5px -1px rgba(0, 0, 0, 0.6);
|
position: fixed;
|
||||||
|
padding-top: 30px;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
box-sizing: content-box !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.green {
|
ul>li+li {
|
||||||
color: green;
|
margin-left: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul>li {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 5px 15px;
|
||||||
|
border-radius: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
background-color: #12EACB;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active>a {
|
||||||
|
color: rgb(205, 201, 194);
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: rgb(172, 165, 154);
|
||||||
|
text-decoration-color: initial;
|
||||||
|
font-family: "Aeonik", sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
padding-left: 20px;
|
||||||
|
height: 60px;
|
||||||
|
padding-right: 20px;
|
||||||
|
border-radius: 60px;
|
||||||
|
background-color: rgb(24, 26, 27);
|
||||||
|
margin-right: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ul {
|
||||||
|
display: flex;
|
||||||
|
list-style: none;
|
||||||
|
padding-inline-start: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import { api } from '@/http-api';
|
||||||
|
import { ImageType, ImageClass } from '@/image';
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<script lang="ts">
|
||||||
|
|
||||||
|
interface InputFileEvent extends Event {
|
||||||
|
target: HTMLInputElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
emits: ['updateImageList', 'delete'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
sent: false,
|
||||||
|
file: null as FileList | null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
images: {
|
||||||
|
type: Map<number, ImageType>,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async submitImage() {
|
||||||
|
if (this.sent === true || this.file === null)
|
||||||
|
return;
|
||||||
|
let formData = new FormData();
|
||||||
|
formData.append('file', this.file[0]);
|
||||||
|
await api.createImage(formData);
|
||||||
|
this.sent = true;
|
||||||
|
this.$emit('updateImageList');
|
||||||
|
this.resetFile();
|
||||||
|
},
|
||||||
|
handleFilesUpload(event: InputFileEvent) {
|
||||||
|
this.file = event.target.files;
|
||||||
|
this.sent = false;
|
||||||
|
},
|
||||||
|
resetFile() {
|
||||||
|
this.file = null;
|
||||||
|
(document.getElementById('fileUpload') as HTMLInputElement).value = "";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
file() {
|
||||||
|
if (this.file === null)
|
||||||
|
return;
|
||||||
|
Array.from(this.file).forEach((file, id) => {
|
||||||
|
const reader = new window.FileReader();
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
reader.onload = () => {
|
||||||
|
const imgElt = document.getElementById("preview-" + id) as HTMLImageElement;
|
||||||
|
if (imgElt !== null) {
|
||||||
|
if (reader.result as string) {
|
||||||
|
imgElt.setAttribute("src", (reader.result as string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<label>Files
|
||||||
|
<input id="fileUpload" type="file" @change="handleFilesUpload($event as InputFileEvent)" accept="image/jpeg"
|
||||||
|
multiple />
|
||||||
|
</label>
|
||||||
|
<button :class="sent ? 'green' : 'normal'" @click="submitImage()">{{ sent ? 'Sent' : 'Submit' }}</button>
|
||||||
|
<button v-if="file !== null" @click="resetFile()">Reset</button>
|
||||||
|
</div>
|
||||||
|
<h2 v-if="file !== null">Preview :</h2>
|
||||||
|
<div class="previewBox">
|
||||||
|
<label v-for="(f, id) in (file as FileList)" :key="id" class="imageLabel">{{ (f as File).name }}:
|
||||||
|
<img :id="'preview-' + id" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<style scoped>
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 90%;
|
||||||
|
border: 1px solid black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.imageLabel {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
max-width: 33%;
|
||||||
|
height: 33vh;
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.previewBox {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in new issue
Block a user