2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2021-11-19 19:36:12 +09:00
|
|
|
<div v-show="files.length != 0" class="skeikyzd">
|
|
|
|
<XDraggable v-model="_files" class="files" item-key="id" animation="150" delay="100" delay-on-touch-only="true">
|
2020-12-05 12:50:09 +09:00
|
|
|
<template #item="{element}">
|
2022-07-05 23:01:23 +09:00
|
|
|
<div class="file" @click="showFileMenu(element, $event)" @contextmenu.prevent="showFileMenu(element, $event)">
|
2020-12-05 12:50:09 +09:00
|
|
|
<MkDriveFileThumbnail :data-id="element.id" class="thumbnail" :file="element" fit="cover"/>
|
2021-11-19 19:36:12 +09:00
|
|
|
<div v-if="element.isSensitive" class="sensitive">
|
2023-03-12 06:01:04 +09:00
|
|
|
<i class="ph-warning ph-bold ph-lg icon"></i>
|
2020-12-05 12:50:09 +09:00
|
|
|
</div>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
2020-12-05 12:50:09 +09:00
|
|
|
</template>
|
2020-10-17 20:12:00 +09:00
|
|
|
</XDraggable>
|
2022-01-21 18:27:33 +09:00
|
|
|
<p class="remain">{{ 16 - files.length }}/16</p>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent, defineAsyncComponent } from 'vue';
|
2022-08-31 00:24:33 +09:00
|
|
|
import MkDriveFileThumbnail from '@/components/MkDriveFileThumbnail.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2022-11-11 07:12:44 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-01-30 04:37:25 +09:00
|
|
|
components: {
|
2020-12-05 12:50:09 +09:00
|
|
|
XDraggable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2022-07-05 23:01:23 +09:00
|
|
|
MkDriveFileThumbnail,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
files: {
|
|
|
|
type: Array,
|
2022-07-05 23:01:23 +09:00
|
|
|
required: true,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
detachMediaFn: {
|
|
|
|
type: Function,
|
2022-07-05 23:01:23 +09:00
|
|
|
required: false,
|
|
|
|
},
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
2020-12-05 12:50:09 +09:00
|
|
|
emits: ['updated', 'detach', 'changeSensitive', 'changeName'],
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
data() {
|
|
|
|
return {
|
2020-02-04 09:20:10 +09:00
|
|
|
menu: null as Promise<null> | null,
|
2022-11-11 17:41:34 +09:00
|
|
|
i18n,
|
2020-01-30 04:37:25 +09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2020-12-05 12:50:09 +09:00
|
|
|
computed: {
|
|
|
|
_files: {
|
|
|
|
get() {
|
|
|
|
return this.files;
|
|
|
|
},
|
|
|
|
set(value) {
|
|
|
|
this.$emit('updated', value);
|
2022-07-05 23:01:23 +09:00
|
|
|
},
|
|
|
|
},
|
2020-12-05 12:50:09 +09:00
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
methods: {
|
|
|
|
detachMedia(id) {
|
|
|
|
if (this.detachMediaFn) {
|
|
|
|
this.detachMediaFn(id);
|
2020-10-17 20:12:00 +09:00
|
|
|
} else {
|
|
|
|
this.$emit('detach', id);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
toggleSensitive(file) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('drive/files/update', {
|
2020-01-30 04:37:25 +09:00
|
|
|
fileId: file.id,
|
2022-07-05 23:01:23 +09:00
|
|
|
isSensitive: !file.isSensitive,
|
2020-01-30 04:37:25 +09:00
|
|
|
}).then(() => {
|
2020-12-05 12:50:09 +09:00
|
|
|
this.$emit('changeSensitive', file, !file.isSensitive);
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
},
|
|
|
|
async rename(file) {
|
2021-11-18 18:45:58 +09:00
|
|
|
const { canceled, result } = await os.inputText({
|
2022-11-11 17:22:00 +09:00
|
|
|
title: i18n.ts.enterFileName,
|
2021-11-18 18:45:58 +09:00
|
|
|
default: file.name,
|
2022-07-05 23:01:23 +09:00
|
|
|
allowEmpty: false,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
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: file.id,
|
2022-07-05 23:01:23 +09:00
|
|
|
name: result,
|
2020-01-30 04:37:25 +09:00
|
|
|
}).then(() => {
|
2020-12-05 12:50:09 +09:00
|
|
|
this.$emit('changeName', file, result);
|
2020-01-30 04:37:25 +09:00
|
|
|
file.name = result;
|
|
|
|
});
|
|
|
|
},
|
2021-05-28 09:38:09 +09:00
|
|
|
|
|
|
|
async describe(file) {
|
2022-08-31 00:24:33 +09:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkMediaCaption.vue')), {
|
2022-11-11 17:22:00 +09:00
|
|
|
title: i18n.ts.describeFile,
|
2021-05-28 09:38:09 +09:00
|
|
|
input: {
|
2022-11-11 17:22:00 +09:00
|
|
|
placeholder: i18n.ts.inputNewDescription,
|
2022-07-05 23:01:23 +09:00
|
|
|
default: file.comment !== null ? file.comment : '',
|
2021-05-28 09:38:09 +09:00
|
|
|
},
|
2022-07-05 23:01:23 +09:00
|
|
|
image: file,
|
2021-05-28 09:38:09 +09:00
|
|
|
}, {
|
|
|
|
done: result => {
|
|
|
|
if (!result || result.canceled) return;
|
2022-05-26 22:53:09 +09:00
|
|
|
let comment = result.result.length === 0 ? null : result.result;
|
2021-05-28 09:38:09 +09:00
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: file.id,
|
2022-01-21 17:43:51 +09:00
|
|
|
comment: comment,
|
|
|
|
}).then(() => {
|
|
|
|
file.comment = comment;
|
2021-05-28 09:38:09 +09:00
|
|
|
});
|
2022-07-05 23:01:23 +09:00
|
|
|
},
|
2021-05-28 09:38:09 +09:00
|
|
|
}, 'closed');
|
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
showFileMenu(file, ev: MouseEvent) {
|
2020-02-04 09:20:10 +09:00
|
|
|
if (this.menu) return;
|
2021-08-08 12:19:10 +09:00
|
|
|
this.menu = os.popupMenu([{
|
2022-11-11 17:22:00 +09:00
|
|
|
text: i18n.ts.renameFile,
|
2023-03-12 06:01:04 +09:00
|
|
|
icon: 'ph-cursor-text ph-bold ph-lg',
|
2022-07-05 23:01:23 +09:00
|
|
|
action: () => { this.rename(file); },
|
2020-10-17 20:12:00 +09:00
|
|
|
}, {
|
2022-11-11 17:22:00 +09:00
|
|
|
text: file.isSensitive ? i18n.ts.unmarkAsSensitive : i18n.ts.markAsSensitive,
|
2023-03-12 06:01:04 +09:00
|
|
|
icon: file.isSensitive ? 'ph-eye-slash-bold ph-lg' : 'ph-eye ph-bold ph-lg',
|
2022-07-05 23:01:23 +09:00
|
|
|
action: () => { this.toggleSensitive(file); },
|
2021-05-28 09:38:09 +09:00
|
|
|
}, {
|
2022-11-11 17:22:00 +09:00
|
|
|
text: i18n.ts.describeFile,
|
2023-03-12 06:01:04 +09:00
|
|
|
icon: 'ph-cursor-text ph-bold ph-lg',
|
2022-07-05 23:01:23 +09:00
|
|
|
action: () => { this.describe(file); },
|
2020-10-17 20:12:00 +09:00
|
|
|
}, {
|
2022-11-11 17:22:00 +09:00
|
|
|
text: i18n.ts.attachCancel,
|
2023-03-12 06:01:04 +09:00
|
|
|
icon: 'ph-circle-wavy-warning ph-bold ph-lg',
|
2022-07-05 23:01:23 +09:00
|
|
|
action: () => { this.detachMedia(file.id); },
|
2022-01-28 11:53:12 +09:00
|
|
|
}], ev.currentTarget ?? ev.target).then(() => this.menu = null);
|
2022-07-05 23:01:23 +09:00
|
|
|
},
|
|
|
|
},
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.skeikyzd {
|
2020-10-17 20:12:00 +09:00
|
|
|
padding: 8px 16px;
|
2020-01-30 04:37:25 +09:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .files {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
2022-07-05 23:01:23 +09:00
|
|
|
> .file {
|
2020-01-30 04:37:25 +09:00
|
|
|
position: relative;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
2020-10-17 20:12:00 +09:00
|
|
|
margin-right: 4px;
|
|
|
|
border-radius: 4px;
|
2021-03-02 22:57:16 +09:00
|
|
|
overflow: hidden;
|
2020-01-30 04:37:25 +09:00
|
|
|
cursor: move;
|
|
|
|
|
|
|
|
&:hover > .remove {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
z-index: 1;
|
|
|
|
color: var(--fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .sensitive {
|
|
|
|
display: flex;
|
|
|
|
position: absolute;
|
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
z-index: 2;
|
|
|
|
background: rgba(17, 17, 17, .7);
|
|
|
|
color: #fff;
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .remain {
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 8px;
|
|
|
|
right: 8px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|