2020-07-11 01:13:11 +00:00
|
|
|
<template>
|
2020-11-25 12:31:34 +00:00
|
|
|
<div class="mkw-digitalClock _monospace" :class="{ _panel: !props.transparent }" :style="{ fontSize: `${props.fontSize}em` }">
|
2020-07-11 01:13:11 +00:00
|
|
|
<span>
|
|
|
|
<span v-text="hh"></span>
|
|
|
|
<span :style="{ visibility: showColon ? 'visible' : 'hidden' }">:</span>
|
|
|
|
<span v-text="mm"></span>
|
|
|
|
<span :style="{ visibility: showColon ? 'visible' : 'hidden' }">:</span>
|
|
|
|
<span v-text="ss"></span>
|
2021-11-19 10:36:12 +00:00
|
|
|
<span v-if="props.showMs" :style="{ visibility: showColon ? 'visible' : 'hidden' }">:</span>
|
|
|
|
<span v-if="props.showMs" v-text="ms"></span>
|
2020-07-11 01:13:11 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 11:12:00 +00:00
|
|
|
import { defineComponent } from 'vue';
|
2020-07-11 01:13:11 +00:00
|
|
|
import define from './define';
|
2021-11-11 17:02:25 +00:00
|
|
|
import * as os from '@/os';
|
2020-07-11 01:13:11 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
const widget = define({
|
2020-07-11 01:13:11 +00:00
|
|
|
name: 'digitalClock',
|
|
|
|
props: () => ({
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
fontSize: {
|
|
|
|
type: 'number',
|
|
|
|
default: 1.5,
|
|
|
|
step: 0.1,
|
|
|
|
},
|
|
|
|
showMs: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
})
|
2020-10-17 11:12:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
extends: widget,
|
2020-07-11 01:13:11 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
clock: null,
|
|
|
|
hh: null,
|
|
|
|
mm: null,
|
|
|
|
ss: null,
|
|
|
|
ms: null,
|
|
|
|
showColon: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.tick();
|
2020-10-17 11:12:00 +00:00
|
|
|
this.$watch(() => this.props.showMs, () => {
|
2020-07-11 01:13:11 +00:00
|
|
|
if (this.clock) clearInterval(this.clock);
|
|
|
|
this.clock = setInterval(this.tick, this.props.showMs ? 10 : 1000);
|
|
|
|
}, { immediate: true });
|
|
|
|
},
|
2020-10-17 11:12:00 +00:00
|
|
|
beforeUnmount() {
|
2020-07-11 01:13:11 +00:00
|
|
|
clearInterval(this.clock);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
tick() {
|
|
|
|
const now = new Date();
|
|
|
|
this.hh = now.getHours().toString().padStart(2, '0');
|
|
|
|
this.mm = now.getMinutes().toString().padStart(2, '0');
|
|
|
|
this.ss = now.getSeconds().toString().padStart(2, '0');
|
|
|
|
this.ms = Math.floor(now.getMilliseconds() / 10).toString().padStart(2, '0');
|
|
|
|
this.showColon = now.getSeconds() % 2 === 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mkw-digitalClock {
|
|
|
|
padding: 16px 0;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
</style>
|