This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CanvasView.vue
166 lines (161 loc) · 6.25 KB
/
CanvasView.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<template>
<p class="mt-5 ms-6">Single File Upload</p>
<div class="flex flex-wrap">
<SingleFileUpload :uploadedFile="uploadedFile" :callback="handleFileUploading">
<template v-slot="file">
<div class="m-5">
<div class="flex items-center justify-center">
<label
v-if="!file.file.previewUrl"
for="dropzone-file"
class="flex flex-col items-center justify-center w-full h-56 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer bg-gray-50 dark:hover:bg-bray-800 dark:bg-gray-700 hover:bg-gray-100 dark:border-gray-600 dark:hover:border-gray-500 dark:hover:bg-gray-600"
>
<div class="flex flex-col items-center justify-center pt-5 pb-6 px-10">
<svg
class="w-8 h-8 mb-4 text-gray-500 dark:text-gray-400"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 20 16"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"
/>
</svg>
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400">
<span class="font-semibold">Click to upload</span> or drag and drop
</p>
<p class="text-xs text-gray-500 dark:text-gray-400">SVG, PNG, JPG or GIF</p>
</div>
</label>
<div v-else>
<div class="w-full h-64">
<img
v-if="file.file.previewType != 'video'"
class="h-full w-full object-contain rounded-2xl"
:src="file.file.previewUrl"
/>
<video v-else autoplay loop class="h-full w-full object-contain">
<source :src="file.file.previewUrl" type="video/mp4" />
</video>
</div>
</div>
</div>
<p class="flex items-center justify-center text-center w-3/4">
{{ file.file ? file.file.previewName : '' }}
</p>
</div>
</template>
</SingleFileUpload>
</div>
<br />
<hr />
<p class="mt-5 ms-6">Multiple File Upload</p>
<div class="flex flex-wrap">
<MultipleFileUpload
:removeBtnText="'remove'"
:uploadBtnText="'Save'"
:progressBtnText="'Saving...'"
:uploadedFiles="uploadedFiles"
:callback="handleMultipleFileUpload"
>
<template v-slot="file">
<div class="m-5">
<div class="flex items-center justify-center">
<label
v-if="!file.file"
for="dropzone-file"
class="flex flex-col items-center justify-center w-full h-56 border-2 border-gray-300 border-dashed rounded-lg cursor-pointer bg-gray-50 dark:hover:bg-bray-800 dark:bg-gray-700 hover:bg-gray-100 dark:border-gray-600 dark:hover:border-gray-500 dark:hover:bg-gray-600"
>
<div class="flex flex-col items-center justify-center pt-5 pb-6 px-10">
<svg
class="w-8 h-8 mb-4 text-gray-500 dark:text-gray-400"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 20 16"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"
/>
</svg>
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400">
<span class="font-semibold">Click to upload</span> or drag and drop
</p>
<p class="text-xs text-gray-500 dark:text-gray-400">SVG, PNG, JPG or GIF</p>
</div>
</label>
<div v-else>
<div class="w-full h-64">
<img
v-if="file.file.previewType != 'video'"
class="h-full w-full object-contain rounded-2xl"
:src="file.file.previewUrl"
alt=""
/>
<video v-else autoplay loop class="h-full w-full object-contain">
<source :src="file.file.previewUrl" type="video/mp4" />
</video>
</div>
</div>
</div>
<p class="flex items-center justify-center text-center w-3/4">
{{ file.file ? file.file.previewName : '' }}
</p>
</div>
</template>
</MultipleFileUpload>
</div>
</template>
<script lang="ts">
import { SingleFileUpload, MultipleFileUpload } from '@canopassoftware/vue-file-upload'
export default {
components: {
MultipleFileUpload,
SingleFileUpload
},
data() {
return {
uploadedFile: {} as {
fileType: string
fileUrl: string
fileName: string
},
uploadedFiles: [] as Array<{
fileType: string
fileUrl: string
fileName: string
}>
}
},
methods: {
async handleFileUploading(file: any) {
// add your fileuploading logic to server and set data to the uploadedFile
this.uploadedFile.fileType = 'image'
this.uploadedFile.fileUrl = 'https://picsum.photos/300/224'
this.uploadedFile.fileName = file.name
await new Promise((resolve) => setTimeout(resolve, 2000))
},
async handleMultipleFileUpload(files: any) {
this.uploadedFiles = []
// add your fileuploading logic to server and set data to the uploadedFiles
for (var i = 0; i < files.length; i++) {
this.uploadedFiles.push({
fileType: 'image',
fileUrl: 'https://picsum.photos/300/224',
fileName: 'example-image.jpg'
})
}
await new Promise((resolve) => setTimeout(resolve, 2000))
}
}
}
</script>