Skip to content

Commit 0e45979

Browse files
committed
feat(filePreview): Preview image on Room.vue when click image
1 parent be5b7f8 commit 0e45979

File tree

4 files changed

+182
-4
lines changed

4 files changed

+182
-4
lines changed

src/lib/Room/Room.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
v-if="showFiles"
279279
ref="file"
280280
type="file"
281-
multiple
281+
multiple
282282
:accept="acceptedFiles"
283283
style="display: none"
284284
@change="onFileChange($event.target.files)"
@@ -297,6 +297,7 @@
297297
</div>
298298
</div>
299299
</div>
300+
<RoomFilePreview v-show="fileModal" :file="modalFile" :current-user-id="currentUserId" @close-file-modal="fileModal=false"/>
300301
</div>
301302
</template>
302303

@@ -314,6 +315,7 @@ import RoomMessageReply from './RoomMessageReply/RoomMessageReply'
314315
import RoomUsersTag from './RoomUsersTag/RoomUsersTag'
315316
import RoomEmojis from './RoomEmojis/RoomEmojis'
316317
import RoomTemplatesText from './RoomTemplatesText/RoomTemplatesText'
318+
import RoomFilePreview from './RoomFilePreview/RoomFilePreview'
317319
import Message from '../Message/Message'
318320
319321
import filteredItems from '../../utils/filter-items'
@@ -343,7 +345,8 @@ export default {
343345
RoomUsersTag,
344346
RoomEmojis,
345347
RoomTemplatesText,
346-
Message
348+
Message,
349+
RoomFilePreview
347350
},
348351
349352
directives: {
@@ -431,7 +434,11 @@ export default {
431434
emojisDB: new Database(),
432435
recorder: this.initRecorder(),
433436
isRecording: false,
434-
format: 'mp3'
437+
format: 'mp3',
438+
fileModal: false,
439+
modalFile: {
440+
url: ''
441+
}
435442
}
436443
},
437444
@@ -1202,7 +1209,12 @@ export default {
12021209
}
12031210
},
12041211
openFile({ message, file }) {
1205-
this.$emit('open-file', { message, file })
1212+
if (file.action === 'preview') {
1213+
this.fileModal = true
1214+
this.modalFile = Object.assign({}, this.modalFile, file.file)
1215+
} else {
1216+
this.$emit('open-file', { message, file })
1217+
}
12061218
},
12071219
openUserTag(user) {
12081220
this.$emit('open-user-tag', user)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.vac-room-file-preview {
2+
position: absolute;
3+
width: 100%;
4+
height: 100%;
5+
z-index: 11;
6+
7+
.vac-room-file-preview-container {
8+
width: 100%;
9+
height: 100%;
10+
background-color: rgba(0, 0, 0, 0.5);
11+
}
12+
13+
.vac-image-preview {
14+
width: 100%;
15+
height: 100%;
16+
background-size: contain !important;
17+
background-repeat: no-repeat;
18+
background-position: center;
19+
}
20+
21+
//.vac-video-preview {
22+
// position: absolute;
23+
// width: 100%;
24+
// height: 100%;
25+
// border-radius: 4px;
26+
// background: linear-gradient(
27+
// to bottom,
28+
// rgba(0, 0, 0, 0) 55%,
29+
// rgba(0, 0, 0, 0.02) 60%,
30+
// rgba(0, 0, 0, 0.05) 65%,
31+
// rgba(0, 0, 0, 0.1) 70%,
32+
// rgba(0, 0, 0, 0.2) 75%,
33+
// rgba(0, 0, 0, 0.3) 80%,
34+
// rgba(0, 0, 0, 0.5) 85%,
35+
// rgba(0, 0, 0, 0.6) 90%,
36+
// rgba(0, 0, 0, 0.7) 95%,
37+
// rgba(0, 0, 0, 0.8) 100%
38+
// );
39+
//
40+
// svg {
41+
// height: 26px;
42+
// width: 26px;
43+
// }
44+
//
45+
// .vac-button-view,
46+
// .vac-button-download {
47+
// position: absolute;
48+
// bottom: 6px;
49+
// left: 7px;
50+
// }
51+
//
52+
// :first-child {
53+
// left: 40px;
54+
// }
55+
//
56+
// .vac-button-view {
57+
// max-width: 18px;
58+
// bottom: 8px;
59+
// }
60+
//}
61+
//
62+
//.vac-video-container {
63+
// width: 350px;
64+
// max-width: 100%;
65+
// margin: 4px auto 5px;
66+
//
67+
// video {
68+
// border-radius: 4px;
69+
// }
70+
//}
71+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<template>
2+
<div class="vac-room-file-preview">
3+
<div
4+
v-if="isImage"
5+
class="vac-room-file-preview-container"
6+
@click.stop="$emit('close-file-modal')"
7+
@keypress.esc="$emit('close-file-modal')"
8+
>
9+
<loader
10+
:show="isImageLoading"
11+
/>
12+
<div
13+
class="vac-image-preview"
14+
:style="{
15+
'background-image': `url('${
16+
isImageLoading ? file.preview || file.url : file.url
17+
}')`
18+
}"
19+
@keypress.esc="$emit('close-file-modal')"
20+
/>
21+
</div>
22+
23+
<div
24+
v-else-if="isVideo"
25+
class="vac-video-preview"
26+
@keypress.esc="$emit('close-file-modal')"
27+
>
28+
<video width="100%" height="100%" controls>
29+
<source :src="file.url" />
30+
</video>
31+
</div>
32+
<button @click="$emit('close-file-modal')">
33+
Close
34+
</button>
35+
</div>
36+
</template>
37+
<script>
38+
39+
import Loader from '../../../components/Loader/Loader'
40+
// import SvgIcon from '../../../components/SvgIcon/SvgIcon'
41+
42+
const { isImageFile, isVideoFile } = require('../../../utils/media-file')
43+
44+
export default {
45+
name: 'RoomFilePreview',
46+
components: {
47+
// SvgIcon,
48+
Loader
49+
},
50+
51+
props: {
52+
file: { type: Object, required: true }
53+
},
54+
55+
emits: ['open-file'],
56+
57+
data() {
58+
return {
59+
imageLoading: false
60+
}
61+
},
62+
computed: {
63+
isImageLoading() {
64+
return this.file.url.indexOf('blob:http') !== -1 || this.imageLoading
65+
},
66+
isImage() {
67+
return isImageFile(this.file)
68+
},
69+
isVideo() {
70+
if (this.file.url) return isVideoFile(this.file)
71+
else return false
72+
}
73+
},
74+
75+
watch: {
76+
file: {
77+
immediate: true,
78+
deep: true,
79+
handler() {
80+
this.checkImgLoad()
81+
}
82+
}
83+
},
84+
methods: {
85+
checkImgLoad() {
86+
if (!isImageFile(this.file)) return
87+
this.imageLoading = true
88+
const image = new Image()
89+
image.src = this.file.url
90+
image.addEventListener('load', () => (this.imageLoading = false))
91+
}
92+
}
93+
}
94+
</script>

src/styles/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@import '../lib/Room/RoomFiles/RoomFile/RoomFile';
1313
@import '../lib/Room/RoomUsersTag/RoomUsersTag';
1414
@import '../lib/Room/RoomTemplatesText/RoomTemplatesText';
15+
@import '../lib/Room/RoomFilePreview/RoomFilePreview';
1516

1617
@import '../lib/RoomsList/RoomsList';
1718
@import '../lib/RoomsList/RoomContent/RoomContent';

0 commit comments

Comments
 (0)