2020-12-30 05:07:16 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div
|
|
|
|
class="mkw-onlineUsers"
|
|
|
|
:class="{
|
|
|
|
_panel: !widgetProps.transparent,
|
|
|
|
pad: !widgetProps.transparent,
|
|
|
|
}"
|
|
|
|
>
|
|
|
|
<I18n
|
|
|
|
v-if="onlineUsersCount"
|
|
|
|
:src="i18n.ts.onlineUsersCount"
|
|
|
|
text-tag="span"
|
|
|
|
class="text"
|
|
|
|
>
|
|
|
|
<template #n
|
|
|
|
><b>{{ onlineUsersCount }}</b></template
|
|
|
|
>
|
|
|
|
</I18n>
|
|
|
|
</div>
|
2020-12-30 05:07:16 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { onMounted, onUnmounted, ref } from "vue";
|
|
|
|
import {
|
|
|
|
useWidgetPropsManager,
|
|
|
|
Widget,
|
|
|
|
WidgetComponentEmits,
|
|
|
|
WidgetComponentExpose,
|
|
|
|
WidgetComponentProps,
|
|
|
|
} from "./widget";
|
|
|
|
import { GetFormResultType } from "@/scripts/form";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { useInterval } from "@/scripts/use-interval";
|
|
|
|
import { i18n } from "@/i18n";
|
2020-12-30 05:07:16 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const name = "onlineUsers";
|
2020-12-30 05:07:16 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "boolean" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: true,
|
2020-12-30 05:07:16 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2023-04-08 02:01:42 +02:00
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
|
|
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(
|
|
|
|
name,
|
2022-01-08 12:30:01 +01:00
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
2023-04-08 02:01:42 +02:00
|
|
|
emit
|
2022-01-08 12:30:01 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const onlineUsersCount = ref(0);
|
|
|
|
|
|
|
|
const tick = () => {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("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>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mkw-onlineUsers {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
&.pad {
|
|
|
|
padding: 16px 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
|
|
|
::v-deep(b) {
|
2023-03-20 00:58:54 +01:00
|
|
|
color: var(--badge);
|
2020-12-30 05:07:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
::v-deep(span) {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|