2018-02-16 09:36:28 -06:00
|
|
|
<template>
|
|
|
|
<div class="mk-drive">
|
2017-10-31 23:11:40 -05:00
|
|
|
<nav ref="nav">
|
2018-04-14 11:04:40 -05:00
|
|
|
<a @click.prevent="goRoot()" href="/i/drive">%fa:cloud%%i18n:@drive%</a>
|
2018-02-16 09:36:28 -06:00
|
|
|
<template v-for="folder in hierarchyFolders">
|
|
|
|
<span :key="folder.id + '>'">%fa:angle-right%</span>
|
|
|
|
<a :key="folder.id" @click.prevent="cd(folder)" :href="`/i/drive/folder/${folder.id}`">{{ folder.name }}</a>
|
2018-02-07 23:50:18 -06:00
|
|
|
</template>
|
|
|
|
<template v-if="folder != null">
|
2017-12-07 11:44:50 -06:00
|
|
|
<span>%fa:angle-right%</span>
|
2018-02-16 09:36:28 -06:00
|
|
|
<p>{{ folder.name }}</p>
|
2018-02-07 23:50:18 -06:00
|
|
|
</template>
|
|
|
|
<template v-if="file != null">
|
2017-12-07 11:44:50 -06:00
|
|
|
<span>%fa:angle-right%</span>
|
2018-02-16 09:36:28 -06:00
|
|
|
<p>{{ file.name }}</p>
|
2018-02-07 23:50:18 -06:00
|
|
|
</template>
|
2017-01-11 14:55:38 -06:00
|
|
|
</nav>
|
2017-06-07 01:43:29 -05:00
|
|
|
<mk-uploader ref="uploader"/>
|
2018-02-16 09:36:28 -06:00
|
|
|
<div class="browser" :class="{ fetching }" v-if="file == null">
|
2018-02-07 03:34:43 -06:00
|
|
|
<div class="info" v-if="info">
|
2018-04-14 11:04:40 -05:00
|
|
|
<p v-if="folder == null">{{ (info.usage / info.capacity * 100).toFixed(1) }}% %i18n:@used%</p>
|
2018-03-29 00:48:47 -05:00
|
|
|
<p v-if="folder != null && (folder.foldersCount > 0 || folder.filesCount > 0)">
|
2018-04-14 11:04:40 -05:00
|
|
|
<template v-if="folder.foldersCount > 0">{{ folder.foldersCount }} %i18n:@folder-count%</template>
|
|
|
|
<template v-if="folder.foldersCount > 0 && folder.filesCount > 0">%i18n:@count-separator%</template>
|
|
|
|
<template v-if="folder.filesCount > 0">{{ folder.filesCount }} %i18n:@file-count%</template>
|
2017-03-18 10:02:45 -05:00
|
|
|
</p>
|
|
|
|
</div>
|
2018-02-07 03:34:43 -06:00
|
|
|
<div class="folders" v-if="folders.length > 0">
|
2018-02-21 16:06:47 -06:00
|
|
|
<x-folder v-for="folder in folders" :key="folder.id" :folder="folder"/>
|
2018-04-14 11:04:40 -05:00
|
|
|
<p v-if="moreFolders">%i18n:@load-more%</p>
|
2017-01-11 14:55:38 -06:00
|
|
|
</div>
|
2018-02-07 03:34:43 -06:00
|
|
|
<div class="files" v-if="files.length > 0">
|
2018-02-21 16:06:47 -06:00
|
|
|
<x-file v-for="file in files" :key="file.id" :file="file"/>
|
2018-02-07 03:34:43 -06:00
|
|
|
<button class="more" v-if="moreFiles" @click="fetchMoreFiles">
|
2018-04-15 17:07:32 -05:00
|
|
|
{{ fetchingMoreFiles ? '%i18n:!common.loading%' : '%i18n:!@load-more%' }}
|
2017-03-25 02:01:36 -05:00
|
|
|
</button>
|
2017-01-11 14:55:38 -06:00
|
|
|
</div>
|
2018-02-07 03:34:43 -06:00
|
|
|
<div class="empty" v-if="files.length == 0 && folders.length == 0 && !fetching">
|
2018-04-14 11:04:40 -05:00
|
|
|
<p v-if="folder == null">%i18n:@nothing-in-drive%</p>
|
|
|
|
<p v-if="folder != null">%i18n:@folder-is-empty%</p>
|
2017-01-11 14:55:38 -06:00
|
|
|
</div>
|
2017-03-18 10:02:45 -05:00
|
|
|
</div>
|
2018-02-07 03:34:43 -06:00
|
|
|
<div class="fetching" v-if="fetching && file == null && files.length == 0 && folders.length == 0">
|
2017-03-18 10:02:45 -05:00
|
|
|
<div class="spinner">
|
|
|
|
<div class="dot1"></div>
|
|
|
|
<div class="dot2"></div>
|
2017-01-11 14:55:38 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-02-21 16:06:47 -06:00
|
|
|
<input ref="file" class="file" type="file" multiple="multiple" @change="onChangeLocalFile"/>
|
|
|
|
<x-file-detail v-if="file != null" :file="file"/>
|
2018-02-16 09:36:28 -06:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2018-02-21 16:06:47 -06:00
|
|
|
import XFolder from './drive.folder.vue';
|
|
|
|
import XFile from './drive.file.vue';
|
|
|
|
import XFileDetail from './drive.file-detail.vue';
|
2018-02-16 09:36:28 -06:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2018-02-21 16:06:47 -06:00
|
|
|
components: {
|
|
|
|
XFolder,
|
|
|
|
XFile,
|
|
|
|
XFileDetail
|
|
|
|
},
|
2018-02-16 09:36:28 -06:00
|
|
|
props: ['initFolder', 'initFile', 'selectFile', 'multiple', 'isNaked', 'top'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* 現在の階層(フォルダ)
|
|
|
|
* * null でルートを表す
|
|
|
|
*/
|
|
|
|
folder: null,
|
|
|
|
|
|
|
|
file: null,
|
|
|
|
|
|
|
|
files: [],
|
|
|
|
folders: [],
|
|
|
|
moreFiles: false,
|
|
|
|
moreFolders: false,
|
|
|
|
hierarchyFolders: [],
|
|
|
|
selectedFiles: [],
|
|
|
|
info: null,
|
|
|
|
connection: null,
|
|
|
|
connectionId: null,
|
|
|
|
|
|
|
|
fetching: true,
|
|
|
|
fetchingMoreFiles: false,
|
|
|
|
fetchingMoreFolders: false
|
2017-02-21 10:05:23 -06:00
|
|
|
};
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
isFileSelectMode(): boolean {
|
|
|
|
return this.selectFile;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2018-02-17 21:35:18 -06:00
|
|
|
this.connection = (this as any).os.streams.driveStream.getConnection();
|
|
|
|
this.connectionId = (this as any).os.streams.driveStream.use();
|
2018-02-16 09:36:28 -06:00
|
|
|
|
|
|
|
this.connection.on('file_created', this.onStreamDriveFileCreated);
|
|
|
|
this.connection.on('file_updated', this.onStreamDriveFileUpdated);
|
|
|
|
this.connection.on('folder_created', this.onStreamDriveFolderCreated);
|
|
|
|
this.connection.on('folder_updated', this.onStreamDriveFolderUpdated);
|
|
|
|
|
|
|
|
if (this.initFolder) {
|
|
|
|
this.cd(this.initFolder, true);
|
|
|
|
} else if (this.initFile) {
|
|
|
|
this.cf(this.initFile, true);
|
|
|
|
} else {
|
|
|
|
this.fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isNaked) {
|
|
|
|
(this.$refs.nav as any).style.top = `${this.top}px`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.connection.off('file_created', this.onStreamDriveFileCreated);
|
|
|
|
this.connection.off('file_updated', this.onStreamDriveFileUpdated);
|
|
|
|
this.connection.off('folder_created', this.onStreamDriveFolderCreated);
|
|
|
|
this.connection.off('folder_updated', this.onStreamDriveFolderUpdated);
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).os.streams.driveStream.dispose(this.connectionId);
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onStreamDriveFileCreated(file) {
|
|
|
|
this.addFile(file, true);
|
|
|
|
},
|
2017-02-21 10:05:23 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
onStreamDriveFileUpdated(file) {
|
2017-02-21 10:05:23 -06:00
|
|
|
const current = this.folder ? this.folder.id : null;
|
2018-03-29 00:48:47 -05:00
|
|
|
if (current != file.folderId) {
|
2017-02-21 10:05:23 -06:00
|
|
|
this.removeFile(file);
|
|
|
|
} else {
|
|
|
|
this.addFile(file, true);
|
|
|
|
}
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-02-21 10:05:23 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
onStreamDriveFolderCreated(folder) {
|
2017-02-21 10:05:23 -06:00
|
|
|
this.addFolder(folder, true);
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-02-21 10:05:23 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
onStreamDriveFolderUpdated(folder) {
|
2017-02-21 10:05:23 -06:00
|
|
|
const current = this.folder ? this.folder.id : null;
|
2018-03-29 00:48:47 -05:00
|
|
|
if (current != folder.parentId) {
|
2017-02-21 10:05:23 -06:00
|
|
|
this.removeFolder(folder);
|
|
|
|
} else {
|
|
|
|
this.addFolder(folder, true);
|
|
|
|
}
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-02-21 10:05:23 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
dive(folder) {
|
|
|
|
this.hierarchyFolders.unshift(folder);
|
|
|
|
if (folder.parent) this.dive(folder.parent);
|
|
|
|
},
|
2017-02-21 10:05:23 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
cd(target, silent = false) {
|
2017-02-21 10:05:23 -06:00
|
|
|
this.file = null;
|
|
|
|
|
|
|
|
if (target == null) {
|
2018-02-22 03:37:47 -06:00
|
|
|
this.goRoot(silent);
|
2017-02-21 10:05:23 -06:00
|
|
|
return;
|
2018-02-16 09:36:28 -06:00
|
|
|
} else if (typeof target == 'object') {
|
|
|
|
target = target.id;
|
|
|
|
}
|
2017-02-21 10:05:23 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
this.fetching = true;
|
2016-12-28 16:49:51 -06:00
|
|
|
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/folders/show', {
|
2018-03-29 00:48:47 -05:00
|
|
|
folderId: target
|
2017-02-21 10:05:23 -06:00
|
|
|
}).then(folder => {
|
|
|
|
this.folder = folder;
|
|
|
|
this.hierarchyFolders = [];
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
if (folder.parent) this.dive(folder.parent);
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2018-02-08 22:11:30 -06:00
|
|
|
this.$emit('open-folder', this.folder, silent);
|
2017-02-26 02:36:54 -06:00
|
|
|
this.fetch();
|
2017-02-21 10:05:23 -06:00
|
|
|
});
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
addFolder(folder, unshift = false) {
|
2017-02-21 10:05:23 -06:00
|
|
|
const current = this.folder ? this.folder.id : null;
|
|
|
|
// 追加しようとしているフォルダが、今居る階層とは違う階層のものだったら中断
|
2018-03-29 00:48:47 -05:00
|
|
|
if (current != folder.parentId) return;
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2017-02-21 10:05:23 -06:00
|
|
|
// 追加しようとしているフォルダを既に所有してたら中断
|
|
|
|
if (this.folders.some(f => f.id == folder.id)) return;
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2017-02-21 10:05:23 -06:00
|
|
|
if (unshift) {
|
|
|
|
this.folders.unshift(folder);
|
|
|
|
} else {
|
|
|
|
this.folders.push(folder);
|
|
|
|
}
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2016-12-28 16:49:51 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
addFile(file, unshift = false) {
|
2017-02-21 10:05:23 -06:00
|
|
|
const current = this.folder ? this.folder.id : null;
|
|
|
|
// 追加しようとしているファイルが、今居る階層とは違う階層のものだったら中断
|
2018-03-29 00:48:47 -05:00
|
|
|
if (current != file.folderId) return;
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2017-02-21 10:05:23 -06:00
|
|
|
if (this.files.some(f => f.id == file.id)) {
|
|
|
|
const exist = this.files.map(f => f.id).indexOf(file.id);
|
2018-02-20 10:23:25 -06:00
|
|
|
Vue.set(this.files, exist, file);
|
2017-02-21 10:05:23 -06:00
|
|
|
return;
|
|
|
|
}
|
2016-12-28 16:49:51 -06:00
|
|
|
|
2017-02-21 10:05:23 -06:00
|
|
|
if (unshift) {
|
|
|
|
this.files.unshift(file);
|
|
|
|
} else {
|
|
|
|
this.files.push(file);
|
|
|
|
}
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
removeFolder(folder) {
|
2017-02-21 10:05:23 -06:00
|
|
|
if (typeof folder == 'object') folder = folder.id;
|
|
|
|
this.folders = this.folders.filter(f => f.id != folder);
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
removeFile(file) {
|
2017-02-21 10:05:23 -06:00
|
|
|
if (typeof file == 'object') file = file.id;
|
|
|
|
this.files = this.files.filter(f => f.id != file);
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
appendFile(file) {
|
|
|
|
this.addFile(file);
|
|
|
|
},
|
|
|
|
appendFolder(folder) {
|
|
|
|
this.addFolder(folder);
|
|
|
|
},
|
|
|
|
prependFile(file) {
|
|
|
|
this.addFile(file, true);
|
|
|
|
},
|
|
|
|
prependFolder(folder) {
|
|
|
|
this.addFolder(folder, true);
|
|
|
|
},
|
2017-12-08 11:11:48 -06:00
|
|
|
|
2018-02-22 03:37:47 -06:00
|
|
|
goRoot(silent = false) {
|
2017-02-21 10:05:23 -06:00
|
|
|
if (this.folder || this.file) {
|
2018-02-16 09:36:28 -06:00
|
|
|
this.file = null;
|
|
|
|
this.folder = null;
|
|
|
|
this.hierarchyFolders = [];
|
2018-02-22 03:37:47 -06:00
|
|
|
this.$emit('move-root', silent);
|
2017-02-26 02:36:54 -06:00
|
|
|
this.fetch();
|
2017-02-21 10:05:23 -06:00
|
|
|
}
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-12-08 10:51:05 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
fetch() {
|
|
|
|
this.folders = [];
|
|
|
|
this.files = [];
|
|
|
|
this.moreFolders = false;
|
|
|
|
this.moreFiles = false;
|
|
|
|
this.fetching = true;
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2018-02-08 22:11:30 -06:00
|
|
|
this.$emit('begin-fetch');
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2017-02-21 10:05:23 -06:00
|
|
|
let fetchedFolders = null;
|
|
|
|
let fetchedFiles = null;
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2017-02-21 10:05:23 -06:00
|
|
|
const foldersMax = 20;
|
|
|
|
const filesMax = 20;
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2017-02-19 18:53:57 -06:00
|
|
|
// フォルダ一覧取得
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/folders', {
|
2018-03-29 00:48:47 -05:00
|
|
|
folderId: this.folder ? this.folder.id : null,
|
2017-02-21 10:05:23 -06:00
|
|
|
limit: foldersMax + 1
|
|
|
|
}).then(folders => {
|
|
|
|
if (folders.length == foldersMax + 1) {
|
|
|
|
this.moreFolders = true;
|
|
|
|
folders.pop();
|
|
|
|
}
|
|
|
|
fetchedFolders = folders;
|
|
|
|
complete();
|
|
|
|
});
|
2017-01-11 14:55:38 -06:00
|
|
|
|
2017-02-19 18:53:57 -06:00
|
|
|
// ファイル一覧取得
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/files', {
|
2018-03-29 00:48:47 -05:00
|
|
|
folderId: this.folder ? this.folder.id : null,
|
2017-02-21 10:05:23 -06:00
|
|
|
limit: filesMax + 1
|
|
|
|
}).then(files => {
|
|
|
|
if (files.length == filesMax + 1) {
|
|
|
|
this.moreFiles = true;
|
|
|
|
files.pop();
|
|
|
|
}
|
|
|
|
fetchedFiles = files;
|
|
|
|
complete();
|
|
|
|
});
|
|
|
|
|
|
|
|
let flag = false;
|
2017-02-21 11:05:44 -06:00
|
|
|
const complete = () => {
|
2017-02-21 10:05:23 -06:00
|
|
|
if (flag) {
|
2017-02-23 09:18:33 -06:00
|
|
|
fetchedFolders.forEach(this.appendFolder);
|
|
|
|
fetchedFiles.forEach(this.appendFile);
|
2018-02-16 09:36:28 -06:00
|
|
|
this.fetching = false;
|
|
|
|
|
2017-02-21 10:05:23 -06:00
|
|
|
// 一連の読み込みが完了したイベントを発行
|
2018-02-08 22:11:30 -06:00
|
|
|
this.$emit('fetched');
|
2017-02-21 10:05:23 -06:00
|
|
|
} else {
|
|
|
|
flag = true;
|
|
|
|
// 一連の読み込みが半分完了したイベントを発行
|
2018-02-08 22:11:30 -06:00
|
|
|
this.$emit('fetch-mid');
|
2017-02-21 10:05:23 -06:00
|
|
|
}
|
|
|
|
};
|
2017-03-18 10:02:45 -05:00
|
|
|
|
|
|
|
if (this.folder == null) {
|
|
|
|
// Fetch addtional drive info
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive').then(info => {
|
2018-02-16 09:36:28 -06:00
|
|
|
this.info = info;
|
2017-03-18 10:02:45 -05:00
|
|
|
});
|
|
|
|
}
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-02-21 10:05:23 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
fetchMoreFiles() {
|
|
|
|
this.fetching = true;
|
|
|
|
this.fetchingMoreFiles = true;
|
2017-02-26 02:36:54 -06:00
|
|
|
|
|
|
|
const max = 30;
|
|
|
|
|
|
|
|
// ファイル一覧取得
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/files', {
|
2018-03-29 00:48:47 -05:00
|
|
|
folderId: this.folder ? this.folder.id : null,
|
2017-06-06 11:55:02 -05:00
|
|
|
limit: max + 1,
|
2018-03-29 00:48:47 -05:00
|
|
|
untilId: this.files[this.files.length - 1].id
|
2017-02-26 02:36:54 -06:00
|
|
|
}).then(files => {
|
|
|
|
if (files.length == max + 1) {
|
|
|
|
this.moreFiles = true;
|
|
|
|
files.pop();
|
|
|
|
} else {
|
|
|
|
this.moreFiles = false;
|
|
|
|
}
|
|
|
|
files.forEach(this.appendFile);
|
2018-02-16 09:36:28 -06:00
|
|
|
this.fetching = false;
|
|
|
|
this.fetchingMoreFiles = false;
|
2017-02-26 02:36:54 -06:00
|
|
|
});
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-02-26 02:36:54 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
chooseFile(file) {
|
2017-03-12 05:27:54 -05:00
|
|
|
if (this.isFileSelectMode) {
|
2017-08-28 06:23:47 -05:00
|
|
|
if (this.multiple) {
|
|
|
|
if (this.selectedFiles.some(f => f.id == file.id)) {
|
|
|
|
this.selectedFiles = this.selectedFiles.filter(f => f.id != file.id);
|
|
|
|
} else {
|
|
|
|
this.selectedFiles.push(file);
|
|
|
|
}
|
2018-02-08 22:11:30 -06:00
|
|
|
this.$emit('change-selection', this.selectedFiles);
|
2017-02-21 10:05:23 -06:00
|
|
|
} else {
|
2018-02-08 22:11:30 -06:00
|
|
|
this.$emit('selected', file);
|
2017-02-21 10:05:23 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.cf(file);
|
|
|
|
}
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-02-16 02:20:45 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
cf(file, silent = false) {
|
2017-02-21 10:05:23 -06:00
|
|
|
if (typeof file == 'object') file = file.id;
|
2017-02-16 02:20:45 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
this.fetching = true;
|
2017-02-16 02:20:45 -06:00
|
|
|
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/files/show', {
|
2018-03-29 00:48:47 -05:00
|
|
|
fileId: file
|
2017-02-21 10:05:23 -06:00
|
|
|
}).then(file => {
|
|
|
|
this.file = file;
|
|
|
|
this.folder = null;
|
|
|
|
this.hierarchyFolders = [];
|
2017-02-16 02:20:45 -06:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
if (file.folder) this.dive(file.folder);
|
2017-02-16 02:20:45 -06:00
|
|
|
|
2018-02-19 08:37:09 -06:00
|
|
|
this.fetching = false;
|
|
|
|
|
2018-02-08 22:11:30 -06:00
|
|
|
this.$emit('open-file', this.file, silent);
|
2017-02-21 10:05:23 -06:00
|
|
|
});
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-03-13 00:56:53 -05:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
openContextMenu() {
|
2017-03-13 00:56:53 -05:00
|
|
|
const fn = window.prompt('何をしますか?(数字を入力してください): <1 → ファイルをアップロード | 2 → ファイルをURLでアップロード | 3 → フォルダ作成 | 4 → このフォルダ名を変更 | 5 → このフォルダを移動 | 6 → このフォルダを削除>');
|
|
|
|
if (fn == null || fn == '') return;
|
|
|
|
switch (fn) {
|
|
|
|
case '1':
|
2017-10-31 13:31:36 -05:00
|
|
|
this.selectLocalFile();
|
2017-03-13 00:56:53 -05:00
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
this.urlUpload();
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
this.createFolder();
|
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
this.renameFolder();
|
|
|
|
break;
|
|
|
|
case '5':
|
|
|
|
this.moveFolder();
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
alert('ごめんなさい!フォルダの削除は未実装です...。');
|
|
|
|
break;
|
|
|
|
}
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-03-13 00:56:53 -05:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
selectLocalFile() {
|
|
|
|
(this.$refs.file as any).click();
|
|
|
|
},
|
2017-10-31 13:31:36 -05:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
createFolder() {
|
2017-03-13 00:56:53 -05:00
|
|
|
const name = window.prompt('フォルダー名');
|
|
|
|
if (name == null || name == '') return;
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/folders/create', {
|
2017-03-13 00:56:53 -05:00
|
|
|
name: name,
|
2018-03-29 00:48:47 -05:00
|
|
|
parentId: this.folder ? this.folder.id : undefined
|
2017-03-13 00:56:53 -05:00
|
|
|
}).then(folder => {
|
|
|
|
this.addFolder(folder, true);
|
|
|
|
});
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-03-13 00:56:53 -05:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
renameFolder() {
|
2017-03-13 00:56:53 -05:00
|
|
|
if (this.folder == null) {
|
|
|
|
alert('現在いる場所はルートで、フォルダではないため名前の変更はできません。名前を変更したいフォルダに移動してからやってください。');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const name = window.prompt('フォルダー名', this.folder.name);
|
|
|
|
if (name == null || name == '') return;
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/folders/update', {
|
2017-03-13 00:56:53 -05:00
|
|
|
name: name,
|
2018-03-29 00:48:47 -05:00
|
|
|
folderId: this.folder.id
|
2017-03-13 00:56:53 -05:00
|
|
|
}).then(folder => {
|
|
|
|
this.cd(folder);
|
|
|
|
});
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-03-13 00:56:53 -05:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
moveFolder() {
|
2017-03-13 00:56:53 -05:00
|
|
|
if (this.folder == null) {
|
|
|
|
alert('現在いる場所はルートで、フォルダではないため移動はできません。移動したいフォルダに移動してからやってください。');
|
|
|
|
return;
|
|
|
|
}
|
2018-02-21 16:06:47 -06:00
|
|
|
(this as any).apis.chooseDriveFolder().then(folder => {
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/folders/update', {
|
2018-03-29 00:48:47 -05:00
|
|
|
parentId: folder ? folder.id : null,
|
|
|
|
folderId: this.folder.id
|
2017-03-13 00:56:53 -05:00
|
|
|
}).then(folder => {
|
|
|
|
this.cd(folder);
|
|
|
|
});
|
|
|
|
});
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
2017-03-13 00:56:53 -05:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
urlUpload() {
|
2017-03-13 00:56:53 -05:00
|
|
|
const url = window.prompt('アップロードしたいファイルのURL');
|
|
|
|
if (url == null || url == '') return;
|
2018-02-17 21:35:18 -06:00
|
|
|
(this as any).api('drive/files/upload_from_url', {
|
2017-03-13 00:56:53 -05:00
|
|
|
url: url,
|
2018-03-29 00:48:47 -05:00
|
|
|
folderId: this.folder ? this.folder.id : undefined
|
2017-03-13 00:56:53 -05:00
|
|
|
});
|
|
|
|
alert('アップロードをリクエストしました。アップロードが完了するまで時間がかかる場合があります。');
|
2018-02-16 09:36:28 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
onChangeLocalFile() {
|
|
|
|
Array.from((this.$refs.file as any).files)
|
|
|
|
.forEach(f => (this.$refs.uploader as any).upload(f, this.folder));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
|
|
|
.mk-drive
|
|
|
|
background #fff
|
|
|
|
|
|
|
|
> nav
|
|
|
|
display block
|
|
|
|
position sticky
|
|
|
|
position -webkit-sticky
|
|
|
|
top 0
|
|
|
|
z-index 1
|
|
|
|
width 100%
|
|
|
|
padding 10px 12px
|
|
|
|
overflow auto
|
|
|
|
white-space nowrap
|
|
|
|
font-size 0.9em
|
2018-04-28 18:51:17 -05:00
|
|
|
color rgba(#000, 0.67)
|
2018-02-16 09:36:28 -06:00
|
|
|
-webkit-backdrop-filter blur(12px)
|
|
|
|
backdrop-filter blur(12px)
|
|
|
|
background-color rgba(#fff, 0.75)
|
2018-04-28 18:51:17 -05:00
|
|
|
border-bottom solid 1px rgba(#000, 0.13)
|
2018-02-16 09:36:28 -06:00
|
|
|
|
|
|
|
> p
|
|
|
|
> a
|
|
|
|
display inline
|
|
|
|
margin 0
|
|
|
|
padding 0
|
|
|
|
text-decoration none !important
|
|
|
|
color inherit
|
|
|
|
|
|
|
|
&:last-child
|
|
|
|
font-weight bold
|
|
|
|
|
|
|
|
> [data-fa]
|
|
|
|
margin-right 4px
|
|
|
|
|
|
|
|
> span
|
|
|
|
margin 0 8px
|
|
|
|
opacity 0.5
|
|
|
|
|
|
|
|
> .browser
|
|
|
|
&.fetching
|
|
|
|
opacity 0.5
|
|
|
|
|
|
|
|
> .info
|
|
|
|
border-bottom solid 1px #eee
|
|
|
|
|
|
|
|
&:empty
|
|
|
|
display none
|
2017-03-13 00:56:53 -05:00
|
|
|
|
2018-02-16 09:36:28 -06:00
|
|
|
> p
|
|
|
|
display block
|
|
|
|
max-width 500px
|
|
|
|
margin 0 auto
|
|
|
|
padding 4px 16px
|
|
|
|
font-size 10px
|
|
|
|
color #777
|
|
|
|
|
|
|
|
> .folders
|
2018-02-21 16:06:47 -06:00
|
|
|
> .folder
|
2018-02-16 09:36:28 -06:00
|
|
|
border-bottom solid 1px #eee
|
|
|
|
|
|
|
|
> .files
|
2018-02-21 16:06:47 -06:00
|
|
|
> .file
|
2018-02-16 09:36:28 -06:00
|
|
|
border-bottom solid 1px #eee
|
|
|
|
|
|
|
|
> .more
|
|
|
|
display block
|
|
|
|
width 100%
|
|
|
|
padding 16px
|
|
|
|
font-size 16px
|
|
|
|
color #555
|
|
|
|
|
|
|
|
> .empty
|
|
|
|
padding 16px
|
|
|
|
text-align center
|
|
|
|
color #999
|
|
|
|
pointer-events none
|
|
|
|
|
|
|
|
> p
|
|
|
|
margin 0
|
|
|
|
|
|
|
|
> .fetching
|
|
|
|
.spinner
|
|
|
|
margin 100px auto
|
|
|
|
width 40px
|
|
|
|
height 40px
|
|
|
|
text-align center
|
|
|
|
|
|
|
|
animation sk-rotate 2.0s infinite linear
|
|
|
|
|
|
|
|
.dot1, .dot2
|
|
|
|
width 60%
|
|
|
|
height 60%
|
|
|
|
display inline-block
|
|
|
|
position absolute
|
|
|
|
top 0
|
2018-04-28 18:51:17 -05:00
|
|
|
background rgba(#000, 0.2)
|
2018-02-16 09:36:28 -06:00
|
|
|
border-radius 100%
|
|
|
|
|
|
|
|
animation sk-bounce 2.0s infinite ease-in-out
|
|
|
|
|
|
|
|
.dot2
|
|
|
|
top auto
|
|
|
|
bottom 0
|
|
|
|
animation-delay -1.0s
|
|
|
|
|
|
|
|
@keyframes sk-rotate { 100% { transform: rotate(360deg); }}
|
|
|
|
|
|
|
|
@keyframes sk-bounce {
|
|
|
|
0%, 100% {
|
|
|
|
transform: scale(0.0);
|
|
|
|
} 50% {
|
|
|
|
transform: scale(1.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-21 16:06:47 -06:00
|
|
|
> .file
|
2018-02-16 09:36:28 -06:00
|
|
|
display none
|
|
|
|
|
|
|
|
</style>
|