refactor(menu): show delete/approve options conditionally

This commit is contained in:
Tim
2025-07-11 17:05:41 +08:00
parent cb484fa53a
commit fb8fc66733
2 changed files with 17 additions and 10 deletions

View File

@@ -58,14 +58,14 @@
</template> </template>
<script> <script>
import { ref, watch } from 'vue' import { ref, watch, computed } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import CommentEditor from './CommentEditor.vue' import CommentEditor from './CommentEditor.vue'
import { renderMarkdown } from '../utils/markdown' import { renderMarkdown } from '../utils/markdown'
import TimeManager from '../utils/time' import TimeManager from '../utils/time'
import BaseTimeline from './BaseTimeline.vue' import BaseTimeline from './BaseTimeline.vue'
import { API_BASE_URL, toast } from '../main' import { API_BASE_URL, toast } from '../main'
import { getToken } from '../utils/auth' import { getToken, authState } from '../utils/auth'
import ReactionsGroup from './ReactionsGroup.vue' import ReactionsGroup from './ReactionsGroup.vue'
import DropdownMenu from './DropdownMenu.vue' import DropdownMenu from './DropdownMenu.vue'
const CommentItem = { const CommentItem = {
@@ -101,9 +101,10 @@ const CommentItem = {
const toggleEditor = () => { const toggleEditor = () => {
showEditor.value = !showEditor.value showEditor.value = !showEditor.value
} }
const commentMenuItems = ref([ const isAuthor = computed(() => authState.username === props.comment.userName)
{ text: '删除评论', color: 'red', onClick: () => deleteComment() } const commentMenuItems = computed(() =>
]) isAuthor.value ? [{ text: '删除评论', color: 'red', onClick: () => deleteComment() }] : []
)
const deleteComment = () => { const deleteComment = () => {
} }
const submitReply = async (text) => { const submitReply = async (text) => {

View File

@@ -138,11 +138,17 @@ export default {
const loggedIn = computed(() => authState.loggedIn) const loggedIn = computed(() => authState.loggedIn)
const isAdmin = computed(() => authState.role === 'ADMIN') const isAdmin = computed(() => authState.role === 'ADMIN')
const isAuthor = computed(() => authState.username === author.value.username) const isAuthor = computed(() => authState.username === author.value.username)
const articleMenuItems = [ const articleMenuItems = computed(() => {
{ text: '删除文章', color: 'red', onClick: () => deletePost() }, const items = []
{ text: '通过审核', onClick: () => approvePost() }, if (isAuthor.value) {
{ text: '驳回', color: 'red', onClick: () => rejectPost() } items.push({ text: '删除文章', color: 'red', onClick: () => deletePost() })
] }
if (isAdmin.value && status.value === 'PENDING') {
items.push({ text: '通过审核', onClick: () => approvePost() })
items.push({ text: '驳回', color: 'red', onClick: () => rejectPost() })
}
return items
})
const gatherPostItems = () => { const gatherPostItems = () => {
const items = [] const items = []