2021-01-03 07:38:32 -06:00
|
|
|
<template>
|
2022-01-08 05:30:01 -06:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" :naked="widgetProps.transparent">
|
2021-04-20 09:22:59 -05:00
|
|
|
<template #header><i class="fas fa-server"></i>{{ $ts._widgets.serverMetric }}</template>
|
2021-11-19 04:36:12 -06:00
|
|
|
<template #func><button class="_button" @click="toggleView()"><i class="fas fa-sort"></i></button></template>
|
2021-01-03 07:38:32 -06:00
|
|
|
|
2021-11-19 04:36:12 -06:00
|
|
|
<div v-if="meta" class="mkw-serverMetric">
|
2022-01-08 05:30:01 -06:00
|
|
|
<XCpuMemory v-if="widgetProps.view === 0" :connection="connection" :meta="meta"/>
|
|
|
|
<XNet v-else-if="widgetProps.view === 1" :connection="connection" :meta="meta"/>
|
|
|
|
<XCpu v-else-if="widgetProps.view === 2" :connection="connection" :meta="meta"/>
|
|
|
|
<XMemory v-else-if="widgetProps.view === 3" :connection="connection" :meta="meta"/>
|
|
|
|
<XDisk v-else-if="widgetProps.view === 4" :connection="connection" :meta="meta"/>
|
2021-01-03 07:38:32 -06:00
|
|
|
</div>
|
|
|
|
</MkContainer>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, ref } from 'vue';
|
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from '../widget';
|
2021-11-11 11:02:25 -06:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
2021-01-03 07:38:32 -06:00
|
|
|
import XCpuMemory from './cpu-mem.vue';
|
|
|
|
import XNet from './net.vue';
|
|
|
|
import XCpu from './cpu.vue';
|
|
|
|
import XMemory from './mem.vue';
|
|
|
|
import XDisk from './disk.vue';
|
2021-11-11 11:02:25 -06:00
|
|
|
import * as os from '@/os';
|
2021-12-29 07:13:09 -06:00
|
|
|
import { stream } from '@/stream';
|
2021-01-03 07:38:32 -06:00
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
const name = 'serverMetric';
|
2021-01-03 07:38:32 -06:00
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2021-01-03 07:38:32 -06:00
|
|
|
},
|
2022-01-08 05:30:01 -06:00
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2021-01-03 07:38:32 -06:00
|
|
|
},
|
2022-01-08 05:30:01 -06:00
|
|
|
view: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 0,
|
|
|
|
hidden: true,
|
2021-01-03 07:38:32 -06:00
|
|
|
},
|
2022-01-08 05:30:01 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 02:43:12 -05:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 05:30:01 -06:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const meta = ref(null);
|
|
|
|
|
|
|
|
os.api('server-info', {}).then(res => {
|
|
|
|
meta.value = res;
|
|
|
|
});
|
|
|
|
|
|
|
|
const toggleView = () => {
|
2022-05-25 02:43:12 -05:00
|
|
|
if (widgetProps.view === 4) {
|
2022-01-08 05:30:01 -06:00
|
|
|
widgetProps.view = 0;
|
|
|
|
} else {
|
|
|
|
widgetProps.view++;
|
2021-01-03 07:38:32 -06:00
|
|
|
}
|
2022-01-08 05:30:01 -06:00
|
|
|
save();
|
|
|
|
};
|
|
|
|
|
|
|
|
const connection = stream.useChannel('serverStats');
|
|
|
|
onUnmounted(() => {
|
|
|
|
connection.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2021-01-03 07:38:32 -06:00
|
|
|
});
|
|
|
|
</script>
|