Skip to content

Commit

Permalink
feat: support display seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
jic999 committed Mar 4, 2024
1 parent dccc679 commit e102a79
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ settings:
title: Show Time
showDate:
title: Show Date
showSecond:
title: Show Second
showLunar:
title: Show Lunar
showFooter:
Expand Down
2 changes: 2 additions & 0 deletions src/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ settings:
title: 時刻を表示
showDate:
title: 日付を表示
showSecond:
title: 秒を表示
showLunar:
title: 旧暦を表示
showFooter:
Expand Down
2 changes: 2 additions & 0 deletions src/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ settings:
title: 显示时间
showDate:
title: 显示日期
showSecond:
title: 显示秒钟
showLunar:
title: 显示农历
showFooter:
Expand Down
16 changes: 12 additions & 4 deletions src/pages/home/components/MainClock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import solarLunar from 'solarlunar-es'
const settingStore = useSettingStore()
const $time = ref<HTMLDivElement | null>(null)
const date = ref('')
const time = ref('')
const lunarDate = ref('')
Expand All @@ -15,10 +17,16 @@ function refreshTime() {
const lang = settingStore.settings.language === 'System' ? navigator.language : settingStore.settings.language
date.value = now.toLocaleString(lang, { month: 'long', day: 'numeric' })
week.value = now.toLocaleString(lang, { weekday: 'long' })
time.value = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`
if (settingStore.getSettingValue('showSecond'))
time.value = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`
else
time.value = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`
$time.value!.innerText = time.value
// 若为0点 或阴历为空 刷新日期
// en: If 00:00 or the lunar is empty, refresh date
if (!lunarDate.value || time.value === '00:00')
if (!lunarDate.value || time.value === '00:00' || time.value === '00:00:00')
getDate()
return refreshTime
}
Expand All @@ -42,7 +50,7 @@ function timing() {
refreshTime()
// 若 nowMinute !== newMinute 说明开始了新的分钟
// en: nowMinute !== newMinute means a new minute has started
if (nowMinute !== time.value) {
if (!settingStore.getSettingValue('showSecond') && nowMinute !== time.value) {
// 清除每秒定时器 开启分钟定时器
// en: Clear second timer and start minute timer
clearInterval(timeInterval)
Expand All @@ -61,7 +69,7 @@ onBeforeUnmount(() => {

<template>
<div text-center>
<div v-if="settingStore.getSettingValue('showTime')" text-48>
<div v-if="settingStore.getSettingValue('showTime')" ref="$time" text-48 tracking-wide>
{{ time }}
</div>
<p text="14 $text-c-1">
Expand Down
8 changes: 8 additions & 0 deletions src/pages/home/components/MainSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ function loadData(data: any) {
value-field="key"
:on-update-value="(key: string) => settingStore.setSettings({ showDate: key })"
/>
<SettingSelection
v-model="settingStore.settings.showSecond"
:title="S.showSecond.name"
:options="S.showSecond.children"
label-field="name"
value-field="key"
:on-update-value="(key: string) => settingStore.setSettings({ showSecond: key })"
/>
<SettingSelection
v-model="settingStore.settings.showLunar"
:title="S.showLunar.name"
Expand Down
1 change: 1 addition & 0 deletions src/utils/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './website_preference'
export * from './show_footer'
export * from './show_time'
export * from './show_date'
export * from './show_second'
export * from './language'
export * from './tag_mode'
export * from './link_strategy'
13 changes: 13 additions & 0 deletions src/utils/settings/show_second.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SettingItem, type SettingItemChildren } from '@/types'

const showSecondList: SettingItemChildren<boolean> = [
{ name: () => t('settings.common.show'), key: 'Show', value: true },
{ name: () => t('settings.common.hide'), key: 'Hide', value: false },
]

export const showSecond = new SettingItem({
name: () => t('settings.showSecond.title'),
key: 'ShowSecond',
children: showSecondList,
defaultKey: 'Hide',
})

0 comments on commit e102a79

Please sign in to comment.