2023-03-20 04:58:06 +01:00
|
|
|
<template>
|
2023-03-20 05:20:21 +01:00
|
|
|
<div class="_gaps">
|
|
|
|
<MkSelect v-model="sortModeSelect">
|
|
|
|
<template #label>{{ i18n.ts.sort }}</template>
|
|
|
|
<option v-for="x in sortOptions" :key="x.value" :value="x.value">{{ x.displayName }}</option>
|
|
|
|
</MkSelect>
|
|
|
|
<div v-if="!fetching">
|
|
|
|
<MkPagination v-slot="{items}" :pagination="pagination">
|
|
|
|
<div class="_gaps">
|
|
|
|
<div
|
|
|
|
v-for="file in items" :key="file.id"
|
|
|
|
class="_button"
|
|
|
|
@click="$event => onClick($event, file)"
|
|
|
|
@contextmenu.stop="$event => onContextMenu($event, file)"
|
|
|
|
>
|
|
|
|
<div :class="$style.file">
|
|
|
|
<div v-if="file.isSensitive" class="sensitive-label">{{ i18n.ts.sensitive }}</div>
|
|
|
|
<MkDriveFileThumbnail :class="$style.fileThumbnail" :file="file" fit="contain"/>
|
|
|
|
<div :class="$style.fileBody">
|
|
|
|
<div style="margin-bottom: 4px;">
|
|
|
|
{{ file.name }}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span style="margin-right: 1em;">{{ file.type }}</span>
|
|
|
|
<span>{{ bytes(file.size) }}</span>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span>{{ i18n.ts.registeredDate }}: <MkTime :time="file.createdAt" mode="detail"/></span>
|
|
|
|
</div>
|
|
|
|
<div v-if="sortModeSelect === 'sizeDesc'">
|
|
|
|
<div :class="$style.meter"><div :class="$style.meterValue" :style="genUsageBar(file.size)"></div></div>
|
2023-03-20 04:58:06 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-03-20 05:20:21 +01:00
|
|
|
</div>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<MkLoading/>
|
|
|
|
</div>
|
2023-03-20 04:58:06 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { ref, watch } from 'vue';
|
|
|
|
import tinycolor from 'tinycolor2';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import MkPagination from '@/components/MkPagination.vue';
|
|
|
|
import MkDriveFileThumbnail from '@/components/MkDriveFileThumbnail.vue';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import bytes from '@/filters/bytes';
|
|
|
|
import { dateString } from '@/filters/date';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
import MkSelect from '@/components/MkSelect.vue';
|
2023-03-20 05:20:21 +01:00
|
|
|
import { getDriveFileMenu } from '@/scripts/get-drive-file-menu';
|
2023-03-20 04:58:06 +01:00
|
|
|
|
|
|
|
let sortMode = '+size';
|
|
|
|
const pagination = {
|
|
|
|
endpoint: 'drive/files' as const,
|
|
|
|
limit: 10,
|
|
|
|
params: { sort: sortMode },
|
|
|
|
};
|
|
|
|
|
|
|
|
const sortOptions = [
|
|
|
|
{ value: 'sizeDesc', displayName: i18n.ts._drivecleaner.orderBySizeDesc },
|
|
|
|
{ value: 'createdAtAsc', displayName: i18n.ts._drivecleaner.orderByCreatedAtAsc },
|
|
|
|
];
|
|
|
|
|
|
|
|
const capacity = ref<number>(0);
|
|
|
|
const usage = ref<number>(0);
|
|
|
|
const fetching = ref(true);
|
|
|
|
const sortModeSelect = ref('sizeDesc');
|
|
|
|
|
|
|
|
fetchDriveInfo();
|
|
|
|
|
|
|
|
watch(sortModeSelect, () => {
|
|
|
|
switch (sortModeSelect.value) {
|
|
|
|
case 'sizeDesc':
|
|
|
|
sortMode = '+size';
|
2023-03-20 05:20:21 +01:00
|
|
|
fetchDriveInfo();
|
2023-03-20 04:58:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'createdAtAsc':
|
|
|
|
sortMode = '-createdAt';
|
2023-03-20 05:20:21 +01:00
|
|
|
fetchDriveInfo();
|
2023-03-20 04:58:06 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function fetchDriveInfo(): void {
|
2023-03-20 05:20:21 +01:00
|
|
|
fetching.value = true;
|
2023-03-20 04:58:06 +01:00
|
|
|
os.api('drive').then(info => {
|
|
|
|
capacity.value = info.capacity;
|
|
|
|
usage.value = info.usage;
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function genUsageBar(fsize: number): object {
|
|
|
|
return {
|
|
|
|
width: `${fsize / usage.value * 100}%`,
|
|
|
|
background: tinycolor({ h: 180 - (fsize / usage.value * 180), s: 0.7, l: 0.5 }),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-20 05:20:21 +01:00
|
|
|
function onClick(ev: MouseEvent, file) {
|
|
|
|
os.popupMenu(getDriveFileMenu(file), (ev.currentTarget ?? ev.target ?? undefined) as HTMLElement | undefined);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onContextMenu(ev: MouseEvent, file): void {
|
|
|
|
os.contextMenu(getDriveFileMenu(file), ev);
|
2023-03-20 04:58:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.drivecleaner,
|
|
|
|
icon: 'ti ti-trash',
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-03-20 05:20:21 +01:00
|
|
|
<style lang="scss" module>
|
2023-03-20 04:58:06 +01:00
|
|
|
.file {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
text-align: left;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
2023-03-20 05:20:21 +01:00
|
|
|
}
|
2023-03-20 04:58:06 +01:00
|
|
|
|
2023-03-20 05:20:21 +01:00
|
|
|
.fileThumbnail {
|
|
|
|
width: 100px;
|
|
|
|
height: 100px;
|
|
|
|
}
|
2023-03-20 04:58:06 +01:00
|
|
|
|
2023-03-20 05:20:21 +01:00
|
|
|
.fileBody {
|
|
|
|
margin-left: 0.3em;
|
|
|
|
padding: 8px;
|
|
|
|
flex: 1;
|
|
|
|
}
|
2023-03-20 04:58:06 +01:00
|
|
|
|
2023-03-20 05:20:21 +01:00
|
|
|
.meter {
|
|
|
|
margin-top: 8px;
|
|
|
|
height: 12px;
|
|
|
|
background: rgba(0, 0, 0, 0.1);
|
|
|
|
overflow: clip;
|
|
|
|
border-radius: 999px;
|
2023-03-20 04:58:06 +01:00
|
|
|
}
|
|
|
|
|
2023-03-20 05:20:21 +01:00
|
|
|
.meterValue {
|
|
|
|
height: 100%;
|
2023-03-20 04:58:06 +01:00
|
|
|
}
|
|
|
|
</style>
|