rudeshark.net/packages/client/src/widgets/online-users.vue

99 lines
1.9 KiB
Vue
Raw Normal View History

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>
<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
const widgetPropsDef = {
transparent: {
2023-04-08 02:01:42 +02:00
type: "boolean" as const,
default: true,
2020-12-30 05:07:16 +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) }>();
2023-04-08 02:01:42 +02:00
const { widgetProps, configure } = useWidgetPropsManager(
name,
widgetPropsDef,
props,
2023-04-08 02:01:42 +02:00
emit
);
const onlineUsersCount = ref(0);
const tick = () => {
2023-04-08 02:01:42 +02:00
os.api("get-online-users-count").then((res) => {
onlineUsersCount.value = res.count;
});
};
useInterval(tick, 1000 * 15, {
immediate: true,
afterMounted: true,
});
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>