diff --git a/src/store/useForumStore.ts b/src/store/useForumStore.ts index 489bf2f..59d5f6e 100644 --- a/src/store/useForumStore.ts +++ b/src/store/useForumStore.ts @@ -397,7 +397,7 @@ export const useForumStore = defineStore('forum', () => { async function ConfirmApply(owner: number, id: number) { try { isLoading.value = true - const data = await QueryGetAPI(FORUM_API_URL + 'manage/confirm-apply', { owner: owner, id: id }) + const data = await QueryGetAPI(FORUM_API_URL + 'manage/confirm-apply', { forum: owner, id: id }) if (data.code == 200) { message?.success('已通过申请') return true diff --git a/src/views/manage/ForumManage.vue b/src/views/manage/ForumManage.vue index 786d5b8..ac93886 100644 --- a/src/views/manage/ForumManage.vue +++ b/src/views/manage/ForumManage.vue @@ -26,7 +26,7 @@ import { NTime, useMessage, } from 'naive-ui' -import { h, ref } from 'vue' +import { h, onMounted, ref } from 'vue' import { ForumModel, ForumUserLevels, ForumUserModel } from '@/api/models/forum' import { FORUM_API_URL } from '@/data/constants' // @ts-ignore @@ -40,7 +40,7 @@ const message = useMessage() const managedForums = ref((await useForum.GetManagedForums()) ?? []) const currentForum = ref((await useForum.GetForumInfo(accountInfo.value.id)) ?? ({} as ForumModel)) -const selectedForum = ref(accountInfo.value.id) +const selectedForum = ref() const readedAgreement = ref(false) const showAgreement = ref(false) @@ -106,6 +106,7 @@ async function createForum() { } } async function SwitchForum(owner: number) { + selectedForum.value = owner currentForum.value = (await useForum.GetForumInfo(owner)) ?? ({} as ForumModel) } async function refreshForumInfo() { @@ -152,17 +153,32 @@ const memberColumns: DataTableColumns = [ title: '操作', key: 'action', render(row) { - return h( - NButton, - { - text: true, - type: 'success', - onClick: () => { - banUser(row.id) + return h(NFlex, {}, () => [ + h( + NButton, + { + text: true, + type: 'error', + onClick: () => { + banUser(row.id) + }, }, - }, - { default: () => '封禁' }, - ) + { default: () => '封禁' }, + ), + currentForum.value.owner.id == accountInfo.value.id + ? h( + NButton, + { + text: true, + type: 'success', + onClick: () => { + addAdmin(row.id) + }, + }, + { default: () => '设为管理员' }, + ) + : null, + ]) }, }, ] @@ -190,30 +206,33 @@ const adminColumns: DataTableColumns = [ { title: '操作', key: 'action', + disabled: () => currentForum.value.owner.id != accountInfo.value.id, render(row) { - return h( - NButton, - { - text: true, - type: 'error', - onClick: () => { - removeAdmin(row.id) - }, - }, - { default: () => ' 取消管理员' }, - ) + return currentForum.value.owner.id == accountInfo.value.id + ? h( + NButton, + { + text: true, + type: 'error', + onClick: () => { + removeAdmin(row.id) + }, + }, + { default: () => ' 取消管理员' }, + ) + : null }, }, ] -async function addAdmin() { +async function addAdmin(id: number) { try { const data = await QueryGetAPI(FORUM_API_URL + 'manage/add-admin', { forum: currentForum.value.owner.id, - id: currentAdminInfo.value?.id, + id: id, }) if (data.code == 200) { - message.success('已添加 ' + currentAdminInfo.value?.name + ' 为管理员') + message.success('已设置为管理员') refreshForumInfo() addAdminName.value = '' showAddAdminModal.value = false @@ -244,7 +263,7 @@ async function banUser(id: number) { try { const data = await QueryGetAPI(FORUM_API_URL + 'manage/ban', { forum: currentForum.value.owner.id, - id: currentBanUserInfo.value?.id, + id: id, }) if (data.code == 200) { message.success('已封禁用户') @@ -283,9 +302,36 @@ async function updateForumSettings() { message.error('修改失败: ' + err) } } + +onMounted(() => { + if (currentForum.value.name) { + selectedForum.value = currentForum.value.owner.id + } +})