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