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