-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclock.vue
99 lines (96 loc) · 2.51 KB
/
clock.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<template>
<div class="main is-unselectable">
<div class="clockface" v-bind:class="theme">
<span v-if="!settings.show24h.value">{{clock.time12h}}</span>
<span v-else>{{clock.time24h}}</span>
<span class="small" v-if="settings.showSeconds.value">{{clock.seconds}}</span>
<span class="small" v-if="!settings.show24h.value">{{clock.label}}</span>
</div>
</div>
</template>
<script>
import moment from 'moment';
import store from '../../store';
const widget_name = 'clock';
const manifest = {
name: widget_name, // Widget name
description: 'Simple clock widget',
settings: {
show24h: {
name: 'Show 24 hours',
value: true,
type: 'boolean',
},
showSeconds: {
name: 'Show seconds',
value: false,
type: 'boolean',
},
},
layout: { // default layout
i: widget_name, // Must be the same name
x: 7,
y: 3,
w: 10,
h: 3,
},
};
export default {
name: manifest.name,
data: () => ({
clock: {
time12h: '',
time24h: '',
seconds: '',
label: '',
},
}),
manifest: manifest,
computed: {
settings(){
return store.getters.settings[manifest.name];
},
dark(){
return store.getters.settings.mdash.dark.value
},
theme(){
return {
'has-text-white': this.dark,
'has-text-black': !this.dark,
};
},
},
mounted() {
this.setTime();
this.setSeconds();
setInterval(this.setTime(), 60000); // update time every minute.
setInterval(this.setSeconds, 1000); // update seconds every second.
},
methods: {
setTime() {
this.clock.time12h = moment().format('h:mm');
this.clock.time24h = moment().format('H:mm')
this.setLabel();
},
setSeconds(){
this.clock.seconds = moment().format(':ss');
},
setLabel() {
this.clock.label = moment().format('A');
},
},
};
</script>
<style scoped>
.main {
text-align: center;
font-family: 'Lato', sans-serif;
}
.clockface {
font-size: 9rem;
}
.clockface .small {
font-size: 3rem;
margin-left:-0.5em;
}
</style>