2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2021-01-23 18:14:57 +09:00
|
|
|
<FormBase class="">
|
|
|
|
<FormGroup v-if="!fetching">
|
|
|
|
<template #label>{{ $ts.usageAmount }}</template>
|
|
|
|
<div class="_formItem uawsfosz">
|
|
|
|
<div class="_formPanel">
|
|
|
|
<div class="meter"><div :style="meterStyle"></div></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<FormKeyValueView>
|
|
|
|
<template #key>{{ $ts.capacity }}</template>
|
|
|
|
<template #value>{{ bytes(capacity, 1) }}</template>
|
|
|
|
</FormKeyValueView>
|
|
|
|
<FormKeyValueView>
|
|
|
|
<template #key>{{ $ts.inUse }}</template>
|
|
|
|
<template #value>{{ bytes(usage, 1) }}</template>
|
|
|
|
</FormKeyValueView>
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<div class="_formItem">
|
|
|
|
<div class="_formLabel">{{ $ts.statistics }}</div>
|
|
|
|
<div class="_formPanel">
|
|
|
|
<div ref="chart"></div>
|
|
|
|
</div>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
2021-01-23 18:14:57 +09:00
|
|
|
|
|
|
|
<FormButton :center="false" @click="chooseUploadFolder()" primary>
|
|
|
|
{{ $ts.uploadFolder }}
|
|
|
|
<template #suffix>{{ uploadFolder ? uploadFolder.name : '-' }}</template>
|
2021-04-20 23:22:59 +09:00
|
|
|
<template #suffixIcon><i class="fas fa-folder-open"></i></template>
|
2021-01-23 18:14:57 +09:00
|
|
|
</FormButton>
|
|
|
|
</FormBase>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent } from 'vue';
|
2021-01-23 18:14:57 +09:00
|
|
|
import * as tinycolor from 'tinycolor2';
|
|
|
|
import ApexCharts from 'apexcharts';
|
2021-03-23 17:30:14 +09:00
|
|
|
import FormButton from '@client/components/form/button.vue';
|
|
|
|
import FormGroup from '@client/components/form/group.vue';
|
|
|
|
import FormKeyValueView from '@client/components/form/key-value-view.vue';
|
|
|
|
import FormBase from '@client/components/form/base.vue';
|
|
|
|
import * as os from '@client/os';
|
|
|
|
import bytes from '@client/filters/bytes';
|
2021-04-10 12:54:12 +09:00
|
|
|
import * as symbols from '@client/symbols';
|
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: {
|
2021-01-23 18:14:57 +09:00
|
|
|
FormBase,
|
|
|
|
FormButton,
|
|
|
|
FormGroup,
|
|
|
|
FormKeyValueView,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
2021-01-23 18:14:57 +09:00
|
|
|
emits: ['info'],
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 12:54:12 +09:00
|
|
|
[symbols.PAGE_INFO]: {
|
2021-01-23 18:14:57 +09:00
|
|
|
title: this.$ts.drive,
|
2021-04-20 23:22:59 +09:00
|
|
|
icon: 'fas fa-cloud'
|
2021-01-23 18:14:57 +09:00
|
|
|
},
|
|
|
|
fetching: true,
|
|
|
|
usage: null,
|
|
|
|
capacity: null,
|
2020-04-22 00:34:56 +09:00
|
|
|
uploadFolder: null,
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-01-23 18:14:57 +09:00
|
|
|
computed: {
|
|
|
|
meterStyle(): any {
|
|
|
|
return {
|
|
|
|
width: `${this.usage / this.capacity * 100}%`,
|
|
|
|
background: tinycolor({
|
|
|
|
h: 180 - (this.usage / this.capacity * 180),
|
|
|
|
s: 0.7,
|
|
|
|
l: 0.5
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-22 00:34:56 +09:00
|
|
|
async created() {
|
2021-01-23 18:14:57 +09:00
|
|
|
os.api('drive').then(info => {
|
|
|
|
this.capacity = info.capacity;
|
|
|
|
this.usage = info.usage;
|
|
|
|
this.fetching = false;
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.renderChart();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-19 10:55:52 +09:00
|
|
|
if (this.$store.state.uploadFolder) {
|
2020-10-17 20:12:00 +09:00
|
|
|
this.uploadFolder = await os.api('drive/folders/show', {
|
2020-12-19 10:55:52 +09:00
|
|
|
folderId: this.$store.state.uploadFolder
|
2020-04-22 00:34:56 +09:00
|
|
|
});
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
2021-01-23 18:14:57 +09:00
|
|
|
mounted() {
|
2021-04-10 12:54:12 +09:00
|
|
|
this.$emit('info', this[symbols.PAGE_INFO]);
|
2021-01-23 18:14:57 +09:00
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
methods: {
|
2020-04-22 00:34:56 +09:00
|
|
|
chooseUploadFolder() {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.selectDriveFolder(false).then(async folder => {
|
2020-12-19 10:55:52 +09:00
|
|
|
this.$store.set('uploadFolder', folder ? folder.id : null);
|
2020-10-17 20:12:00 +09:00
|
|
|
os.success();
|
2020-12-19 10:55:52 +09:00
|
|
|
if (this.$store.state.uploadFolder) {
|
2020-10-17 20:12:00 +09:00
|
|
|
this.uploadFolder = await os.api('drive/folders/show', {
|
2020-12-19 10:55:52 +09:00
|
|
|
folderId: this.$store.state.uploadFolder
|
2020-04-22 00:34:56 +09:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.uploadFolder = null;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
2021-01-23 18:14:57 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
renderChart() {
|
|
|
|
os.api('charts/user/drive', {
|
|
|
|
userId: this.$i.id,
|
|
|
|
span: 'day',
|
|
|
|
limit: 21
|
|
|
|
}).then(stats => {
|
|
|
|
const addition = [];
|
|
|
|
const deletion = [];
|
|
|
|
const now = new Date();
|
|
|
|
const y = now.getFullYear();
|
|
|
|
const m = now.getMonth();
|
|
|
|
const d = now.getDate();
|
|
|
|
for (let i = 0; i < 21; i++) {
|
|
|
|
const x = new Date(y, m, d - i);
|
|
|
|
addition.push([
|
|
|
|
x,
|
|
|
|
stats.incSize[i]
|
|
|
|
]);
|
|
|
|
deletion.push([
|
|
|
|
x,
|
|
|
|
-stats.decSize[i]
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
const chart = new ApexCharts(this.$refs.chart, {
|
|
|
|
chart: {
|
|
|
|
type: 'bar',
|
|
|
|
stacked: true,
|
|
|
|
height: 150,
|
|
|
|
toolbar: {
|
|
|
|
show: false
|
|
|
|
},
|
|
|
|
zoom: {
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plotOptions: {
|
|
|
|
bar: {
|
|
|
|
columnWidth: '80%'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
clipMarkers: false,
|
|
|
|
borderColor: 'rgba(0, 0, 0, 0.1)',
|
|
|
|
xaxis: {
|
|
|
|
lines: {
|
|
|
|
show: true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
shared: true,
|
|
|
|
intersect: false,
|
|
|
|
theme: this.$store.state.darkMode ? 'dark' : 'light',
|
|
|
|
},
|
|
|
|
dataLabels: {
|
|
|
|
enabled: false
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
show: false
|
|
|
|
},
|
|
|
|
series: [{
|
|
|
|
name: 'Additions',
|
|
|
|
data: addition
|
|
|
|
}, {
|
|
|
|
name: 'Deletions',
|
|
|
|
data: deletion
|
|
|
|
}],
|
|
|
|
xaxis: {
|
|
|
|
type: 'datetime',
|
|
|
|
labels: {
|
|
|
|
style: {
|
|
|
|
colors: tinycolor(getComputedStyle(document.documentElement).getPropertyValue('--fg')).toRgbString()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
axisBorder: {
|
|
|
|
color: 'rgba(0, 0, 0, 0.1)'
|
|
|
|
},
|
|
|
|
axisTicks: {
|
|
|
|
color: 'rgba(0, 0, 0, 0.1)'
|
|
|
|
},
|
|
|
|
crosshairs: {
|
|
|
|
width: 1,
|
|
|
|
opacity: 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
yaxis: {
|
|
|
|
labels: {
|
|
|
|
formatter: v => bytes(v, 0),
|
|
|
|
style: {
|
|
|
|
colors: tinycolor(getComputedStyle(document.documentElement).getPropertyValue('--fg')).toRgbString()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
chart.render();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
bytes
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2020-01-30 11:10:42 +09:00
|
|
|
.uawsfosz {
|
2021-01-23 18:14:57 +09:00
|
|
|
> div {
|
|
|
|
padding: 24px;
|
|
|
|
|
|
|
|
> .meter {
|
|
|
|
$size: 12px;
|
|
|
|
background: rgba(0, 0, 0, 0.1);
|
|
|
|
border-radius: ($size / 2);
|
2021-03-02 22:57:16 +09:00
|
|
|
overflow: hidden;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2021-01-23 18:14:57 +09:00
|
|
|
> div {
|
|
|
|
height: $size;
|
|
|
|
border-radius: ($size / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
</style>
|