Skip to content

Commit f792ff8

Browse files
committed
chore: 优化角色徽章相关代码与显示逻辑
1 parent 1b538af commit f792ff8

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/components/forum/ForumRoleBadge.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
2-
<div class="inline-block align-middle mb-1" v-if="rule">
2+
<div class="inline-block align-middle mb-1" v-if="role">
33
<span
4-
v-if="rule === 'official'"
4+
v-if="role === 'official'"
55
class="inline-flex items-center rounded-md px-1.5 pb-0.5 pt-0.75 align-middle text-xs font-semibold transition-colors bg-[#c9353f1a] c-[#d8111b] ml-0.5 scale-80"
66
>
77
{{ message.forum.topic.official }}
88
</span>
99
<span
10-
v-if="rule === 'author'"
10+
v-if="role === 'author'"
1111
class="inline-flex items-center rounded-md px-1.5 pb-0.5 pt-0.75 align-middle text-xs font-semibold transition-colors bg-[#2c71ff1a] c-[#0056e3] ml-0.5 scale-80"
1212
>
1313
{{ message.forum.topic.author }}
@@ -29,12 +29,12 @@ let { authorId = null, type = null } = defineProps<{
2929
authorId?: string | number | null
3030
}>()
3131
32-
const userRule = computed(() => {
32+
const userRole = computed(() => {
3333
if (!authorId) return null
3434
if (isAuthor(authorId).value) return 'author'
3535
if (isOfficial(authorId).value) return 'official'
3636
return null
3737
})
3838
39-
const rule = computed(() => type || userRule.value)
39+
const role = computed(() => type || userRole.value)
4040
</script>

src/components/forum/ForumTopic.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
>
1515
<p>
1616
{{ title }}
17-
<ForumRoleBadge :type="rule" />
17+
<ForumRoleBadge :type="role" />
1818
</p>
1919
<p class="mr-2" v-if="topic.type">
2020
<span
@@ -130,7 +130,7 @@ const renderText = computed(() => {
130130
if (isAnn.value) return contentSanitized
131131
return contentSanitized.slice(0, isExpanded.value ? undefined : 180)
132132
})
133-
const rule = computed(() => (isOfficial(author.id).value ? 'official' : null))
133+
const role = computed(() => (isOfficial(author.id).value ? 'official' : null))
134134
const hasOverflow = computed(
135135
() => topic.contentRaw.replace(/!\[.*?\]\(.*?\)/g, '').length > 180,
136136
)

src/components/forum/ForumTopicComment.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="title flex" :class="style[size].header">
1818
<p class="font-size-3.5">{{ author.username }}</p>
1919

20-
<ForumRoleBadge :type="rule" />
20+
<ForumRoleBadge :type="role" />
2121
</div>
2222

2323
<article
@@ -57,6 +57,7 @@ import { computed } from 'vue'
5757
import ForumRoleBadge from './ForumRoleBadge.vue'
5858
import { Image } from '@/components/ui/image'
5959
import ForumCommentMeta from './ForumCommentMeta.vue'
60+
import { useRuleChecks } from '~/composables/useRuleChecks'
6061
6162
const {
6263
size = 'normal',
@@ -77,7 +78,13 @@ const {
7778
commentClickHandler: Function
7879
}>()
7980
80-
const rule = computed(() => (topicAuthorId === author.id ? 'author' : null))
81+
const { isOfficial } = useRuleChecks()
82+
83+
const role = computed(() => {
84+
if (topicAuthorId === author.id) return 'author'
85+
if (isOfficial(author.id).value) return 'official'
86+
return null
87+
})
8188
8289
const style = {
8390
small: {

0 commit comments

Comments
 (0)