2020-12-30 05:07:16 +01:00
|
|
|
<template>
|
2023-05-24 07:34:46 +02:00
|
|
|
<div data-cy-mkw-onlineUsers :class="[$style.root, { _panel: !widgetProps.transparent, [$style.pad]: !widgetProps.transparent }]">
|
|
|
|
<span :class="$style.text">
|
|
|
|
<I18n v-if="onlineUsersCount" :src="i18n.ts.onlineUsersCount" textTag="span">
|
|
|
|
<template #n><b style="color: #41b781;">{{ number(onlineUsersCount) }}</b></template>
|
|
|
|
</I18n>
|
|
|
|
</span>
|
2020-12-30 05:07:16 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 15:09:41 +01:00
|
|
|
import { ref } from 'vue';
|
2023-05-19 09:20:53 +02:00
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2022-06-25 20:12:58 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
2022-06-25 20:12:58 +02:00
|
|
|
import { useInterval } from '@/scripts/use-interval';
|
2022-07-20 15:24:26 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2023-02-23 11:51:10 +01:00
|
|
|
import number from '@/filters/number';
|
2020-12-30 05:07:16 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'onlineUsers';
|
2020-12-30 05:07:16 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-12-30 05:07:16 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 09:20:53 +02:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const onlineUsersCount = ref(0);
|
|
|
|
|
|
|
|
const tick = () => {
|
2023-07-02 01:28:26 +02:00
|
|
|
os.apiGet('get-online-users-count').then(res => {
|
2022-01-08 12:30:01 +01:00
|
|
|
onlineUsersCount.value = res.count;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-25 20:12:58 +02:00
|
|
|
useInterval(tick, 1000 * 15, {
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
2022-01-08 12:30:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-12-30 05:07:16 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-05-24 07:34:46 +02:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2020-12-30 05:07:16 +01:00
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
&.pad {
|
|
|
|
padding: 16px 0;
|
|
|
|
}
|
2023-05-24 07:34:46 +02:00
|
|
|
}
|
2020-12-30 05:07:16 +01:00
|
|
|
|
2023-05-24 07:34:46 +02:00
|
|
|
.text {
|
|
|
|
color: var(--fgTransparentWeak);
|
2020-12-30 05:07:16 +01:00
|
|
|
}
|
|
|
|
</style>
|