2020-12-30 13:07:16 +09:00
|
|
|
<template>
|
2023-03-09 19:59:11 +09:00
|
|
|
<div data-cy-mkw-onlineUsers class="mkw-onlineUsers" :class="{ _panel: !widgetProps.transparent, pad: !widgetProps.transparent }">
|
2023-05-17 11:42:50 +09:00
|
|
|
<I18n v-if="onlineUsersCount" :src="i18n.ts.onlineUsersCount" textTag="span" class="text">
|
2023-02-23 19:51:10 +09:00
|
|
|
<template #n><b>{{ number(onlineUsersCount) }}</b></template>
|
2020-12-30 13:07:16 +09:00
|
|
|
</I18n>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 23:09:41 +09:00
|
|
|
import { ref } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentExpose } from './widget';
|
2022-06-26 03:12:58 +09:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2022-06-26 03:12:58 +09:00
|
|
|
import { useInterval } from '@/scripts/use-interval';
|
2022-07-20 22:24:26 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2023-02-23 19:51:10 +09:00
|
|
|
import number from '@/filters/number';
|
2020-12-30 13:07:16 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const name = 'onlineUsers';
|
2020-12-30 13:07:16 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-12-30 13:07:16 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09: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 16:43:12 +09:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 20:30:01 +09: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;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-26 03:12:58 +09:00
|
|
|
useInterval(tick, 1000 * 15, {
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
2022-01-08 20:30:01 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-12-30 13:07:16 +09:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-27 18:29:39 +09:00
|
|
|
<style lang="scss" scoped>
|
2020-12-30 13:07:16 +09:00
|
|
|
.mkw-onlineUsers {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
&.pad {
|
|
|
|
padding: 16px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
|
|
|
::v-deep(b) {
|
|
|
|
color: #41b781;
|
|
|
|
}
|
|
|
|
|
|
|
|
::v-deep(span) {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|