feat: add content review flow

This commit is contained in:
2026-01-15 11:10:43 +08:00
parent 37da8256fa
commit 37325ab1b4
10 changed files with 422 additions and 4 deletions

View File

@@ -109,5 +109,26 @@ export const ContentService = {
method: 'PATCH',
body: { status }
});
},
async reviewContent(contentID, { action, reason } = {}) {
if (!contentID) throw new Error('contentID is required');
return requestJson(`/super/v1/contents/${contentID}/review`, {
method: 'POST',
body: {
action,
reason
}
});
},
async batchReviewContents({ content_ids, action, reason } = {}) {
if (!Array.isArray(content_ids) || content_ids.length === 0) throw new Error('content_ids is required');
return requestJson('/super/v1/contents/review/batch', {
method: 'POST',
body: {
content_ids,
action,
reason
}
});
}
};

View File

@@ -32,6 +32,17 @@ const priceAmountMin = ref(null);
const priceAmountMax = ref(null);
const sortField = ref('id');
const sortOrder = ref(-1);
const selectedContents = ref([]);
const reviewDialogVisible = ref(false);
const reviewSubmitting = ref(false);
const reviewAction = ref('approve');
const reviewReason = ref('');
const reviewTargetIDs = ref([]);
const reviewActionOptions = [
{ label: '通过', value: 'approve' },
{ label: '驳回', value: 'reject' }
];
const statusOptions = [
{ label: '全部', value: '' },
@@ -67,6 +78,11 @@ function parseDate(value) {
return date;
}
function getContentID(row) {
const id = Number(row?.content?.id ?? row?.id ?? 0);
return Number.isFinite(id) ? id : 0;
}
function formatDate(value) {
if (!value) return '-';
if (String(value).startsWith('0001-01-01')) return '-';
@@ -159,6 +175,9 @@ function getContentVisibilitySeverity(value) {
}
}
const selectedCount = computed(() => selectedContents.value.length);
const reviewTargetCount = computed(() => reviewTargetIDs.value.length);
async function loadContents() {
loading.value = true;
try {
@@ -184,6 +203,7 @@ async function loadContents() {
sortOrder: sortOrder.value
});
contents.value = (result.items || []).map((item) => ({ ...item, __key: item?.content?.id ?? undefined }));
selectedContents.value = [];
totalRecords.value = result.total;
} catch (error) {
toast.add({ severity: 'error', summary: '加载失败', detail: error?.message || '无法加载内容列表', life: 4000 });
@@ -192,6 +212,60 @@ async function loadContents() {
}
}
function openReviewDialog(row) {
const id = getContentID(row);
if (!id) return;
reviewTargetIDs.value = [id];
reviewAction.value = 'approve';
reviewReason.value = '';
reviewDialogVisible.value = true;
}
function openBatchReviewDialog(action) {
if (!selectedContents.value.length) {
toast.add({ severity: 'warn', summary: '请先选择内容', detail: '至少选择 1 条内容进行审核', life: 3000 });
return;
}
const ids = selectedContents.value.map((row) => getContentID(row)).filter((id) => id > 0);
if (!ids.length) {
toast.add({ severity: 'warn', summary: '选择无效', detail: '未识别到可审核的内容', life: 3000 });
return;
}
reviewTargetIDs.value = ids;
reviewAction.value = action || 'approve';
reviewReason.value = '';
reviewDialogVisible.value = true;
}
async function confirmReview() {
const action = reviewAction.value;
const reason = reviewReason.value.trim();
const ids = reviewTargetIDs.value.filter((id) => id > 0);
if (!ids.length) return;
if (action === 'reject' && !reason) {
toast.add({ severity: 'warn', summary: '请输入原因', detail: '驳回时需填写原因', life: 3000 });
return;
}
reviewSubmitting.value = true;
try {
if (ids.length === 1) {
await ContentService.reviewContent(ids[0], { action, reason });
} else {
await ContentService.batchReviewContents({ content_ids: ids, action, reason });
}
toast.add({ severity: 'success', summary: '审核成功', detail: `已处理 ${ids.length} 条内容`, life: 3000 });
reviewDialogVisible.value = false;
reviewTargetIDs.value = [];
selectedContents.value = [];
await loadContents();
} catch (error) {
toast.add({ severity: 'error', summary: '审核失败', detail: error?.message || '无法完成审核', life: 4000 });
} finally {
reviewSubmitting.value = false;
}
}
function onSearch() {
page.value = 1;
loadContents();
@@ -265,7 +339,12 @@ watch(
<h4 class="m-0">内容列表</h4>
<span class="text-muted-color">平台侧汇总跨租户</span>
</div>
<Button label="刷新" icon="pi pi-refresh" severity="secondary" @click="loadContents" :disabled="loading" />
<div class="flex items-center gap-2">
<span class="text-sm text-muted-color">已选 {{ selectedCount }} </span>
<Button label="批量通过" icon="pi pi-check" severity="success" :disabled="selectedCount === 0" @click="openBatchReviewDialog('approve')" />
<Button label="批量驳回" icon="pi pi-times" severity="danger" :disabled="selectedCount === 0" @click="openBatchReviewDialog('reject')" />
<Button label="刷新" icon="pi pi-refresh" severity="secondary" @click="loadContents" :disabled="loading" />
</div>
</div>
<div class="flex flex-col gap-4">
@@ -320,6 +399,7 @@ watch(
<DataTable
:value="contents"
dataKey="__key"
v-model:selection="selectedContents"
:loading="loading"
lazy
:paginator="true"
@@ -338,6 +418,7 @@ watch(
scrollHeight="640px"
responsiveLayout="scroll"
>
<Column selectionMode="multiple" headerStyle="width: 3rem" />
<Column header="ID" sortable sortField="id" style="min-width: 8rem">
<template #body="{ data }">
<span class="text-muted-color">{{ data?.content?.id ?? '-' }}</span>
@@ -406,7 +487,8 @@ watch(
</Column>
<Column header="操作" style="min-width: 10rem">
<template #body="{ data }">
<Button v-if="data?.content?.status === 'published'" label="下架" icon="pi pi-ban" severity="danger" text size="small" class="p-0" @click="openUnpublishDialog(data)" />
<Button v-if="data?.content?.status === 'reviewing'" label="审核" icon="pi pi-check-square" text size="small" class="p-0 mr-3" @click="openReviewDialog(data)" />
<Button v-else-if="data?.content?.status === 'published'" label="下架" icon="pi pi-ban" severity="danger" text size="small" class="p-0" @click="openUnpublishDialog(data)" />
<span v-else class="text-muted-color">-</span>
</template>
</Column>
@@ -431,4 +513,28 @@ watch(
<Button label="确认下架" icon="pi pi-ban" severity="danger" @click="confirmUnpublish" :loading="unpublishLoading" />
</template>
</Dialog>
<Dialog v-model:visible="reviewDialogVisible" :modal="true" :style="{ width: '520px' }">
<template #header>
<div class="flex items-center gap-2">
<span class="font-medium">内容审核</span>
<span class="text-muted-color"> {{ reviewTargetCount }} </span>
</div>
</template>
<div class="flex flex-col gap-4">
<div>
<label class="block font-medium mb-2">审核动作</label>
<Select v-model="reviewAction" :options="reviewActionOptions" optionLabel="label" optionValue="value" class="w-full" />
</div>
<div>
<label class="block font-medium mb-2">审核说明</label>
<InputText v-model="reviewReason" placeholder="驳回时建议填写原因" class="w-full" />
</div>
<div class="text-sm text-muted-color">审核后会同步通知作者</div>
</div>
<template #footer>
<Button label="取消" icon="pi pi-times" text @click="reviewDialogVisible = false" :disabled="reviewSubmitting" />
<Button label="确认审核" icon="pi pi-check" severity="success" @click="confirmReview" :loading="reviewSubmitting" :disabled="reviewSubmitting || (reviewAction === 'reject' && !reviewReason.trim())" />
</template>
</Dialog>
</template>