2020-07-11 03:13:11 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div
|
|
|
|
class="mkw-digitalClock _monospace"
|
|
|
|
:class="{ _panel: !widgetProps.transparent }"
|
|
|
|
:style="{ fontSize: `${widgetProps.fontSize}em` }"
|
|
|
|
>
|
|
|
|
<div v-if="widgetProps.showLabel" class="label">{{ tzAbbrev }}</div>
|
|
|
|
<div class="time">
|
|
|
|
<MkDigitalClock :show-ms="widgetProps.showMs" :offset="tzOffset" />
|
|
|
|
</div>
|
|
|
|
<div v-if="widgetProps.showLabel" class="label">
|
|
|
|
{{ tzOffsetLabel }}
|
|
|
|
</div>
|
2022-08-04 15:20:00 +02:00
|
|
|
</div>
|
2020-07-11 03:13:11 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { onUnmounted, ref, watch } from "vue";
|
|
|
|
import {
|
|
|
|
useWidgetPropsManager,
|
|
|
|
Widget,
|
|
|
|
WidgetComponentEmits,
|
|
|
|
WidgetComponentExpose,
|
|
|
|
WidgetComponentProps,
|
|
|
|
} from "./widget";
|
|
|
|
import { GetFormResultType } from "@/scripts/form";
|
|
|
|
import { timezones } from "@/scripts/timezones";
|
|
|
|
import MkDigitalClock from "@/components/MkDigitalClock.vue";
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const name = "digitalClock";
|
2020-10-17 13:12:00 +02: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: false,
|
2020-07-11 03:13:11 +02:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
fontSize: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "number" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: 1.5,
|
|
|
|
step: 0.1,
|
2020-07-11 03:13:11 +02:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
showMs: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "boolean" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: true,
|
2020-07-11 03:13:11 +02:00
|
|
|
},
|
2022-08-05 16:51:15 +02:00
|
|
|
showLabel: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "boolean" as const,
|
2022-08-05 16:51:15 +02:00
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
timezone: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "enum" as const,
|
2022-08-05 16:51:15 +02:00
|
|
|
default: null,
|
2023-04-08 02:01:42 +02:00
|
|
|
enum: [
|
|
|
|
...timezones.map((tz) => ({
|
|
|
|
label: tz.name,
|
|
|
|
value: tz.name.toLowerCase(),
|
|
|
|
})),
|
|
|
|
{
|
|
|
|
label: "(auto)",
|
|
|
|
value: null,
|
|
|
|
},
|
|
|
|
],
|
2022-08-05 16:51:15 +02: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
|
|
|
);
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const tzAbbrev = $computed(
|
|
|
|
() =>
|
|
|
|
(widgetProps.timezone === null
|
|
|
|
? timezones.find(
|
|
|
|
(tz) =>
|
|
|
|
tz.name.toLowerCase() ===
|
|
|
|
Intl.DateTimeFormat()
|
|
|
|
.resolvedOptions()
|
|
|
|
.timeZone.toLowerCase()
|
|
|
|
)?.abbrev
|
|
|
|
: timezones.find(
|
|
|
|
(tz) => tz.name.toLowerCase() === widgetProps.timezone
|
|
|
|
)?.abbrev) ?? "?"
|
|
|
|
);
|
2022-08-05 16:51:15 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const tzOffset = $computed(() =>
|
|
|
|
widgetProps.timezone === null
|
|
|
|
? 0 - new Date().getTimezoneOffset()
|
|
|
|
: timezones.find((tz) => tz.name.toLowerCase() === widgetProps.timezone)
|
|
|
|
?.offset ?? 0
|
|
|
|
);
|
2022-08-05 16:51:15 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const tzOffsetLabel = $computed(
|
|
|
|
() =>
|
|
|
|
(tzOffset >= 0 ? "+" : "-") +
|
|
|
|
Math.floor(tzOffset / 60)
|
|
|
|
.toString()
|
|
|
|
.padStart(2, "0") +
|
|
|
|
":" +
|
|
|
|
(tzOffset % 60).toString().padStart(2, "0")
|
|
|
|
);
|
2022-08-05 16:51:15 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-07-11 03:13:11 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mkw-digitalClock {
|
|
|
|
padding: 16px 0;
|
|
|
|
text-align: center;
|
2022-08-04 15:20:00 +02:00
|
|
|
|
2022-08-05 16:51:15 +02:00
|
|
|
> .label {
|
|
|
|
font-size: 65%;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2020-07-11 03:13:11 +02:00
|
|
|
}
|
|
|
|
</style>
|