fix: 全局格式化

This commit is contained in:
Tim
2025-08-11 18:16:13 +08:00
parent 31cff70f63
commit 1c4df40f12
76 changed files with 1442 additions and 939 deletions

View File

@@ -12,18 +12,33 @@
<div class="profile-page-header-user-info">
<div class="profile-page-header-user-info-name">{{ user.username }}</div>
<div class="profile-page-header-user-info-description">{{ user.introduction }}</div>
<div v-if="!isMine && !subscribed" class="profile-page-header-subscribe-button" @click="subscribeUser">
<div
v-if="!isMine && !subscribed"
class="profile-page-header-subscribe-button"
@click="subscribeUser"
>
<i class="fas fa-user-plus"></i>
关注
</div>
<div v-if="!isMine && subscribed" class="profile-page-header-unsubscribe-button" @click="unsubscribeUser">
<div
v-if="!isMine && subscribed"
class="profile-page-header-unsubscribe-button"
@click="unsubscribeUser"
>
<i class="fas fa-user-minus"></i>
取消关注
</div>
<LevelProgress :exp="levelInfo.exp" :current-level="levelInfo.currentLevel" :next-exp="levelInfo.nextExp" />
<LevelProgress
:exp="levelInfo.exp"
:current-level="levelInfo.currentLevel"
:next-exp="levelInfo.nextExp"
/>
<div class="profile-level-target">
目标 Lv.{{ levelInfo.currentLevel + 1 }}
<i class="fas fa-info-circle profile-exp-info" title="经验值可通过发帖、评论等操作获得,达到目标后即可提升等级,解锁更多功能。"></i>
<i
class="fas fa-info-circle profile-exp-info"
title="经验值可通过发帖、评论等操作获得,达到目标后即可提升等级,解锁更多功能。"
></i>
</div>
</div>
</div>
@@ -39,8 +54,8 @@
</div>
<div class="profile-info-item">
<div class="profile-info-item-label">最后评论时间:</div>
<div class="profile-info-item-value">{{ user.lastCommentTime != null ? formatDate(user.lastCommentTime) :
"暂无评论" }}
<div class="profile-info-item-value">
{{ user.lastCommentTime != null ? formatDate(user.lastCommentTime) : '暂无评论' }}
</div>
</div>
<div class="profile-info-item">
@@ -50,21 +65,31 @@
</div>
<div class="profile-tabs">
<div :class="['profile-tabs-item', { selected: selectedTab === 'summary' }]" @click="selectedTab = 'summary'">
<div
:class="['profile-tabs-item', { selected: selectedTab === 'summary' }]"
@click="selectedTab = 'summary'"
>
<i class="fas fa-chart-line"></i>
<div class="profile-tabs-item-label">总结</div>
</div>
<div :class="['profile-tabs-item', { selected: selectedTab === 'timeline' }]" @click="selectedTab = 'timeline'">
<div
:class="['profile-tabs-item', { selected: selectedTab === 'timeline' }]"
@click="selectedTab = 'timeline'"
>
<i class="fas fa-clock"></i>
<div class="profile-tabs-item-label">时间线</div>
</div>
<div :class="['profile-tabs-item', { selected: selectedTab === 'following' }]"
@click="selectedTab = 'following'">
<div
:class="['profile-tabs-item', { selected: selectedTab === 'following' }]"
@click="selectedTab = 'following'"
>
<i class="fas fa-user-plus"></i>
<div class="profile-tabs-item-label">关注</div>
</div>
<div :class="['profile-tabs-item', { selected: selectedTab === 'achievements' }]"
@click="selectedTab = 'achievements'">
<div
:class="['profile-tabs-item', { selected: selectedTab === 'achievements' }]"
@click="selectedTab = 'achievements'"
>
<i class="fas fa-medal"></i>
<div class="profile-tabs-item-label">勋章</div>
</div>
@@ -108,17 +133,19 @@
</router-link>
<template v-if="item.comment.parentComment">
下对
<router-link :to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
class="timeline-link">
<router-link
:to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
</router-link>
回复了
</template>
<template v-else>
下评论了
</template>
<router-link :to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link">
<template v-else> 下评论了 </template>
<router-link
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.content, 200) }}
</router-link>
<div class="timeline-date">
@@ -177,7 +204,11 @@
</div>
<div v-else-if="selectedTab === 'timeline'" class="profile-timeline">
<BasePlaceholder v-if="timelineItems.length === 0" text="暂无时间线" icon="fas fa-inbox" />
<BasePlaceholder
v-if="timelineItems.length === 0"
text="暂无时间线"
icon="fas fa-inbox"
/>
<BaseTimeline :items="timelineItems">
<template #item="{ item }">
<template v-if="item.type === 'post'">
@@ -193,7 +224,10 @@
{{ item.comment.post.title }}
</router-link>
下评论了
<router-link :to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`" class="timeline-link">
<router-link
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.content, 200) }}
</router-link>
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
@@ -204,12 +238,17 @@
{{ item.comment.post.title }}
</router-link>
下对
<router-link :to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
class="timeline-link">
<router-link
:to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
</router-link>
回复了
<router-link :to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`" class="timeline-link">
<router-link
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.content, 200) }}
</router-link>
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
@@ -230,10 +269,16 @@
<div v-else-if="selectedTab === 'following'" class="follow-container">
<div class="follow-tabs">
<div :class="['follow-tab-item', { selected: followTab === 'followers' }]" @click="followTab = 'followers'">
<div
:class="['follow-tab-item', { selected: followTab === 'followers' }]"
@click="followTab = 'followers'"
>
关注者
</div>
<div :class="['follow-tab-item', { selected: followTab === 'following' }]" @click="followTab = 'following'">
<div
:class="['follow-tab-item', { selected: followTab === 'following' }]"
@click="followTab = 'following'"
>
正在关注
</div>
</div>
@@ -266,7 +311,7 @@ import { prevLevelExp } from '../utils/level'
import AchievementList from '../components/AchievementList.vue'
definePageMeta({
alias: ['/users/:id/']
alias: ['/users/:id/'],
})
export default {
@@ -291,7 +336,7 @@ export default {
const selectedTab = ref(
['summary', 'timeline', 'following', 'achievements'].includes(route.query.tab)
? route.query.tab
: 'summary'
: 'summary',
)
const followTab = ref('followers')
@@ -306,7 +351,7 @@ export default {
return { exp, currentLevel, nextExp, percent }
})
const isMine = computed(function() {
const isMine = computed(function () {
const mine = authState.username === username || String(authState.userId) === username
console.log(mine)
return mine
@@ -334,19 +379,19 @@ export default {
const postsRes = await fetch(`${API_BASE_URL}/api/users/${username}/hot-posts`)
if (postsRes.ok) {
const data = await postsRes.json()
hotPosts.value = data.map(p => ({ icon: 'fas fa-book', post: p }))
hotPosts.value = data.map((p) => ({ icon: 'fas fa-book', post: p }))
}
const repliesRes = await fetch(`${API_BASE_URL}/api/users/${username}/hot-replies`)
if (repliesRes.ok) {
const data = await repliesRes.json()
hotReplies.value = data.map(c => ({ icon: 'fas fa-comment', comment: c }))
hotReplies.value = data.map((c) => ({ icon: 'fas fa-comment', comment: c }))
}
const tagsRes = await fetch(`${API_BASE_URL}/api/users/${username}/hot-tags`)
if (tagsRes.ok) {
const data = await tagsRes.json()
hotTags.value = data.map(t => ({ icon: 'fas fa-tag', tag: t }))
hotTags.value = data.map((t) => ({ icon: 'fas fa-tag', tag: t }))
}
}
@@ -354,30 +399,30 @@ export default {
const [postsRes, repliesRes, tagsRes] = await Promise.all([
fetch(`${API_BASE_URL}/api/users/${username}/posts?limit=50`),
fetch(`${API_BASE_URL}/api/users/${username}/replies?limit=50`),
fetch(`${API_BASE_URL}/api/users/${username}/tags?limit=50`)
fetch(`${API_BASE_URL}/api/users/${username}/tags?limit=50`),
])
const posts = postsRes.ok ? await postsRes.json() : []
const replies = repliesRes.ok ? await repliesRes.json() : []
const tags = tagsRes.ok ? await tagsRes.json() : []
const mapped = [
...posts.map(p => ({
...posts.map((p) => ({
type: 'post',
icon: 'fas fa-book',
post: p,
createdAt: p.createdAt
createdAt: p.createdAt,
})),
...replies.map(r => ({
...replies.map((r) => ({
type: r.parentComment ? 'reply' : 'comment',
icon: 'fas fa-comment',
comment: r,
createdAt: r.createdAt
createdAt: r.createdAt,
})),
...tags.map(t => ({
...tags.map((t) => ({
type: 'tag',
icon: 'fas fa-tag',
tag: t,
createdAt: t.createdAt
}))
createdAt: t.createdAt,
})),
]
mapped.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
timelineItems.value = mapped
@@ -386,7 +431,7 @@ export default {
const fetchFollowUsers = async () => {
const [followerRes, followingRes] = await Promise.all([
fetch(`${API_BASE_URL}/api/users/${username}/followers`),
fetch(`${API_BASE_URL}/api/users/${username}/following`)
fetch(`${API_BASE_URL}/api/users/${username}/following`),
])
followers.value = followerRes.ok ? await followerRes.json() : []
followings.value = followingRes.ok ? await followingRes.json() : []
@@ -434,7 +479,7 @@ export default {
}
const res = await fetch(`${API_BASE_URL}/api/subscriptions/users/${username}`, {
method: 'POST',
headers: { Authorization: `Bearer ${token}` }
headers: { Authorization: `Bearer ${token}` },
})
if (res.ok) {
subscribed.value = true
@@ -452,7 +497,7 @@ export default {
}
const res = await fetch(`${API_BASE_URL}/api/subscriptions/users/${username}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${token}` }
headers: { Authorization: `Bearer ${token}` },
})
if (res.ok) {
subscribed.value = false
@@ -462,7 +507,7 @@ export default {
}
}
const gotoTag = tag => {
const gotoTag = (tag) => {
const value = encodeURIComponent(tag.id ?? tag.name)
router.push({ path: '/', query: { tags: value } })
}
@@ -488,11 +533,15 @@ export default {
onMounted(init)
watch(selectedTab, async val => {
watch(selectedTab, async (val) => {
// router.replace({ query: { ...route.query, tab: val } })
if (val === 'timeline' && timelineItems.value.length === 0) {
await loadTimeline()
} else if (val === 'following' && followers.value.length === 0 && followings.value.length === 0) {
} else if (
val === 'following' &&
followers.value.length === 0 &&
followings.value.length === 0
) {
await loadFollow()
} else if (val === 'achievements' && medals.value.length === 0) {
await loadAchievements()
@@ -524,9 +573,9 @@ export default {
unsubscribeUser,
gotoTag,
hotTags,
levelInfo
levelInfo,
}
}
},
}
</script>
@@ -808,7 +857,8 @@ export default {
padding: 40px 0;
}
.follow-container {}
.follow-container {
}
.follow-tabs {
display: flex;