mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
370 lines
10 KiB
370 lines
10 KiB
4 years ago
|
<template>
|
||
|
<div class="main">
|
||
|
<div class="d-flex align-center img-container">
|
||
3 years ago
|
<div v-for="(item, i) in localState" :key="i" class="thumbnail align-center justify-center d-flex">
|
||
4 years ago
|
<v-tooltip bottom>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
4 years ago
|
<v-img
|
||
3 years ago
|
v-if="isImage(item.title)"
|
||
4 years ago
|
:key="item.url"
|
||
3 years ago
|
lazy-src="https://via.placeholder.com/60.png?text=Loading..."
|
||
|
alt="#"
|
||
|
max-height="33px"
|
||
|
contain
|
||
|
:src="item.url"
|
||
|
v-on="on"
|
||
3 years ago
|
@click="selectImage(item.url, i)"
|
||
3 years ago
|
>
|
||
|
<template #placeholder>
|
||
|
<v-skeleton-loader type="image" height="33" width="33" />
|
||
4 years ago
|
</template>
|
||
|
</v-img>
|
||
3 years ago
|
<v-icon v-else-if="item.icon" size="33" v-on="on" @click="openUrl(item.url, '_blank')">
|
||
|
{{ item.icon }}
|
||
3 years ago
|
</v-icon>
|
||
3 years ago
|
<v-icon v-else size="33" v-on="on" @click="openUrl(item.url, '_blank')"> mdi-file </v-icon>
|
||
4 years ago
|
</template>
|
||
|
<span>{{ item.title }}</span>
|
||
|
</v-tooltip>
|
||
|
</div>
|
||
|
|
||
|
<div class="add d-flex align-center justify-center px-1" @click="addFile">
|
||
3 years ago
|
<v-icon v-if="uploading" small color="primary"> mdi-loading mdi-spin </v-icon>
|
||
|
<v-icon v-else small color="primary"> mdi-plus </v-icon>
|
||
4 years ago
|
</div>
|
||
|
|
||
3 years ago
|
<v-spacer />
|
||
4 years ago
|
|
||
3 years ago
|
<v-icon class="expand-icon mr-1" x-small color="primary" @click.stop="dialog = true"> mdi-arrow-expand </v-icon>
|
||
|
<input ref="file" type="file" multiple class="d-none" @change="onFileSelection" />
|
||
4 years ago
|
</div>
|
||
|
|
||
3 years ago
|
<v-dialog v-model="dialog" width="800">
|
||
4 years ago
|
<v-card class="h-100 images-modal">
|
||
|
<v-card-text class="h-100 backgroundColor">
|
||
3 years ago
|
<v-btn small class="my-4" :loading="uploading" @click="addFile">
|
||
3 years ago
|
<v-icon small class="mr-2"> mdi-link-variant </v-icon>
|
||
4 years ago
|
Attach File
|
||
|
</v-btn>
|
||
|
|
||
|
<div class="d-flex flex-wrap h-100">
|
||
3 years ago
|
<v-container fluid style="max-height: calc(90vh - 80px); overflow-y: auto">
|
||
4 years ago
|
<v-row>
|
||
3 years ago
|
<v-col v-for="(item, i) in localState" :key="i" cols="4">
|
||
3 years ago
|
<v-card
|
||
|
class="modal-thumbnail-card align-center justify-center d-flex"
|
||
|
height="200px"
|
||
|
style="position: relative"
|
||
|
>
|
||
3 years ago
|
<v-icon small class="remove-icon" @click="removeItem(i)"> mdi-close-circle </v-icon>
|
||
|
<div class="pa-2 d-flex align-center" style="height: 200px">
|
||
3 years ago
|
<img
|
||
|
v-if="isImage(item.title)"
|
||
3 years ago
|
style="max-height: 100%; max-width: 100%"
|
||
3 years ago
|
alt="#"
|
||
|
:src="item.url"
|
||
3 years ago
|
@click="selectImage(item.url, i)"
|
||
|
/>
|
||
3 years ago
|
|
||
3 years ago
|
<v-icon v-else-if="item.icon" size="33" @click="openUrl(item.url, '_blank')">
|
||
|
{{ item.icon }}
|
||
3 years ago
|
</v-icon>
|
||
3 years ago
|
<v-icon v-else size="33" @click="openUrl(item.url, '_blank')"> mdi-file </v-icon>
|
||
4 years ago
|
</div>
|
||
|
</v-card>
|
||
3 years ago
|
<p class="caption mt-2 modal-title" :title="item.title">
|
||
|
{{ item.title }}
|
||
|
</p>
|
||
4 years ago
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-container>
|
||
|
</div>
|
||
|
</v-card-text>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
|
||
|
<v-overlay v-model="showImage" z-index="99999" opacity=".93">
|
||
3 years ago
|
<div v-click-outside="hideIfVisible" class="image-overlay-container">
|
||
|
<v-carousel v-if="showImage && selectedImage" v-model="carousel" height="calc(100vh - 100px)" hide-delimiters>
|
||
3 years ago
|
<v-carousel-item v-for="(item, i) in localState" :key="i">
|
||
4 years ago
|
<div class="mx-auto d-flex flex-column justify-center align-center">
|
||
3 years ago
|
<p class="title text-center">
|
||
|
{{ item.title }}
|
||
|
</p>
|
||
4 years ago
|
|
||
3 years ago
|
<div style="width: 90vh; height: calc(100vh - 150px)" class="d-flex align-center justify-center">
|
||
3 years ago
|
<img
|
||
|
v-if="isImage(item.title)"
|
||
3 years ago
|
style="max-width: 90vh; max-height: calc(100vh - 100px)"
|
||
3 years ago
|
:src="item.url"
|
||
3 years ago
|
/>
|
||
3 years ago
|
<v-icon v-else-if="item.icon" size="55">
|
||
|
{{ item.icon }}
|
||
|
</v-icon>
|
||
3 years ago
|
<v-icon v-else size="55"> mdi-file </v-icon>
|
||
4 years ago
|
</div>
|
||
|
</div>
|
||
|
</v-carousel-item>
|
||
|
</v-carousel>
|
||
|
<v-sheet
|
||
|
class="mx-auto align-center justify-center"
|
||
|
max-width="90vw"
|
||
|
height="80px"
|
||
|
style="background: transparent"
|
||
|
>
|
||
3 years ago
|
<v-slide-group multiple show-arrows>
|
||
|
<v-slide-item v-for="(item, i) in localState" :key="i">
|
||
4 years ago
|
<!-- <div class="d-flex justify-center" style="height:80px">-->
|
||
|
<v-card
|
||
3 years ago
|
:key="i"
|
||
4 years ago
|
class="ma-2 pa-2 d-flex align-center justify-center overlay-thumbnail"
|
||
3 years ago
|
:class="{ active: carousel === i }"
|
||
3 years ago
|
width="48"
|
||
|
height="48"
|
||
4 years ago
|
@click="carousel = i"
|
||
3 years ago
|
>
|
||
3 years ago
|
<img v-if="isImage(item.title)" style="max-width: 100%; max-height: 100%" :src="item.url" />
|
||
3 years ago
|
<v-icon v-else-if="item.icon" size="48">
|
||
|
{{ item.icon }}
|
||
|
</v-icon>
|
||
3 years ago
|
<v-icon v-else size="48"> mdi-file </v-icon>
|
||
4 years ago
|
</v-card>
|
||
|
<!-- </div>-->
|
||
|
</v-slide-item>
|
||
|
</v-slide-group>
|
||
|
</v-sheet>
|
||
|
|
||
3 years ago
|
<v-icon x-large class="close-icon" @click="showImage = false"> mdi-close-circle </v-icon>
|
||
4 years ago
|
</div>
|
||
|
</v-overlay>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { isImage } from '@/components/project/spreadsheet/helpers/imageExt';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'Attachment',
|
||
4 years ago
|
props: ['dbAlias', 'value'],
|
||
3 years ago
|
data: () => ({
|
||
|
carousel: null,
|
||
|
uploading: false,
|
||
|
localState: '',
|
||
|
dialog: false,
|
||
|
showImage: false,
|
||
3 years ago
|
selectedImage: null,
|
||
3 years ago
|
}),
|
||
|
watch: {
|
||
3 years ago
|
value(val) {
|
||
3 years ago
|
try {
|
||
3 years ago
|
this.localState = (typeof val === 'string' ? JSON.parse(val) : val) || [];
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
this.localState = [];
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
3 years ago
|
// localState(val) {
|
||
|
// if (this.isForm) {
|
||
|
// this.$emit('input', JSON.stringify(val))
|
||
|
// }
|
||
|
// }
|
||
|
},
|
||
3 years ago
|
created() {
|
||
3 years ago
|
try {
|
||
3 years ago
|
this.localState = (typeof this.value === 'string' ? JSON.parse(this.value) : this.value) || [];
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
this.localState = [];
|
||
3 years ago
|
}
|
||
3 years ago
|
document.addEventListener('keydown', this.onArrowDown);
|
||
3 years ago
|
},
|
||
3 years ago
|
beforeDestroy() {
|
||
3 years ago
|
document.removeEventListener('keydown', this.onArrowDown);
|
||
3 years ago
|
},
|
||
3 years ago
|
mounted() {},
|
||
4 years ago
|
methods: {
|
||
3 years ago
|
openUrl(url, target) {
|
||
3 years ago
|
window.open(url, target);
|
||
4 years ago
|
},
|
||
|
isImage,
|
||
3 years ago
|
hideIfVisible() {
|
||
4 years ago
|
if (this.showImage) {
|
||
3 years ago
|
this.showImage = false;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
selectImage(selectedImage, i) {
|
||
3 years ago
|
this.showImage = true;
|
||
|
this.carousel = i;
|
||
|
this.selectedImage = selectedImage;
|
||
4 years ago
|
},
|
||
3 years ago
|
addFile() {
|
||
3 years ago
|
this.$refs.file.click();
|
||
4 years ago
|
},
|
||
3 years ago
|
async onFileSelection() {
|
||
4 years ago
|
if (!this.$refs.file.files || !this.$refs.file.files.length) {
|
||
3 years ago
|
return;
|
||
4 years ago
|
}
|
||
3 years ago
|
this.uploading = true;
|
||
4 years ago
|
for (const file of this.$refs.file.files) {
|
||
3 years ago
|
const item = await this.$store.dispatch('sqlMgr/ActUploadOld', [
|
||
|
{
|
||
|
dbAlias: this.dbAlias,
|
||
|
},
|
||
|
'xcAttachmentUpload',
|
||
|
{ public: true },
|
||
|
file,
|
||
|
]);
|
||
|
this.localState.push(item);
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
this.uploading = false;
|
||
|
this.$emit('input', JSON.stringify(this.localState));
|
||
|
this.$emit('update');
|
||
4 years ago
|
},
|
||
3 years ago
|
removeItem(i) {
|
||
3 years ago
|
this.localState.splice(i, 1);
|
||
|
this.$emit('input', JSON.stringify(this.localState));
|
||
|
this.$emit('update');
|
||
4 years ago
|
},
|
||
3 years ago
|
onArrowDown(e) {
|
||
3 years ago
|
if (!this.showImage) {
|
||
|
return;
|
||
|
}
|
||
|
e = e || window.event;
|
||
3 years ago
|
// eslint-disable-next-line eqeqeq
|
||
4 years ago
|
if (e.keyCode == '37') {
|
||
3 years ago
|
this.carousel = (this.carousel || this.localState.length) - 1;
|
||
3 years ago
|
// eslint-disable-next-line eqeqeq
|
||
4 years ago
|
} else if (e.keyCode == '39') {
|
||
3 years ago
|
this.carousel = ++this.carousel % this.localState.length;
|
||
4 years ago
|
}
|
||
3 years ago
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
.img-container {
|
||
|
margin: 0 -2px;
|
||
|
}
|
||
|
|
||
|
.add {
|
||
3 years ago
|
transition: 0.2s background-color;
|
||
4 years ago
|
/*background-color: #666666ee;*/
|
||
|
border-radius: 4px;
|
||
|
height: 33px;
|
||
|
margin: 5px 2px;
|
||
|
}
|
||
|
|
||
|
.add:hover {
|
||
|
/*background-color: #66666699;*/
|
||
|
}
|
||
|
|
||
|
.thumbnail {
|
||
|
height: 33px;
|
||
|
width: 33px;
|
||
|
margin: 2px;
|
||
|
border-radius: 4px;
|
||
|
}
|
||
|
|
||
|
.thumbnail img {
|
||
|
/*max-height: 33px;*/
|
||
|
max-width: 33px;
|
||
|
}
|
||
|
|
||
|
.main {
|
||
3 years ago
|
position: relative;
|
||
4 years ago
|
}
|
||
|
|
||
|
.expand-icon {
|
||
|
border-radius: 2px;
|
||
|
/*opacity: 0;*/
|
||
3 years ago
|
transition: 0.3s background-color;
|
||
4 years ago
|
}
|
||
|
|
||
|
.expand-icon:hover {
|
||
|
/*opacity: 1;*/
|
||
|
background-color: var(--v-primary-lighten4);
|
||
|
}
|
||
|
|
||
|
.modal-thumbnail img {
|
||
|
height: 50px;
|
||
|
max-width: 100%;
|
||
|
border-radius: 4px;
|
||
|
}
|
||
|
|
||
|
.modal-thumbnail {
|
||
|
position: relative;
|
||
|
margin: 10px 10px;
|
||
|
}
|
||
|
|
||
|
.remove-icon {
|
||
|
position: absolute;
|
||
|
top: 5px;
|
||
3 years ago
|
right: 5px;
|
||
4 years ago
|
}
|
||
|
|
||
|
.image-overlay-container {
|
||
|
max-height: 100vh;
|
||
|
overflow-y: auto;
|
||
|
position: relative;
|
||
|
}
|
||
|
|
||
|
.image-overlay-container .close-icon {
|
||
|
position: fixed;
|
||
|
top: 15px;
|
||
3 years ago
|
right: 15px;
|
||
4 years ago
|
}
|
||
|
|
||
|
.overlay-thumbnail {
|
||
3 years ago
|
transition: 0.4s transform, 0.4s opacity;
|
||
|
opacity: 0.5;
|
||
4 years ago
|
}
|
||
|
|
||
|
.overlay-thumbnail.active {
|
||
|
transform: scale(1.4);
|
||
|
opacity: 1;
|
||
|
}
|
||
|
|
||
|
.overlay-thumbnail:hover {
|
||
|
opacity: 1;
|
||
|
}
|
||
|
|
||
|
.modal-title {
|
||
|
text-overflow: ellipsis;
|
||
|
white-space: nowrap;
|
||
|
width: 100%;
|
||
|
overflow: hidden;
|
||
|
}
|
||
|
|
||
|
.modal-thumbnail-card {
|
||
3 years ago
|
transition: 0.4s transform;
|
||
4 years ago
|
}
|
||
|
|
||
|
.modal-thumbnail-card:hover {
|
||
|
transform: scale(1.05);
|
||
|
}
|
||
|
</style>
|
||
|
<!--
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|