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(() => {
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
return {
|
||||||
[symbols.PAGE_INFO]: {
|
width: `${usage.value / capacity.value * 100}%`,
|
||||||
title: this.$ts.drive,
|
|
||||||
icon: 'fas fa-cloud',
|
|
||||||
bg: 'var(--bg)',
|
|
||||||
},
|
|
||||||
fetching: true,
|
|
||||||
usage: null,
|
|
||||||
capacity: null,
|
|
||||||
uploadFolder: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
meterStyle(): any {
|
|
||||||
return {
|
|
||||||
width: `${this.usage / this.capacity * 100}%`,
|
|
||||||
background: tinycolor({
|
background: tinycolor({
|
||||||
h: 180 - (this.usage / this.capacity * 180),
|
h: 180 - (usage.value / capacity.value * 180),
|
||||||
s: 0.7,
|
s: 0.7,
|
||||||
l: 0.5
|
l: 0.5
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
},
|
});
|
||||||
keepOriginalUploading: defaultStore.makeGetterSetter('keepOriginalUploading'),
|
|
||||||
},
|
|
||||||
|
|
||||||
async created() {
|
const keepOriginalUploading = computed(defaultStore.makeGetterSetter('keepOriginalUploading'));
|
||||||
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) {
|
os.api('drive').then(info => {
|
||||||
this.uploadFolder = await os.api('drive/folders/show', {
|
capacity.value = info.capacity;
|
||||||
folderId: this.$store.state.uploadFolder
|
usage.value = info.usage;
|
||||||
});
|
fetching.value = false;
|
||||||
}
|
});
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
if (defaultStore.state.uploadFolder) {
|
||||||
chooseUploadFolder() {
|
os.api('drive/folders/show', {
|
||||||
|
folderId: defaultStore.state.uploadFolder
|
||||||
|
}).then(response => {
|
||||||
|
uploadFolder.value = response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function chooseUploadFolder() {
|
||||||
os.selectDriveFolder(false).then(async folder => {
|
os.selectDriveFolder(false).then(async folder => {
|
||||||
this.$store.set('uploadFolder', folder ? folder.id : null);
|
defaultStore.set('uploadFolder', folder ? folder.id : null);
|
||||||
os.success();
|
os.success();
|
||||||
if (this.$store.state.uploadFolder) {
|
if (defaultStore.state.uploadFolder) {
|
||||||
this.uploadFolder = await os.api('drive/folders/show', {
|
uploadFolder.value = await os.api('drive/folders/show', {
|
||||||
folderId: this.$store.state.uploadFolder
|
folderId: defaultStore.state.uploadFolder
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.uploadFolder = null;
|
uploadFolder.value = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
bytes
|
defineExpose({
|
||||||
|
[symbols.PAGE_INFO]: {
|
||||||
|
title: i18n.ts.drive,
|
||||||
|
icon: 'fas fa-cloud',
|
||||||
|
bg: 'var(--bg)',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue