1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-15 15:18:18 +09:00
MisskeyIO/src/client/components/drive.nav-folder.vue

137 lines
2.9 KiB
Vue
Raw Normal View History

2018-02-14 19:21:15 +09:00
<template>
<div class="drylbebk"
2018-02-14 19:21:15 +09:00
:data-draghover="draghover"
@click="onClick"
@dragover.prevent.stop="onDragover"
@dragenter="onDragenter"
@dragleave="onDragleave"
@drop.stop="onDrop"
>
<i v-if="folder == null"><fa :icon="faCloud"/></i>
<span>{{ folder == null ? $t('drive') : folder.name }}</span>
2018-02-14 19:21:15 +09:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import { faCloud } from '@fortawesome/free-solid-svg-icons';
2018-02-14 19:21:15 +09:00
export default Vue.extend({
props: {
folder: {
type: Object,
required: false,
}
},
2018-02-14 19:21:15 +09:00
data() {
return {
hover: false,
draghover: false,
faCloud
2017-02-21 17:52:10 +09:00
};
2018-02-14 19:21:15 +09:00
},
2018-02-18 22:14:51 +09:00
computed: {
browser(): any {
return this.$parent;
}
},
2018-02-14 19:21:15 +09:00
methods: {
onClick() {
this.browser.move(this.folder);
},
2018-02-14 19:21:15 +09:00
onMouseover() {
this.hover = true;
},
2018-02-14 19:21:15 +09:00
onMouseout() {
this.hover = false;
},
2018-02-14 19:21:15 +09:00
onDragover(e) {
2017-02-20 09:53:57 +09:00
// このフォルダがルートかつカレントディレクトリならドロップ禁止
2017-02-21 17:52:10 +09:00
if (this.folder == null && this.browser.folder == null) {
e.dataTransfer.dropEffect = 'none';
2018-02-27 06:25:17 +09:00
}
const isFile = e.dataTransfer.items[0].kind == 'file';
const isDriveFile = e.dataTransfer.types[0] == 'mk_drive_file';
const isDriveFolder = e.dataTransfer.types[0] == 'mk_drive_folder';
if (isFile || isDriveFile || isDriveFolder) {
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
2017-02-21 17:52:10 +09:00
} else {
2018-02-27 06:25:17 +09:00
e.dataTransfer.dropEffect = 'none';
2017-02-21 17:52:10 +09:00
}
2018-02-27 06:35:16 +09:00
return false;
2018-02-14 19:21:15 +09:00
},
2018-02-14 19:21:15 +09:00
onDragenter() {
2017-02-21 17:52:10 +09:00
if (this.folder || this.browser.folder) this.draghover = true;
2018-02-14 19:21:15 +09:00
},
2018-02-14 19:21:15 +09:00
onDragleave() {
2017-02-21 17:52:10 +09:00
if (this.folder || this.browser.folder) this.draghover = false;
2018-02-14 19:21:15 +09:00
},
2018-02-14 19:21:15 +09:00
onDrop(e) {
2017-02-21 17:52:10 +09:00
this.draghover = false;
2016-12-29 07:49:51 +09:00
2017-02-20 09:53:57 +09:00
// ファイルだったら
2017-02-21 17:52:10 +09:00
if (e.dataTransfer.files.length > 0) {
for (const file of Array.from(e.dataTransfer.files)) {
2017-02-21 17:52:10 +09:00
this.browser.upload(file, this.folder);
}
2018-02-27 06:25:17 +09:00
return;
}
2017-01-12 05:55:38 +09:00
2018-02-27 06:25:17 +09:00
//#region ドライブのファイル
const driveFile = e.dataTransfer.getData('mk_drive_file');
if (driveFile != null && driveFile != '') {
const file = JSON.parse(driveFile);
this.browser.removeFile(file.id);
2018-11-09 08:13:34 +09:00
this.$root.api('drive/files/update', {
2018-03-29 14:48:47 +09:00
fileId: file.id,
folderId: this.folder ? this.folder.id : null
2017-02-21 17:52:10 +09:00
});
2018-02-27 06:25:17 +09:00
}
//#endregion
//#region ドライブのフォルダ
const driveFolder = e.dataTransfer.getData('mk_drive_folder');
if (driveFolder != null && driveFolder != '') {
const folder = JSON.parse(driveFolder);
2017-02-20 09:53:57 +09:00
// 移動先が自分自身ならreject
2018-02-27 06:25:17 +09:00
if (this.folder && folder.id == this.folder.id) return;
this.browser.removeFolder(folder.id);
2018-11-09 08:13:34 +09:00
this.$root.api('drive/folders/update', {
2018-03-29 14:48:47 +09:00
folderId: folder.id,
parentId: this.folder ? this.folder.id : null
2017-02-21 17:52:10 +09:00
});
}
2018-02-27 06:25:17 +09:00
//#endregion
2018-02-14 19:21:15 +09:00
}
}
});
</script>
<style lang="scss" scoped>
.drylbebk {
> * {
pointer-events: none;
}
2018-02-14 19:21:15 +09:00
&[data-draghover] {
background: #eee;
}
2018-04-15 07:41:10 +09:00
> i {
margin-right: 4px;
}
}
2018-02-14 19:21:15 +09:00
</style>