2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
|
|
|
<div class="ncvczrfv"
|
2020-10-17 20:12:00 +09:00
|
|
|
:class="{ isSelected }"
|
2020-01-30 04:37:25 +09:00
|
|
|
@click="onClick"
|
2020-10-17 20:12:00 +09:00
|
|
|
@contextmenu.stop="onContextmenu"
|
2020-01-30 04:37:25 +09:00
|
|
|
draggable="true"
|
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
:title="title"
|
|
|
|
>
|
2020-12-19 10:55:52 +09:00
|
|
|
<div class="label" v-if="$i.avatarId == file.id">
|
2020-01-30 04:37:25 +09:00
|
|
|
<img src="/assets/label.svg"/>
|
2020-07-25 01:56:52 +09:00
|
|
|
<p>{{ $t('avatar') }}</p>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
2020-12-19 10:55:52 +09:00
|
|
|
<div class="label" v-if="$i.bannerId == file.id">
|
2020-01-30 04:37:25 +09:00
|
|
|
<img src="/assets/label.svg"/>
|
2020-07-25 01:56:52 +09:00
|
|
|
<p>{{ $t('banner') }}</p>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
|
|
|
<div class="label red" v-if="file.isSensitive">
|
|
|
|
<img src="/assets/label-red.svg"/>
|
2020-07-25 01:56:52 +09:00
|
|
|
<p>{{ $t('nsfw') }}</p>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/>
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
<p class="name">
|
|
|
|
<span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substr(0, file.name.lastIndexOf('.')) : file.name }}</span>
|
|
|
|
<span class="ext" v-if="file.name.lastIndexOf('.') != -1">{{ file.name.substr(file.name.lastIndexOf('.')) }}</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent } from 'vue';
|
2020-01-30 04:37:25 +09:00
|
|
|
import { faEye, faEyeSlash } from '@fortawesome/free-regular-svg-icons';
|
|
|
|
import { faDownload, faLink, faICursor, faTrashAlt } from '@fortawesome/free-solid-svg-icons';
|
2020-10-17 20:12:00 +09:00
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
|
|
|
import MkDriveFileThumbnail from './drive-file-thumbnail.vue';
|
|
|
|
import bytes from '../filters/bytes';
|
|
|
|
import * as os from '@/os';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-04-22 00:34:56 +09:00
|
|
|
components: {
|
2020-10-17 20:12:00 +09:00
|
|
|
MkDriveFileThumbnail
|
2020-04-22 00:34:56 +09:00
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
props: {
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-22 00:34:56 +09:00
|
|
|
isSelected: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-01-30 04:37:25 +09:00
|
|
|
selectMode: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
emits: ['chosen'],
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isDragging: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-04-22 00:34:56 +09:00
|
|
|
// TODO: parentへの参照を無くす
|
2020-01-30 04:37:25 +09:00
|
|
|
browser(): any {
|
|
|
|
return this.$parent;
|
|
|
|
},
|
|
|
|
title(): string {
|
2020-10-17 20:12:00 +09:00
|
|
|
return `${this.file.name}\n${this.file.type} ${bytes(this.file.size)}`;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-10-17 20:12:00 +09:00
|
|
|
getMenu() {
|
|
|
|
return [{
|
|
|
|
text: this.$t('rename'),
|
|
|
|
icon: faICursor,
|
|
|
|
action: this.rename
|
|
|
|
}, {
|
|
|
|
text: this.file.isSensitive ? this.$t('unmarkAsSensitive') : this.$t('markAsSensitive'),
|
|
|
|
icon: this.file.isSensitive ? faEye : faEyeSlash,
|
|
|
|
action: this.toggleSensitive
|
|
|
|
}, null, {
|
|
|
|
text: this.$t('copyUrl'),
|
|
|
|
icon: faLink,
|
|
|
|
action: this.copyUrl
|
|
|
|
}, {
|
|
|
|
type: 'a',
|
|
|
|
href: this.file.url,
|
|
|
|
target: '_blank',
|
|
|
|
text: this.$t('download'),
|
|
|
|
icon: faDownload,
|
|
|
|
download: this.file.name
|
|
|
|
}, null, {
|
|
|
|
text: this.$t('delete'),
|
|
|
|
icon: faTrashAlt,
|
|
|
|
danger: true,
|
|
|
|
action: this.deleteFile
|
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
onClick(ev) {
|
|
|
|
if (this.selectMode) {
|
2020-04-22 00:34:56 +09:00
|
|
|
this.$emit('chosen', this.file);
|
2020-01-30 04:37:25 +09:00
|
|
|
} else {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.modalMenu(this.getMenu(), ev.currentTarget || ev.target);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
onContextmenu(e) {
|
|
|
|
os.contextMenu(this.getMenu(), e);
|
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
onDragstart(e) {
|
|
|
|
e.dataTransfer.effectAllowed = 'move';
|
2020-10-17 20:12:00 +09:00
|
|
|
e.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(this.file));
|
2020-01-30 04:37:25 +09:00
|
|
|
this.isDragging = true;
|
|
|
|
|
|
|
|
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
|
|
|
// (=あなたの子供が、ドラッグを開始しましたよ)
|
|
|
|
this.browser.isDragSource = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onDragend(e) {
|
|
|
|
this.isDragging = false;
|
|
|
|
this.browser.isDragSource = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
rename() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.dialog({
|
2020-03-22 10:51:40 +09:00
|
|
|
title: this.$t('renameFile'),
|
2020-01-30 04:37:25 +09:00
|
|
|
input: {
|
2020-03-22 10:51:40 +09:00
|
|
|
placeholder: this.$t('inputNewFileName'),
|
2020-01-30 04:37:25 +09:00
|
|
|
default: this.file.name,
|
|
|
|
allowEmpty: false
|
|
|
|
}
|
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
if (canceled) return;
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('drive/files/update', {
|
2020-01-30 04:37:25 +09:00
|
|
|
fileId: this.file.id,
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleSensitive() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('drive/files/update', {
|
2020-01-30 04:37:25 +09:00
|
|
|
fileId: this.file.id,
|
|
|
|
isSensitive: !this.file.isSensitive
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
copyUrl() {
|
|
|
|
copyToClipboard(this.file.url);
|
2020-10-17 20:12:00 +09:00
|
|
|
os.success();
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
setAsAvatar() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.updateAvatar(this.file);
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
setAsBanner() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.updateBanner(this.file);
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
addApp() {
|
|
|
|
alert('not implemented yet');
|
|
|
|
},
|
|
|
|
|
|
|
|
async deleteFile() {
|
2020-10-17 20:12:00 +09:00
|
|
|
const { canceled } = await os.dialog({
|
2020-01-30 04:37:25 +09:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('driveFileDeleteConfirm', { name: this.file.name }),
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('drive/files/delete', {
|
2020-01-30 04:37:25 +09:00
|
|
|
fileId: this.file.id
|
|
|
|
});
|
2020-10-17 20:12:00 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
bytes
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ncvczrfv {
|
|
|
|
position: relative;
|
|
|
|
padding: 8px 0 0 0;
|
|
|
|
min-height: 180px;
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
|
|
&, * {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
&:hover {
|
|
|
|
background: rgba(#000, 0.05);
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #0b65a5;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #c12113;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: rgba(#000, 0.1);
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #0b588c;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #ce2212;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
&.isSelected {
|
2020-01-30 04:37:25 +09:00
|
|
|
background: var(--accent);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--accentLighten);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: var(--accentDarken);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
pointer-events: none;
|
|
|
|
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
z-index: 1;
|
|
|
|
background: #0c7ac9;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:before {
|
|
|
|
top: 0;
|
|
|
|
left: 57px;
|
|
|
|
width: 28px;
|
|
|
|
height: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
top: 57px;
|
|
|
|
left: 0;
|
|
|
|
width: 8px;
|
|
|
|
height: 28px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #c12113;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> img {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
> p {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 3;
|
|
|
|
top: 19px;
|
|
|
|
left: -28px;
|
|
|
|
width: 120px;
|
|
|
|
margin: 0;
|
|
|
|
text-align: center;
|
|
|
|
line-height: 28px;
|
|
|
|
color: #fff;
|
|
|
|
transform: rotate(-45deg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
|
|
|
width: 128px;
|
|
|
|
height: 128px;
|
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
margin: 4px 0 0 0;
|
|
|
|
font-size: 0.8em;
|
|
|
|
text-align: center;
|
|
|
|
word-break: break-all;
|
|
|
|
color: var(--fg);
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
> .ext {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|