feat: add tenant content management features for superadmin
- Implemented API endpoints for listing tenant contents and updating content status.
- Added Swagger documentation for new endpoints:
- GET /super/v1/tenants/{tenantID}/contents
- PATCH /super/v1/tenants/{tenantID}/contents/{contentID}/status
- Created DTOs for content item and status update form.
- Enhanced frontend to support content management in the tenant detail page.
- Added search and filter functionalities for tenant contents.
- Implemented unpublish functionality with confirmation dialog.
- Updated service layer to handle new content management logic.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script setup>
|
||||
import SearchField from '@/components/SearchField.vue';
|
||||
import SearchPanel from '@/components/SearchPanel.vue';
|
||||
import { ContentService } from '@/service/ContentService';
|
||||
import { OrderService } from '@/service/OrderService';
|
||||
import { TenantService } from '@/service/TenantService';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
@@ -57,6 +58,34 @@ function getOrderStatusSeverity(value) {
|
||||
}
|
||||
}
|
||||
|
||||
function getContentStatusSeverity(value) {
|
||||
switch (value) {
|
||||
case 'published':
|
||||
return 'success';
|
||||
case 'reviewing':
|
||||
return 'warn';
|
||||
case 'blocked':
|
||||
return 'danger';
|
||||
case 'draft':
|
||||
case 'unpublished':
|
||||
default:
|
||||
return 'secondary';
|
||||
}
|
||||
}
|
||||
|
||||
function getContentVisibilitySeverity(value) {
|
||||
switch (value) {
|
||||
case 'public':
|
||||
return 'info';
|
||||
case 'tenant_only':
|
||||
return 'warn';
|
||||
case 'private':
|
||||
return 'secondary';
|
||||
default:
|
||||
return 'secondary';
|
||||
}
|
||||
}
|
||||
|
||||
async function loadTenant() {
|
||||
const id = tenantID.value;
|
||||
if (!id || Number.isNaN(id)) return;
|
||||
@@ -123,6 +152,33 @@ const durationOptions = [
|
||||
{ label: '365 天', value: 365 }
|
||||
];
|
||||
|
||||
const unpublishDialogVisible = ref(false);
|
||||
const unpublishLoading = ref(false);
|
||||
const unpublishItem = ref(null);
|
||||
|
||||
function openUnpublishDialog(row) {
|
||||
unpublishItem.value = row;
|
||||
unpublishDialogVisible.value = true;
|
||||
}
|
||||
|
||||
async function confirmUnpublish() {
|
||||
const id = tenantID.value;
|
||||
const contentID = unpublishItem.value?.content?.id;
|
||||
if (!id || !contentID) return;
|
||||
|
||||
unpublishLoading.value = true;
|
||||
try {
|
||||
await ContentService.updateTenantContentStatus(id, contentID, { status: 'unpublished' });
|
||||
toast.add({ severity: 'success', summary: '下架成功', detail: `ContentID: ${contentID}`, life: 3000 });
|
||||
unpublishDialogVisible.value = false;
|
||||
await loadContents();
|
||||
} catch (error) {
|
||||
toast.add({ severity: 'error', summary: '下架失败', detail: error?.message || '无法下架内容', life: 4000 });
|
||||
} finally {
|
||||
unpublishLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function confirmRenew() {
|
||||
const id = tenantID.value;
|
||||
if (!id) return;
|
||||
@@ -201,6 +257,100 @@ function onTenantUsersPageChange(event) {
|
||||
loadTenantUsers();
|
||||
}
|
||||
|
||||
const contentsLoading = ref(false);
|
||||
const contents = ref([]);
|
||||
const contentsTotal = ref(0);
|
||||
const contentsPage = ref(1);
|
||||
const contentsRows = ref(10);
|
||||
const contentsKeyword = ref('');
|
||||
const contentsStatus = ref('published');
|
||||
const contentsVisibility = ref('');
|
||||
const contentsOwnerUserID = ref(null);
|
||||
const contentsPublishedAtFrom = ref(null);
|
||||
const contentsPublishedAtTo = ref(null);
|
||||
const contentsCreatedAtFrom = ref(null);
|
||||
const contentsCreatedAtTo = ref(null);
|
||||
const contentsSortField = ref('id');
|
||||
const contentsSortOrder = ref(-1);
|
||||
|
||||
const contentStatusOptions = [
|
||||
{ label: '全部', value: '' },
|
||||
{ label: 'draft', value: 'draft' },
|
||||
{ label: 'reviewing', value: 'reviewing' },
|
||||
{ label: 'published', value: 'published' },
|
||||
{ label: 'unpublished', value: 'unpublished' },
|
||||
{ label: 'blocked', value: 'blocked' }
|
||||
];
|
||||
|
||||
const contentVisibilityOptions = [
|
||||
{ label: '全部', value: '' },
|
||||
{ label: 'public', value: 'public' },
|
||||
{ label: 'tenant_only', value: 'tenant_only' },
|
||||
{ label: 'private', value: 'private' }
|
||||
];
|
||||
|
||||
async function loadContents() {
|
||||
const id = tenantID.value;
|
||||
if (!id) return;
|
||||
|
||||
contentsLoading.value = true;
|
||||
try {
|
||||
const result = await ContentService.listTenantContents(id, {
|
||||
page: contentsPage.value,
|
||||
limit: contentsRows.value,
|
||||
keyword: contentsKeyword.value,
|
||||
status: contentsStatus.value || undefined,
|
||||
visibility: contentsVisibility.value || undefined,
|
||||
user_id: contentsOwnerUserID.value || undefined,
|
||||
published_at_from: contentsPublishedAtFrom.value || undefined,
|
||||
published_at_to: contentsPublishedAtTo.value || undefined,
|
||||
created_at_from: contentsCreatedAtFrom.value || undefined,
|
||||
created_at_to: contentsCreatedAtTo.value || undefined,
|
||||
sortField: contentsSortField.value,
|
||||
sortOrder: contentsSortOrder.value
|
||||
});
|
||||
contents.value = (result.items || []).map((item) => ({ ...item, __key: item?.content?.id ?? undefined }));
|
||||
contentsTotal.value = result.total;
|
||||
} catch (error) {
|
||||
toast.add({ severity: 'error', summary: '加载失败', detail: error?.message || '无法加载租户内容列表', life: 4000 });
|
||||
} finally {
|
||||
contentsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onContentsSearch() {
|
||||
contentsPage.value = 1;
|
||||
loadContents();
|
||||
}
|
||||
|
||||
function onContentsReset() {
|
||||
contentsKeyword.value = '';
|
||||
contentsStatus.value = 'published';
|
||||
contentsVisibility.value = '';
|
||||
contentsOwnerUserID.value = null;
|
||||
contentsPublishedAtFrom.value = null;
|
||||
contentsPublishedAtTo.value = null;
|
||||
contentsCreatedAtFrom.value = null;
|
||||
contentsCreatedAtTo.value = null;
|
||||
contentsSortField.value = 'id';
|
||||
contentsSortOrder.value = -1;
|
||||
contentsPage.value = 1;
|
||||
contentsRows.value = 10;
|
||||
loadContents();
|
||||
}
|
||||
|
||||
function onContentsPage(event) {
|
||||
contentsPage.value = (event.page ?? 0) + 1;
|
||||
contentsRows.value = event.rows ?? contentsRows.value;
|
||||
loadContents();
|
||||
}
|
||||
|
||||
function onContentsSort(event) {
|
||||
contentsSortField.value = event.sortField ?? contentsSortField.value;
|
||||
contentsSortOrder.value = event.sortOrder ?? contentsSortOrder.value;
|
||||
loadContents();
|
||||
}
|
||||
|
||||
const ordersLoading = ref(false);
|
||||
const orders = ref([]);
|
||||
const ordersTotal = ref(0);
|
||||
@@ -295,10 +445,13 @@ watch(
|
||||
() => {
|
||||
tenantUsersPage.value = 1;
|
||||
tenantUsersRows.value = 10;
|
||||
contentsPage.value = 1;
|
||||
contentsRows.value = 10;
|
||||
ordersPage.value = 1;
|
||||
ordersRows.value = 10;
|
||||
loadTenant();
|
||||
loadTenantUsers();
|
||||
loadContents();
|
||||
loadOrders();
|
||||
},
|
||||
{ immediate: true }
|
||||
@@ -373,6 +526,7 @@ onMounted(() => {
|
||||
<Tabs v-model:value="tabValue" value="users">
|
||||
<TabList>
|
||||
<Tab value="users">成员</Tab>
|
||||
<Tab value="contents">内容</Tab>
|
||||
<Tab value="orders">订单</Tab>
|
||||
</TabList>
|
||||
<TabPanels>
|
||||
@@ -473,6 +627,138 @@ onMounted(() => {
|
||||
</DataTable>
|
||||
</div>
|
||||
</TabPanel>
|
||||
<TabPanel value="contents">
|
||||
<div class="flex flex-col gap-4">
|
||||
<SearchPanel :loading="contentsLoading" @search="onContentsSearch" @reset="onContentsReset">
|
||||
<SearchField label="Keyword">
|
||||
<IconField>
|
||||
<InputIcon>
|
||||
<i class="pi pi-search" />
|
||||
</InputIcon>
|
||||
<InputText v-model="contentsKeyword" placeholder="标题关键词" class="w-full" @keyup.enter="onContentsSearch" />
|
||||
</IconField>
|
||||
</SearchField>
|
||||
<SearchField label="状态">
|
||||
<Select v-model="contentsStatus" :options="contentStatusOptions" optionLabel="label" optionValue="value" placeholder="请选择" class="w-full" />
|
||||
</SearchField>
|
||||
<SearchField label="可见性">
|
||||
<Select
|
||||
v-model="contentsVisibility"
|
||||
:options="contentVisibilityOptions"
|
||||
optionLabel="label"
|
||||
optionValue="value"
|
||||
placeholder="请选择"
|
||||
class="w-full"
|
||||
/>
|
||||
</SearchField>
|
||||
<SearchField label="OwnerUserID">
|
||||
<InputNumber v-model="contentsOwnerUserID" :min="1" placeholder="精确匹配" class="w-full" />
|
||||
</SearchField>
|
||||
<SearchField label="发布时间 From">
|
||||
<DatePicker v-model="contentsPublishedAtFrom" showIcon showButtonBar placeholder="开始时间" class="w-full" />
|
||||
</SearchField>
|
||||
<SearchField label="发布时间 To">
|
||||
<DatePicker v-model="contentsPublishedAtTo" showIcon showButtonBar placeholder="结束时间" class="w-full" />
|
||||
</SearchField>
|
||||
<SearchField label="创建时间 From">
|
||||
<DatePicker v-model="contentsCreatedAtFrom" showIcon showButtonBar placeholder="开始时间" class="w-full" />
|
||||
</SearchField>
|
||||
<SearchField label="创建时间 To">
|
||||
<DatePicker v-model="contentsCreatedAtTo" showIcon showButtonBar placeholder="结束时间" class="w-full" />
|
||||
</SearchField>
|
||||
</SearchPanel>
|
||||
|
||||
<DataTable
|
||||
:value="contents"
|
||||
dataKey="__key"
|
||||
:loading="contentsLoading"
|
||||
lazy
|
||||
:paginator="true"
|
||||
:rows="contentsRows"
|
||||
:totalRecords="contentsTotal"
|
||||
:first="(contentsPage - 1) * contentsRows"
|
||||
:rowsPerPageOptions="[10, 20, 50, 100]"
|
||||
sortMode="single"
|
||||
:sortField="contentsSortField"
|
||||
:sortOrder="contentsSortOrder"
|
||||
@page="onContentsPage"
|
||||
@sort="onContentsSort"
|
||||
currentPageReportTemplate="显示第 {first} - {last} 条,共 {totalRecords} 条"
|
||||
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||
scrollable
|
||||
scrollHeight="520px"
|
||||
responsiveLayout="scroll"
|
||||
>
|
||||
<Column header="ID" sortable sortField="id" style="min-width: 8rem">
|
||||
<template #body="{ data }">
|
||||
<span class="text-muted-color">{{ data?.content?.id ?? '-' }}</span>
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="标题" sortable sortField="title" style="min-width: 22rem">
|
||||
<template #body="{ data }">
|
||||
<div class="flex flex-col">
|
||||
<span class="font-medium truncate max-w-[520px]">{{ data?.content?.title ?? '-' }}</span>
|
||||
<span class="text-muted-color">ContentID: {{ data?.content?.id ?? '-' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="Owner" sortable sortField="user_id" style="min-width: 14rem">
|
||||
<template #body="{ data }">
|
||||
<div class="flex flex-col">
|
||||
<span class="font-medium">{{ data?.owner?.username ?? '-' }}</span>
|
||||
<span class="text-muted-color">ID: {{ data?.content?.user_id ?? '-' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="状态" sortable sortField="status" style="min-width: 12rem">
|
||||
<template #body="{ data }">
|
||||
<Tag :value="data?.status_description || data?.content?.status || '-'" :severity="getContentStatusSeverity(data?.content?.status)" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="可见性" sortable sortField="visibility" style="min-width: 12rem">
|
||||
<template #body="{ data }">
|
||||
<Tag
|
||||
:value="data?.visibility_description || data?.content?.visibility || '-'"
|
||||
:severity="getContentVisibilitySeverity(data?.content?.visibility)"
|
||||
/>
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="价格" style="min-width: 10rem">
|
||||
<template #body="{ data }">
|
||||
<span v-if="data?.price && (data.price.price_amount ?? null) !== null">
|
||||
{{ Number(data.price.price_amount) === 0 ? '免费' : formatCny(data.price.price_amount) }}
|
||||
</span>
|
||||
<span v-else class="text-muted-color">-</span>
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="发布时间" sortable sortField="published_at" style="min-width: 14rem">
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data?.content?.published_at) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column header="创建时间" sortable sortField="created_at" style="min-width: 14rem">
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data?.content?.created_at) }}
|
||||
</template>
|
||||
</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)"
|
||||
/>
|
||||
<span v-else class="text-muted-color">-</span>
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</TabPanel>
|
||||
<TabPanel value="orders">
|
||||
<div class="flex flex-col gap-4">
|
||||
<SearchPanel :loading="ordersLoading" @search="onOrdersSearch" @reset="onOrdersReset">
|
||||
@@ -606,4 +892,21 @@ onMounted(() => {
|
||||
<Button label="确认" icon="pi pi-check" @click="confirmRenew" :loading="renewing" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<Dialog v-model:visible="unpublishDialogVisible" :modal="true" :style="{ width: '460px' }">
|
||||
<template #header>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-medium">下架内容</span>
|
||||
<span class="text-muted-color truncate max-w-[280px]">{{ unpublishItem?.content?.title ?? '-' }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="text-muted-color">确认将该内容下架?下架后租户端将不可见/不可购买。</div>
|
||||
<div class="text-sm text-muted-color">ContentID: {{ unpublishItem?.content?.id ?? '-' }}</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<Button label="取消" icon="pi pi-times" text @click="unpublishDialogVisible = false" :disabled="unpublishLoading" />
|
||||
<Button label="确认下架" icon="pi pi-ban" severity="danger" @click="confirmUnpublish" :loading="unpublishLoading" />
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user