liu
6 天以前 5c124cdf26e4d749eae1e7fc9df366e9a5f4d259
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
<script lang="ts" setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
 
defineOptions({ name: 'BiClockWidget' });
 
const clockTime = ref('');
const clockDate = ref('');
let timer: ReturnType<typeof setInterval>;
 
function update() {
  const now = new Date();
  clockTime.value = now.toLocaleTimeString('zh-CN', { hour12: false });
  clockDate.value = now.toLocaleDateString('zh-CN', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
}
 
onMounted(() => {
  update();
  timer = setInterval(update, 1000);
});
onBeforeUnmount(() => clearInterval(timer));
</script>
 
<template>
  <div class="clock-widget">
    <span class="clock-time">{{ clockTime }}</span>
    <span class="clock-date">{{ clockDate }}</span>
  </div>
</template>
 
<style scoped>
.clock-widget {
  display: none;
  flex-direction: column;
  align-items: flex-end;
}
 
@media (min-width: 640px) {
  .clock-widget { display: flex; }
}
 
.clock-time {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  color: rgba(230, 236, 250, 0.95);
}
 
.clock-date {
  font-size: 10px;
  color: rgba(180, 190, 215, 0.7);
}
</style>