优化 时间显示格式调整

This commit is contained in:
2025-10-12 23:39:28 +08:00
parent b2fda14451
commit 27133aa107
9 changed files with 208 additions and 70 deletions

View File

@@ -43,6 +43,7 @@ import { ref, computed, onMounted, nextTick, watch } from 'vue'
import { useAppStore } from '../stores/useAppStore'
import Header from '../components/Header.vue'
import RichTextEditor from '../components/RichTextEditor.vue'
import { formatNoteEditorDate } from '../utils/dateUtils'
const props = defineProps({
id: {
@@ -158,23 +159,10 @@ const handleContentChange = (newContent) => {
// 计算属性
const formattedTime = computed(() => {
const now = new Date()
const date = existingNote?.updatedAt ? new Date(existingNote.updatedAt) : now
// 如果是今天
if (date.toDateString() === now.toDateString()) {
return `今天 ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`
if (existingNote?.updatedAt) {
return formatNoteEditorDate(existingNote.updatedAt)
}
// 如果是昨天
const yesterday = new Date(now)
yesterday.setDate(yesterday.getDate() - 1)
if (date.toDateString() === yesterday.toDateString()) {
return `昨天 ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`
}
// 其他情况显示月日
return `${date.getMonth() + 1}${date.getDate()}`
return formatNoteEditorDate(new Date())
})
const wordCount = computed(() => {

View File

@@ -65,6 +65,7 @@ import NoteItem from '../components/NoteItem.vue'
import Header from '../components/Header.vue'
import FolderManage from '../components/FolderManage.vue'
import SearchBar from '../components/SearchBar.vue'
import { formatNoteListDate } from '../utils/dateUtils'
const store = useAppStore()
@@ -318,31 +319,7 @@ const debouncedHandleSearch = debounceSearch((query) => {
// 改进的日期格式化函数
const formatDate = dateString => {
const date = new Date(dateString)
const now = new Date()
// 计算日期差
const diffTime = now - date
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))
// 今天的便签显示时间
if (diffDays === 0) {
return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`
}
// 昨天的便签显示"昨天"
if (diffDays === 1) {
return '昨天'
}
// 一周内的便签显示星期几
if (diffDays < 7) {
const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
return weekdays[date.getDay()]
}
// 超过一周的便签显示月日
return `${date.getMonth() + 1}/${date.getDate()}`
return formatNoteListDate(dateString)
}
const setCurrentFolder = folder => {