Browse Source

refactor: 调整12小时制,小时的处理方式

nmtuan 1 year ago
parent
commit
b1ab5901f5
3 changed files with 17 additions and 7 deletions
  1. 3 3
      app.vue
  2. 2 2
      components/clock/board.vue
  3. 12 2
      stores/date.ts

+ 3 - 3
app.vue

@@ -2,7 +2,7 @@
  * @Author: NMTuan
  * @Email: NMTuan@qq.com
  * @Date: 2024-02-18 11:35:10
- * @LastEditTime: 2024-02-22 12:23:55
+ * @LastEditTime: 2024-02-22 13:11:25
  * @LastEditors: NMTuan
  * @Description: 
  * @FilePath: \timeNow\app.vue
@@ -45,12 +45,12 @@ onBeforeUnmount(() => {
 
 const title = computed(() => {
     let tit = ''
-    tit += !dateStore.hour24 && dateStore.hour > 12 ? dateStore.hour % 12 : dateStore.hour
+    tit += dateStore.hour12
     tit += ':' + dateStore.minute
     if (settingStore.showSecond) {
         tit += ':' + dateStore.second
     }
-    tit += '- 压感时钟'
+    tit += ' - 压感时钟'
     return tit
 })
 

+ 2 - 2
components/clock/board.vue

@@ -2,14 +2,14 @@
  * @Author: NMTuan
  * @Email: NMTuan@qq.com
  * @Date: 2024-02-18 11:48:34
- * @LastEditTime: 2024-02-22 12:28:57
+ * @LastEditTime: 2024-02-22 13:17:49
  * @LastEditors: NMTuan
  * @Description: 
  * @FilePath: \timeNow\components\clock\board.vue
 -->
 <template>
     <div class="text-zinc-200 text-[22vw] leading-[24vw] text-center font-digital-dismay">
-        <span>{{ !settingStore.hour24 && dateStore.hour > 12 ? dateStore.hour % 12 : dateStore.hour }}</span>
+        <span>{{ dateStore.hour12 }}</span>
         <span class="transition-all"
             :class="[settingStore.flicker && (dateStore.second % 2 === 0 ? 'opacity-1' : 'opacity-0')]">:</span>
         <span>{{ dateStore.minute }}</span>

+ 12 - 2
stores/date.ts

@@ -2,18 +2,21 @@
  * @Author: NMTuan
  * @Email: NMTuan@qq.com
  * @Date: 2024-02-19 22:13:33
- * @LastEditTime: 2024-02-19 23:06:51
+ * @LastEditTime: 2024-02-22 13:17:11
  * @LastEditors: NMTuan
  * @Description:
- * @FilePath: /timeNow/stores/date.ts
+ * @FilePath: \timeNow\stores\date.ts
  */
 import { defineStore } from 'pinia'
 
 export const useDateStore = defineStore('date', () => {
+    const settingStore = useSettingStore()
+
     const year = ref('1970')
     const month = ref('01')
     const date = ref('01')
     const hour = ref('00')
+    const hour12 = ref('00')
     const minute = ref('00')
     const second = ref('00')
     const millisecond = ref(0)
@@ -24,7 +27,13 @@ export const useDateStore = defineStore('date', () => {
         year.value = today.getFullYear().toString()
         month.value = (today.getMonth() + 1).toString().padStart(2, '0')
         date.value = today.getDate().toString().padStart(2, '0')
+
         hour.value = today.getHours().toString().padStart(2, '0')
+        let h = today.getHours()
+        if (!settingStore.hour24 && h > 12) {
+            h = h % 12
+        }
+        hour12.value = h.toString().padStart(2, '0')
         minute.value = today.getMinutes().toString().padStart(2, '0')
         second.value = today.getSeconds().toString().padStart(2, '0')
         millisecond.value = today.getMilliseconds()
@@ -36,6 +45,7 @@ export const useDateStore = defineStore('date', () => {
         month,
         date,
         hour,
+        hour12,
         minute,
         second,
         millisecond,