egirlskey/packages/frontend/src/widgets/server-metric/index.vue

89 lines
2.6 KiB
Vue
Raw Normal View History

2021-01-03 13:38:32 +00:00
<template>
2023-05-29 08:13:12 +00:00
<MkContainer :showHeader="widgetProps.showHeader" :naked="widgetProps.transparent">
2023-01-14 23:30:29 +00:00
<template #icon><i class="ti ti-server"></i></template>
<template #header>{{ i18n.ts._widgets.serverMetric }}</template>
<template #func="{ buttonStyleClass }"><button class="_button" :class="buttonStyleClass" @click="toggleView()"><i class="ti ti-selector"></i></button></template>
2021-01-03 13:38:32 +00:00
<div v-if="meta" data-cy-mkw-serverMetric class="mkw-serverMetric">
<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 13:38:32 +00:00
</div>
</MkContainer>
</template>
<script lang="ts" setup>
import { onUnmounted, ref } from 'vue';
import { useWidgetPropsManager, Widget, WidgetComponentExpose } from '../widget';
2021-01-03 13:38:32 +00: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';
import MkContainer from '@/components/MkContainer.vue';
2022-07-20 13:24:26 +00:00
import { GetFormResultType } from '@/scripts/form';
2021-11-11 17:02:25 +00:00
import * as os from '@/os';
import { useStream } from '@/stream';
2022-07-20 13:24:26 +00:00
import { i18n } from '@/i18n';
2021-01-03 13:38:32 +00:00
const name = 'serverMetric';
2021-01-03 13:38:32 +00:00
const widgetPropsDef = {
showHeader: {
type: 'boolean' as const,
default: true,
2021-01-03 13:38:32 +00:00
},
transparent: {
type: 'boolean' as const,
default: false,
2021-01-03 13:38:32 +00:00
},
view: {
type: 'number' as const,
default: 0,
hidden: true,
2021-01-03 13:38:32 +00: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>; }>();
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
const { widgetProps, configure, save } = useWidgetPropsManager(name,
widgetPropsDef,
props,
emit,
);
const meta = ref(null);
os.api('server-info', {}).then(res => {
meta.value = res;
});
const toggleView = () => {
if (widgetProps.view === 4) {
widgetProps.view = 0;
} else {
widgetProps.view++;
2021-01-03 13:38:32 +00:00
}
save();
};
const connection = useStream().useChannel('serverStats');
onUnmounted(() => {
connection.dispose();
});
defineExpose<WidgetComponentExpose>({
name,
configure,
id: props.widget ? props.widget.id : null,
2021-01-03 13:38:32 +00:00
});
</script>