mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-27 16:40:50 +08:00
feat(frontend): add time manager and unify date formats
This commit is contained in:
@@ -102,6 +102,7 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { stripMarkdown } from '../utils/markdown'
|
||||
import { API_BASE_URL } from '../main'
|
||||
import TimeManager from '../utils/time'
|
||||
import CategorySelect from '../components/CategorySelect.vue'
|
||||
import TagSelect from '../components/TagSelect.vue'
|
||||
import ArticleTags from '../components/ArticleTags.vue'
|
||||
@@ -152,7 +153,7 @@ export default {
|
||||
members: [],
|
||||
comments: (p.comments || []).length,
|
||||
views: p.views,
|
||||
time: new Date(p.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' })
|
||||
time: TimeManager.format(p.createdAt)
|
||||
}))
|
||||
)
|
||||
if (data.length < pageSize) {
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</span>
|
||||
<span class="notif-time">{{ new Date(item.createdAt).toLocaleString() }}</span>
|
||||
<span class="notif-time">{{ TimeManager.format(item.createdAt) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</BaseTimeline>
|
||||
@@ -67,6 +67,7 @@ import { getToken } from '../utils/auth'
|
||||
import { markNotificationsRead } from '../utils/notification'
|
||||
import { toast } from '../main'
|
||||
import { stripMarkdown } from '../utils/markdown'
|
||||
import TimeManager from '../utils/time'
|
||||
import { hatch } from 'ldrs'
|
||||
hatch.register()
|
||||
|
||||
@@ -163,7 +164,7 @@ export default {
|
||||
|
||||
onMounted(fetchNotifications)
|
||||
|
||||
return { notifications, formatType, sanitizeDescription, isLoadingMessage, markRead }
|
||||
return { notifications, formatType, sanitizeDescription, isLoadingMessage, markRead, TimeManager }
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -82,6 +82,7 @@ import ReactionsGroup from '../components/ReactionsGroup.vue'
|
||||
import { renderMarkdown } from '../utils/markdown'
|
||||
import { API_BASE_URL, toast } from '../main'
|
||||
import { getToken } from '../utils/auth'
|
||||
import TimeManager from '../utils/time'
|
||||
import { hatch } from 'ldrs'
|
||||
import { useRouter } from 'vue-router'
|
||||
hatch.register()
|
||||
@@ -129,7 +130,7 @@ export default {
|
||||
const mapComment = c => ({
|
||||
id: c.id,
|
||||
userName: c.author.username,
|
||||
time: new Date(c.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' }),
|
||||
time: TimeManager.format(c.createdAt),
|
||||
avatar: c.author.avatar,
|
||||
text: c.content,
|
||||
reactions: c.reactions || [],
|
||||
@@ -181,7 +182,7 @@ export default {
|
||||
tags.value = data.tags || []
|
||||
postReactions.value = data.reactions || []
|
||||
comments.value = (data.comments || []).map(mapComment)
|
||||
postTime.value = new Date(data.createdAt).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' })
|
||||
postTime.value = TimeManager.format(data.createdAt)
|
||||
await nextTick()
|
||||
gatherPostItems()
|
||||
} catch (e) {
|
||||
|
||||
@@ -181,6 +181,7 @@ import { useRoute } from 'vue-router'
|
||||
import { API_BASE_URL } from '../main'
|
||||
import BaseTimeline from '../components/BaseTimeline.vue'
|
||||
import { stripMarkdown } from '../utils/markdown'
|
||||
import TimeManager from '../utils/time'
|
||||
import { hatch } from 'ldrs'
|
||||
hatch.register()
|
||||
|
||||
@@ -200,7 +201,7 @@ export default {
|
||||
|
||||
const formatDate = (d) => {
|
||||
if (!d) return ''
|
||||
return new Date(d).toLocaleDateString('zh-CN', { year: 'numeric', month: 'numeric', day: 'numeric' })
|
||||
return TimeManager.format(d)
|
||||
}
|
||||
|
||||
const fetchData = async () => {
|
||||
|
||||
Reference in New Issue
Block a user