refactor(client): refactor settings/drive to use Composition API (#8573)
This commit is contained in:
parent
7a51f0ac94
commit
fc02f8fc93
1 changed files with 57 additions and 78 deletions
|
@ -1,41 +1,41 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="_formRoot">
|
<div class="_formRoot">
|
||||||
<FormSection v-if="!fetching">
|
<FormSection v-if="!fetching">
|
||||||
<template #label>{{ $ts.usageAmount }}</template>
|
<template #label>{{ i18n.ts.usageAmount }}</template>
|
||||||
<div class="_formBlock uawsfosz">
|
<div class="_formBlock uawsfosz">
|
||||||
<div class="meter"><div :style="meterStyle"></div></div>
|
<div class="meter"><div :style="meterStyle"></div></div>
|
||||||
</div>
|
</div>
|
||||||
<FormSplit>
|
<FormSplit>
|
||||||
<MkKeyValue class="_formBlock">
|
<MkKeyValue class="_formBlock">
|
||||||
<template #key>{{ $ts.capacity }}</template>
|
<template #key>{{ i18n.ts.capacity }}</template>
|
||||||
<template #value>{{ bytes(capacity, 1) }}</template>
|
<template #value>{{ bytes(capacity, 1) }}</template>
|
||||||
</MkKeyValue>
|
</MkKeyValue>
|
||||||
<MkKeyValue class="_formBlock">
|
<MkKeyValue class="_formBlock">
|
||||||
<template #key>{{ $ts.inUse }}</template>
|
<template #key>{{ i18n.ts.inUse }}</template>
|
||||||
<template #value>{{ bytes(usage, 1) }}</template>
|
<template #value>{{ bytes(usage, 1) }}</template>
|
||||||
</MkKeyValue>
|
</MkKeyValue>
|
||||||
</FormSplit>
|
</FormSplit>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
|
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<template #label>{{ $ts.statistics }}</template>
|
<template #label>{{ i18n.ts.statistics }}</template>
|
||||||
<MkChart src="per-user-drive" :args="{ user: $i }" span="day" :limit="7 * 5" :bar="true" :stacked="true" :detailed="false" :aspect-ratio="6"/>
|
<MkChart src="per-user-drive" :args="{ user: $i }" span="day" :limit="7 * 5" :bar="true" :stacked="true" :detailed="false" :aspect-ratio="6"/>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
|
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<FormLink @click="chooseUploadFolder()">
|
<FormLink @click="chooseUploadFolder()">
|
||||||
{{ $ts.uploadFolder }}
|
{{ i18n.ts.uploadFolder }}
|
||||||
<template #suffix>{{ uploadFolder ? uploadFolder.name : '-' }}</template>
|
<template #suffix>{{ uploadFolder ? uploadFolder.name : '-' }}</template>
|
||||||
<template #suffixIcon><i class="fas fa-folder-open"></i></template>
|
<template #suffixIcon><i class="fas fa-folder-open"></i></template>
|
||||||
</FormLink>
|
</FormLink>
|
||||||
<FormSwitch v-model="keepOriginalUploading" class="_formBlock">{{ $ts.keepOriginalUploading }}<template #caption>{{ $ts.keepOriginalUploadingDescription }}</template></FormSwitch>
|
<FormSwitch v-model="keepOriginalUploading" class="_formBlock">{{ i18n.ts.keepOriginalUploading }}<template #caption>{{ i18n.ts.keepOriginalUploadingDescription }}</template></FormSwitch>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent } from 'vue';
|
import { computed, defineExpose, ref } from 'vue';
|
||||||
import tinycolor from 'tinycolor2';
|
import * as tinycolor from 'tinycolor2';
|
||||||
import FormLink from '@/components/form/link.vue';
|
import FormLink from '@/components/form/link.vue';
|
||||||
import FormSwitch from '@/components/form/switch.vue';
|
import FormSwitch from '@/components/form/switch.vue';
|
||||||
import FormSection from '@/components/form/section.vue';
|
import FormSection from '@/components/form/section.vue';
|
||||||
|
@ -46,80 +46,59 @@ import bytes from '@/filters/bytes';
|
||||||
import * as symbols from '@/symbols';
|
import * as symbols from '@/symbols';
|
||||||
import { defaultStore } from '@/store';
|
import { defaultStore } from '@/store';
|
||||||
import MkChart from '@/components/chart.vue';
|
import MkChart from '@/components/chart.vue';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
export default defineComponent({
|
const fetching = ref(true);
|
||||||
components: {
|
const usage = ref<any>(null);
|
||||||
FormLink,
|
const capacity = ref<any>(null);
|
||||||
FormSwitch,
|
const uploadFolder = ref<any>(null);
|
||||||
FormSection,
|
|
||||||
MkKeyValue,
|
|
||||||
FormSplit,
|
|
||||||
MkChart,
|
|
||||||
},
|
|
||||||
|
|
||||||
emits: ['info'],
|
const meterStyle = computed(() => {
|
||||||
|
return {
|
||||||
|
width: `${usage.value / capacity.value * 100}%`,
|
||||||
|
background: tinycolor({
|
||||||
|
h: 180 - (usage.value / capacity.value * 180),
|
||||||
|
s: 0.7,
|
||||||
|
l: 0.5
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
data() {
|
const keepOriginalUploading = computed(defaultStore.makeGetterSetter('keepOriginalUploading'));
|
||||||
return {
|
|
||||||
[symbols.PAGE_INFO]: {
|
os.api('drive').then(info => {
|
||||||
title: this.$ts.drive,
|
capacity.value = info.capacity;
|
||||||
icon: 'fas fa-cloud',
|
usage.value = info.usage;
|
||||||
bg: 'var(--bg)',
|
fetching.value = false;
|
||||||
},
|
});
|
||||||
fetching: true,
|
|
||||||
usage: null,
|
if (defaultStore.state.uploadFolder) {
|
||||||
capacity: null,
|
os.api('drive/folders/show', {
|
||||||
uploadFolder: null,
|
folderId: defaultStore.state.uploadFolder
|
||||||
|
}).then(response => {
|
||||||
|
uploadFolder.value = response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function chooseUploadFolder() {
|
||||||
|
os.selectDriveFolder(false).then(async folder => {
|
||||||
|
defaultStore.set('uploadFolder', folder ? folder.id : null);
|
||||||
|
os.success();
|
||||||
|
if (defaultStore.state.uploadFolder) {
|
||||||
|
uploadFolder.value = await os.api('drive/folders/show', {
|
||||||
|
folderId: defaultStore.state.uploadFolder
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
uploadFolder.value = null;
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
|
}
|
||||||
|
|
||||||
computed: {
|
defineExpose({
|
||||||
meterStyle(): any {
|
[symbols.PAGE_INFO]: {
|
||||||
return {
|
title: i18n.ts.drive,
|
||||||
width: `${this.usage / this.capacity * 100}%`,
|
icon: 'fas fa-cloud',
|
||||||
background: tinycolor({
|
bg: 'var(--bg)',
|
||||||
h: 180 - (this.usage / this.capacity * 180),
|
|
||||||
s: 0.7,
|
|
||||||
l: 0.5
|
|
||||||
})
|
|
||||||
};
|
|
||||||
},
|
|
||||||
keepOriginalUploading: defaultStore.makeGetterSetter('keepOriginalUploading'),
|
|
||||||
},
|
|
||||||
|
|
||||||
async created() {
|
|
||||||
os.api('drive').then(info => {
|
|
||||||
this.capacity = info.capacity;
|
|
||||||
this.usage = info.usage;
|
|
||||||
this.fetching = false;
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.renderChart();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.$store.state.uploadFolder) {
|
|
||||||
this.uploadFolder = await os.api('drive/folders/show', {
|
|
||||||
folderId: this.$store.state.uploadFolder
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
chooseUploadFolder() {
|
|
||||||
os.selectDriveFolder(false).then(async folder => {
|
|
||||||
this.$store.set('uploadFolder', folder ? folder.id : null);
|
|
||||||
os.success();
|
|
||||||
if (this.$store.state.uploadFolder) {
|
|
||||||
this.uploadFolder = await os.api('drive/folders/show', {
|
|
||||||
folderId: this.$store.state.uploadFolder
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.uploadFolder = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
bytes
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue