2020-01-29 11:37:25 -08:00
|
|
|
<template>
|
|
|
|
<div class="skeikyzd" v-show="files.length != 0">
|
2020-12-04 19:50:09 -08:00
|
|
|
<XDraggable class="files" v-model="_files" item-key="id" animation="150" delay="100" delay-on-touch-only="true">
|
|
|
|
<template #item="{element}">
|
|
|
|
<div @click="showFileMenu(element, $event)" @contextmenu.prevent="showFileMenu(element, $event)">
|
|
|
|
<MkDriveFileThumbnail :data-id="element.id" class="thumbnail" :file="element" fit="cover"/>
|
|
|
|
<div class="sensitive" v-if="element.isSensitive">
|
|
|
|
<Fa class="icon" :icon="faExclamationTriangle"/>
|
|
|
|
</div>
|
2020-01-29 11:37:25 -08:00
|
|
|
</div>
|
2020-12-04 19:50:09 -08:00
|
|
|
</template>
|
2020-10-17 04:12:00 -07:00
|
|
|
</XDraggable>
|
2020-01-29 11:37:25 -08:00
|
|
|
<p class="remain">{{ 4 - files.length }}/4</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 04:12:00 -07:00
|
|
|
import { defineComponent, defineAsyncComponent } from 'vue';
|
2020-01-29 11:37:25 -08:00
|
|
|
import { faTimesCircle, faEye, faEyeSlash } from '@fortawesome/free-regular-svg-icons';
|
|
|
|
import { faExclamationTriangle, faICursor } from '@fortawesome/free-solid-svg-icons';
|
2020-10-17 04:12:00 -07:00
|
|
|
import MkDriveFileThumbnail from './drive-file-thumbnail.vue'
|
2021-03-23 01:30:14 -07:00
|
|
|
import * as os from '@client/os';
|
2020-01-29 11:37:25 -08:00
|
|
|
|
2020-10-17 04:12:00 -07:00
|
|
|
export default defineComponent({
|
2020-01-29 11:37:25 -08:00
|
|
|
components: {
|
2020-12-04 19:50:09 -08:00
|
|
|
XDraggable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2020-10-17 04:12:00 -07:00
|
|
|
MkDriveFileThumbnail
|
2020-01-29 11:37:25 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
files: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
detachMediaFn: {
|
|
|
|
type: Function,
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-12-04 19:50:09 -08:00
|
|
|
emits: ['updated', 'detach', 'changeSensitive', 'changeName'],
|
2020-10-17 04:12:00 -07:00
|
|
|
|
2020-01-29 11:37:25 -08:00
|
|
|
data() {
|
|
|
|
return {
|
2020-02-03 16:20:10 -08:00
|
|
|
menu: null as Promise<null> | null,
|
|
|
|
|
2020-01-29 11:37:25 -08:00
|
|
|
faExclamationTriangle
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2020-12-04 19:50:09 -08:00
|
|
|
computed: {
|
|
|
|
_files: {
|
|
|
|
get() {
|
|
|
|
return this.files;
|
|
|
|
},
|
|
|
|
set(value) {
|
|
|
|
this.$emit('updated', value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-29 11:37:25 -08:00
|
|
|
methods: {
|
|
|
|
detachMedia(id) {
|
|
|
|
if (this.detachMediaFn) {
|
|
|
|
this.detachMediaFn(id);
|
2020-10-17 04:12:00 -07:00
|
|
|
} else {
|
|
|
|
this.$emit('detach', id);
|
2020-01-29 11:37:25 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleSensitive(file) {
|
2020-10-17 04:12:00 -07:00
|
|
|
os.api('drive/files/update', {
|
2020-01-29 11:37:25 -08:00
|
|
|
fileId: file.id,
|
|
|
|
isSensitive: !file.isSensitive
|
|
|
|
}).then(() => {
|
2020-12-04 19:50:09 -08:00
|
|
|
this.$emit('changeSensitive', file, !file.isSensitive);
|
2020-01-29 11:37:25 -08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
async rename(file) {
|
2020-10-17 04:12:00 -07:00
|
|
|
const { canceled, result } = await os.dialog({
|
2020-12-25 17:47:36 -08:00
|
|
|
title: this.$ts.enterFileName,
|
2020-01-29 11:37:25 -08:00
|
|
|
input: {
|
|
|
|
default: file.name
|
|
|
|
},
|
|
|
|
allowEmpty: false
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
2020-10-17 04:12:00 -07:00
|
|
|
os.api('drive/files/update', {
|
2020-01-29 11:37:25 -08:00
|
|
|
fileId: file.id,
|
|
|
|
name: result
|
|
|
|
}).then(() => {
|
2020-12-04 19:50:09 -08:00
|
|
|
this.$emit('changeName', file, result);
|
2020-01-29 11:37:25 -08:00
|
|
|
file.name = result;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
showFileMenu(file, ev: MouseEvent) {
|
2020-02-03 16:20:10 -08:00
|
|
|
if (this.menu) return;
|
2020-10-17 04:12:00 -07:00
|
|
|
this.menu = os.modalMenu([{
|
2020-12-25 17:47:36 -08:00
|
|
|
text: this.$ts.renameFile,
|
2020-10-17 04:12:00 -07:00
|
|
|
icon: faICursor,
|
|
|
|
action: () => { this.rename(file) }
|
|
|
|
}, {
|
2020-12-25 17:47:36 -08:00
|
|
|
text: file.isSensitive ? this.$ts.unmarkAsSensitive : this.$ts.markAsSensitive,
|
2020-10-17 04:12:00 -07:00
|
|
|
icon: file.isSensitive ? faEyeSlash : faEye,
|
|
|
|
action: () => { this.toggleSensitive(file) }
|
|
|
|
}, {
|
2020-12-25 17:47:36 -08:00
|
|
|
text: this.$ts.attachCancel,
|
2020-10-17 04:12:00 -07:00
|
|
|
icon: faTimesCircle,
|
|
|
|
action: () => { this.detachMedia(file.id) }
|
|
|
|
}], ev.currentTarget || ev.target).then(() => this.menu = null);
|
2020-01-29 11:37:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.skeikyzd {
|
2020-10-17 04:12:00 -07:00
|
|
|
padding: 8px 16px;
|
2020-01-29 11:37:25 -08:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .files {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
|
|
> div {
|
|
|
|
position: relative;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
2020-10-17 04:12:00 -07:00
|
|
|
margin-right: 4px;
|
|
|
|
border-radius: 4px;
|
2021-03-02 05:57:16 -08:00
|
|
|
overflow: hidden;
|
2020-01-29 11:37:25 -08:00
|
|
|
cursor: move;
|
|
|
|
|
|
|
|
&:hover > .remove {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
z-index: 1;
|
|
|
|
color: var(--fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .sensitive {
|
|
|
|
display: flex;
|
|
|
|
position: absolute;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
z-index: 2;
|
|
|
|
background: rgba(17, 17, 17, .7);
|
|
|
|
color: #fff;
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .remain {
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 8px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|