feat: |UI| show local datetime string and add useUTCDate option (#483)

This commit is contained in:
Dream Hunter
2024-11-15 00:04:17 +08:00
committed by GitHub
parent 3c81e05a2f
commit c102004f4d
7 changed files with 38 additions and 13 deletions

View File

@@ -4,6 +4,7 @@
## main(v0.8.0)
- feat: |UI| 随机生成地址时不超过最大长度
- feat: |UI| 邮件时间显示浏览器时区,可在设置中切换显示为 UTC 时间
## v0.7.6

View File

@@ -6,6 +6,7 @@ import { useGlobalState } from '../store'
import { CloudDownloadRound, ReplyFilled } from '@vicons/material'
import { useIsMobile } from '../utils/composables'
import { processItem, getDownloadEmlUrl } from '../utils/email-parser'
import { utcToLocalDate } from '../utils';
const message = useMessage()
const isMobile = useIsMobile()
@@ -49,7 +50,7 @@ const props = defineProps({
})
const {
isDark, mailboxSplitSize, indexTab, loading,
isDark, mailboxSplitSize, indexTab, loading, useUTCDate,
useIframeShowMail, sendMailModel, preferShowTextMail
} = useGlobalState()
const autoRefresh = ref(false)
@@ -375,7 +376,7 @@ onBeforeUnmount(() => {
ID: {{ row.id }}
</n-tag>
<n-tag type="info">
{{ `${row.created_at} UTC` }}
{{ utcToLocalDate(row.created_at, useUTCDate) }}
</n-tag>
<n-tag type="info">
FROM: {{ row.source }}
@@ -397,7 +398,7 @@ onBeforeUnmount(() => {
ID: {{ curMail.id }}
</n-tag>
<n-tag type="info">
{{ `${curMail.created_at} UTC` }}
{{ utcToLocalDate(curMail.created_at, useUTCDate) }}
</n-tag>
<n-tag type="info">
FROM: {{ curMail.source }}
@@ -471,7 +472,7 @@ onBeforeUnmount(() => {
ID: {{ row.id }}
</n-tag>
<n-tag type="info">
{{ `${row.created_at} UTC` }}
{{ utcToLocalDate(row.created_at, useUTCDate) }}
</n-tag>
<n-tag type="info">
FROM: {{ row.source }}
@@ -493,7 +494,7 @@ onBeforeUnmount(() => {
ID: {{ curMail.id }}
</n-tag>
<n-tag type="info">
{{ `${curMail.created_at} UTC` }}
{{ utcToLocalDate(curMail.created_at, useUTCDate) }}
</n-tag>
<n-tag type="info">
FROM: {{ curMail.source }}

View File

@@ -4,6 +4,7 @@ import { useMessage } from 'naive-ui'
import { useI18n } from 'vue-i18n'
import { useGlobalState } from '../store'
import { useIsMobile } from '../utils/composables'
import { utcToLocalDate } from '../utils';
const message = useMessage()
const isMobile = useIsMobile()
@@ -30,7 +31,7 @@ const props = defineProps({
},
})
const { isDark, mailboxSplitSize, loading } = useGlobalState()
const { isDark, mailboxSplitSize, loading, useUTCDate } = useGlobalState()
const data = ref([])
const count = ref(0)
@@ -251,7 +252,7 @@ onMounted(async () => {
ID: {{ row.id }}
</n-tag>
<n-tag type="info">
{{ `${row.created_at} UTC` }}
{{ utcToLocalDate(row.created_at, useUTCDate) }}
</n-tag>
<n-tag v-if="showEMailFrom" type="info">
FROM: {{ row.address }}
@@ -273,7 +274,7 @@ onMounted(async () => {
ID: {{ curMail.id }}
</n-tag>
<n-tag type="info">
{{ `${curMail.created_at} UTC` }}
{{ utcToLocalDate(curMail.created_at, useUTCDate) }}
</n-tag>
<n-tag type="info">
FROM: {{ curMail.address }}
@@ -320,7 +321,7 @@ onMounted(async () => {
ID: {{ row.id }}
</n-tag>
<n-tag type="info">
{{ `${row.created_at} UTC` }}
{{ utcToLocalDate(row.created_at, useUTCDate) }}
</n-tag>
<n-tag v-if="showEMailFrom" type="info">
FROM: {{ row.address }}
@@ -342,7 +343,7 @@ onMounted(async () => {
ID: {{ curMail.id }}
</n-tag>
<n-tag type="info">
{{ `${curMail.created_at} UTC` }}
{{ utcToLocalDate(curMail.created_at, useUTCDate) }}
</n-tag>
<n-tag type="info">
FROM: {{ curMail.address }}

View File

@@ -70,6 +70,7 @@ export const useGlobalState = createGlobalState(
const indexTab = useSessionStorage('indexTab', 'mailbox');
const globalTabplacement = useStorage('globalTabplacement', 'top');
const useSideMargin = useStorage('useSideMargin', true);
const useUTCDate = useStorage('useUTCDate', false);
const userOpenSettings = ref({
fetched: false,
enable: false,
@@ -127,6 +128,7 @@ export const useGlobalState = createGlobalState(
userSettings,
globalTabplacement,
useSideMargin,
useUTCDate,
telegramApp,
isTelegram,
showAdminPage,

View File

@@ -11,3 +11,17 @@ export const getRouterPathWithLang = (path: string, lang: string) => {
}
return `/${lang}${path}`;
}
export const utcToLocalDate = (utcDate: string, useUTCDate: boolean) => {
const utcDateString = `${utcDate} UTC`;
if (useUTCDate) {
return utcDateString;
}
try {
const date = new Date(utcDateString);
return date.toLocaleString();
} catch (e) {
console.error(e);
}
return utcDateString;
}

View File

@@ -6,7 +6,7 @@ import { useGlobalState } from '../../store'
const {
mailboxSplitSize, useIframeShowMail, preferShowTextMail,
globalTabplacement, useSideMargin
globalTabplacement, useSideMargin, useUTCDate
} = useGlobalState()
const isMobile = useIsMobile()
@@ -22,6 +22,7 @@ const { t } = useI18n({
top: 'top',
right: 'right',
bottom: 'bottom',
useUTCDate: 'Use UTC Date',
},
zh: {
mailboxSplitSize: '邮箱界面分栏大小',
@@ -33,6 +34,7 @@ const { t } = useI18n({
top: '顶部',
right: '右侧',
bottom: '底部',
useUTCDate: '使用 UTC 时间',
}
}
});
@@ -54,6 +56,9 @@ const { t } = useI18n({
<n-form-item-row :label="t('useIframeShowMail')">
<n-switch v-model:value="useIframeShowMail" :round="false" />
</n-form-item-row>
<n-form-item-row :label="t('useUTCDate')">
<n-switch v-model:value="useUTCDate" :round="false" />
</n-form-item-row>
<n-form-item-row v-if="!isMobile" :label="t('useSideMargin')">
<n-switch v-model:value="useSideMargin" :round="false" />
</n-form-item-row>

View File

@@ -5,8 +5,9 @@ import { useGlobalState } from '../../store'
import { api } from '../../api'
import { onMounted, watch } from 'vue';
import { processItem } from '../../utils/email-parser'
import { utcToLocalDate } from '../../utils';
const { telegramApp, loading } = useGlobalState()
const { telegramApp, loading, useUTCDate } = useGlobalState()
const route = useRoute()
const curMail = ref({});
@@ -50,7 +51,7 @@ onMounted(async () => {
ID: {{ curMail.id }}
</n-tag>
<n-tag type="info">
Date: {{ curMail.created_at }}
Date: {{ utcToLocalDate(curMail.created_at, useUTCDate) }}
</n-tag>
<n-tag type="info">
FROM: {{ curMail.source }}