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:
@@ -33,7 +33,7 @@
|
||||
- 订单详情(含 items / snapshot 展示)
|
||||
- 平台侧退款(支持强制退款,记录操作人)
|
||||
3) **租户管理增强**
|
||||
- 租户详情页(基本信息、过期续期、状态变更、管理员/成员管理)
|
||||
- 租户详情页(基本信息、过期续期、状态变更、管理员/成员/内容管理)
|
||||
4) **用户管理增强**
|
||||
- 用户详情页(角色、状态、余额/冻结、加入/拥有的租户、操作记录)
|
||||
- 角色授予/回收(`super_admin`)
|
||||
|
||||
4
frontend/superadmin/dist/index.html
vendored
4
frontend/superadmin/dist/index.html
vendored
@@ -7,8 +7,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sakai Vue</title>
|
||||
<link href="https://fonts.cdnfonts.com/css/lato" rel="stylesheet">
|
||||
<script type="module" crossorigin src="./assets/index-0nqd4PcY.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="./assets/index-DMfJH3M_.css">
|
||||
<script type="module" crossorigin src="./assets/index-PWlTeOhw.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="./assets/index-B8J4fGz4.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
70
frontend/superadmin/src/service/ContentService.js
Normal file
70
frontend/superadmin/src/service/ContentService.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import { requestJson } from './apiClient';
|
||||
|
||||
function normalizeItems(items) {
|
||||
if (Array.isArray(items)) return items;
|
||||
if (items && typeof items === 'object') return [items];
|
||||
return [];
|
||||
}
|
||||
|
||||
export const ContentService = {
|
||||
async listTenantContents(
|
||||
tenantID,
|
||||
{
|
||||
page,
|
||||
limit,
|
||||
keyword,
|
||||
status,
|
||||
visibility,
|
||||
user_id,
|
||||
published_at_from,
|
||||
published_at_to,
|
||||
created_at_from,
|
||||
created_at_to,
|
||||
sortField,
|
||||
sortOrder
|
||||
} = {}
|
||||
) {
|
||||
if (!tenantID) throw new Error('tenantID is required');
|
||||
|
||||
const iso = (d) => {
|
||||
if (!d) return undefined;
|
||||
const date = d instanceof Date ? d : new Date(d);
|
||||
if (Number.isNaN(date.getTime())) return undefined;
|
||||
return date.toISOString();
|
||||
};
|
||||
|
||||
const query = {
|
||||
page,
|
||||
limit,
|
||||
keyword,
|
||||
status,
|
||||
visibility,
|
||||
user_id,
|
||||
published_at_from: iso(published_at_from),
|
||||
published_at_to: iso(published_at_to),
|
||||
created_at_from: iso(created_at_from),
|
||||
created_at_to: iso(created_at_to)
|
||||
};
|
||||
if (sortField && sortOrder) {
|
||||
if (sortOrder === 1) query.asc = sortField;
|
||||
if (sortOrder === -1) query.desc = sortField;
|
||||
}
|
||||
|
||||
const data = await requestJson(`/super/v1/tenants/${tenantID}/contents`, { query });
|
||||
return {
|
||||
page: data?.page ?? page ?? 1,
|
||||
limit: data?.limit ?? limit ?? 10,
|
||||
total: data?.total ?? 0,
|
||||
items: normalizeItems(data?.items)
|
||||
};
|
||||
}
|
||||
,
|
||||
async updateTenantContentStatus(tenantID, contentID, { status } = {}) {
|
||||
if (!tenantID) throw new Error('tenantID is required');
|
||||
if (!contentID) throw new Error('contentID is required');
|
||||
return requestJson(`/super/v1/tenants/${tenantID}/contents/${contentID}/status`, {
|
||||
method: 'PATCH',
|
||||
body: { status }
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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