2020-12-30 06:07:16 +02:00
|
|
|
<template>
|
2022-01-08 13:30:01 +02:00
|
|
|
<div class="mkw-onlineUsers" :class="{ _panel: !widgetProps.transparent, pad: !widgetProps.transparent }">
|
2020-12-30 06:07:16 +02:00
|
|
|
<I18n v-if="onlineUsersCount" :src="$ts.onlineUsersCount" text-tag="span" class="text">
|
|
|
|
<template #n><b>{{ onlineUsersCount }}</b></template>
|
|
|
|
</I18n>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 13:30:01 +02: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 19:02:25 +02:00
|
|
|
import * as os from '@/os';
|
2020-12-30 06:07:16 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const name = 'onlineUsers';
|
2020-12-30 06:07:16 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-12-30 06:07:16 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02: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 10:43:12 +03:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 13:30:01 +02:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const onlineUsersCount = ref(0);
|
|
|
|
|
|
|
|
const tick = () => {
|
|
|
|
os.api('get-online-users-count').then(res => {
|
|
|
|
onlineUsersCount.value = res.count;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
tick();
|
2022-01-16 03:14:14 +02:00
|
|
|
const intervalId = window.setInterval(tick, 1000 * 15);
|
2022-01-08 13:30:01 +02:00
|
|
|
onUnmounted(() => {
|
2022-01-16 03:14:14 +02:00
|
|
|
window.clearInterval(intervalId);
|
2022-01-08 13:30:01 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-12-30 06:07:16 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mkw-onlineUsers {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
&.pad {
|
|
|
|
padding: 16px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
|
|
|
::v-deep(b) {
|
|
|
|
color: #41b781;
|
|
|
|
}
|
|
|
|
|
|
|
|
::v-deep(span) {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|