Skip to content

Commit 46d9459

Browse files
committed
fix(forum): 修复反馈论坛角色徽章显示异常的问题
1 parent b48062c commit 46d9459

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
<script setup lang="ts">
1919
import { useLocalized } from '@/hooks/useLocalized'
20-
import { isOfficial } from '~/composables/isOfficial'
20+
import { useRuleChecks } from '~/composables/useRuleChecks'
2121
import { isAuthor } from '~/composables/isAuthor'
2222
import { computed } from 'vue'
2323
2424
const { message } = useLocalized()
25+
const { isOfficial } = useRuleChecks()
2526
2627
let { authorId = null, type = null } = defineProps<{
2728
type?: 'official' | 'author' | null

src/components/forum/ForumTopic.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
>
1515
<p>
1616
{{ title }}
17-
<ForumRuleBadge :type="rule" />
17+
<ForumRoleBadge :type="rule" />
1818
</p>
1919
<p class="mr-2" v-if="topic.type">
2020
<span
@@ -95,7 +95,7 @@
9595

9696
<script setup lang="ts">
9797
import { computed } from 'vue'
98-
import ForumRuleBadge from './ForumRuleBadge.vue'
98+
import ForumRoleBadge from './ForumRoleBadge.vue'
9999
import ForumTagList from './ForumTagList.vue'
100100
import ForumTopicComment from './ForumTopicComment.vue'
101101
import ForumTopicMeta from './ForumTopicMeta.vue'
@@ -106,7 +106,7 @@ import { useToggle } from '@vueuse/core'
106106
import { useLocalized } from '@/hooks/useLocalized'
107107
import { sessionCacheRedirect } from '~/composables/sessionCacheRedirect'
108108
import { sanitizeMarkdown } from '~/composables/sanitizeMarkdown'
109-
import { isOfficial } from '~/composables/isOfficial'
109+
import { useRuleChecks } from '~/composables/useRuleChecks'
110110
111111
import type ForumAPI from '@/apis/forum/api'
112112
@@ -123,6 +123,7 @@ const topicTypeMap = getTopicTypeMap()
123123
const { message } = useLocalized()
124124
125125
const [isExpanded, toggleExpand] = useToggle()
126+
const { isOfficial } = useRuleChecks()
126127
127128
const renderText = computed(() => {
128129
const contentSanitized = sanitizeMarkdown(topic.contentRaw)

src/components/forum/ForumTopicComment.vue

Lines changed: 6 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-
<ForumRuleBadge :author-id="author.id" />
20+
<ForumRoleBadge :type="rule" />
2121
</div>
2222

2323
<article
@@ -54,13 +54,15 @@
5454
<script setup lang="ts">
5555
import type ForumAPI from '@/apis/forum/api'
5656
import { computed } from 'vue'
57-
import ForumRuleBadge from './ForumRuleBadge.vue'
57+
import ForumRoleBadge from './ForumRoleBadge.vue'
5858
import { Image } from '@/components/ui/image'
5959
import ForumCommentMeta from './ForumCommentMeta.vue'
6060
6161
const {
6262
size = 'normal',
6363
repo = 'Feedback',
64+
topicAuthorId,
65+
author,
6466
...props
6567
} = defineProps<{
6668
repo: string
@@ -75,6 +77,8 @@ const {
7577
commentClickHandler: Function
7678
}>()
7779
80+
const rule = computed(() => (topicAuthorId === author.id ? 'author' : null))
81+
7882
const style = {
7983
small: {
8084
container: 'py-3',

src/components/forum/topic/ForumTopicPage.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<p class="mx-2 font-size-3.5 font-[var(--vp-font-family-subtitle)]">
2020
{{ data?.user.username }}
2121
</p>
22-
<ForumRuleBadge :author-id="data.user.id" />
22+
<ForumRoleBadge :author-id="data.user.id" />
2323

2424
<span class="color-[--vp-c-text-3]">·</span>
2525

@@ -85,7 +85,7 @@ import { computed, watchEffect } from 'vue'
8585
import { useRequest } from 'vue-request'
8686
import { toast } from 'vue-sonner'
8787
import ForumAside from '../ForumAside.vue'
88-
import ForumRuleBadge from '../ForumRuleBadge.vue'
88+
import ForumRoleBadge from '../ForumRoleBadge.vue'
8989
import ForumTagList from '../ForumTagList.vue'
9090
import { getTopicNumber, setPageTitle } from '../utils'
9191
import ForumCommentArea from '../ForumCommentArea.vue'

src/composables/isOfficial.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/composables/useRuleChecks.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const userRolesMap = {
2020
type Role = keyof typeof rolesPermissions
2121
type Permission = (typeof rolesPermissions)[Role][number]
2222

23-
export const useRuleChecks = (inputId?: string | number) => {
23+
export const useRuleChecks = (inputId: string | number = '') => {
2424
const userInfo = useUserInfoStore()
2525
const id = computed(() => userInfo.info?.id || 0)
2626

@@ -31,7 +31,7 @@ export const useRuleChecks = (inputId?: string | number) => {
3131
})
3232

3333
const userRoles = computed((): Array<Role> => {
34-
return id.value === String(userInfo.info?.id)
34+
return String(inputId) === String(userInfo.info?.id)
3535
? [...staticRoles.value, 'author']
3636
: staticRoles.value
3737
})
@@ -62,10 +62,21 @@ export const useRuleChecks = (inputId?: string | number) => {
6262
const hasAllRoles = (...roles: Role[]) =>
6363
computed(() => roles.every((role) => userRoles.value.includes(role)))
6464

65+
const isOfficial = (userId: string | number) => {
66+
return computed(() => {
67+
userId ??= id.value
68+
return (
69+
userRolesMap.feedbackMember.has(Number(userId)) ||
70+
userRolesMap.teamMember.has(Number(userId))
71+
)
72+
})
73+
}
74+
6575
return {
6676
hasAnyPermissions,
6777
hasAllPermissions,
6878
hasAnyRoles,
6979
hasAllRoles,
80+
isOfficial,
7081
}
7182
}

0 commit comments

Comments
 (0)