refactor: 重构分页逻辑并统一代码风格
1. 新增分页数据处理hook和工具函数,实现分页状态统一管理 2. 替换所有页面的表格分页配置为标准current/page模式 3. 统一项目内字符串引号风格为双引号 4. 调整权限树面板样式和布局代码格式
This commit is contained in:
@@ -55,7 +55,7 @@ function DataPage() {
|
||||
</Card>
|
||||
|
||||
<Card className="section-card" title="短剧数据">
|
||||
<Table rowKey="dramaId" loading={dramas.loading} data={dramas.data.list} pagination={{ total: dramas.data.pagination.total, pageSize: dramas.data.pagination.pageSize }} columns={[
|
||||
<Table rowKey="dramaId" loading={dramas.loading} data={dramas.data.list} pagination={{ current: dramas.data.pagination.page, total: dramas.data.pagination.total, pageSize: dramas.data.pagination.pageSize, onChange: dramas.changePage }} columns={[
|
||||
{ title: '短剧ID', dataIndex: 'dramaId', width: 100 },
|
||||
{ title: '短剧名称', dataIndex: 'title' },
|
||||
{ title: '播放量', dataIndex: 'plays', width: 120 },
|
||||
@@ -68,7 +68,7 @@ function DataPage() {
|
||||
</Card>
|
||||
|
||||
<Card className="section-card" title="剧集数据">
|
||||
<Table rowKey="episodeId" loading={episodes.loading} data={episodes.data.list} pagination={{ total: episodes.data.pagination.total, pageSize: episodes.data.pagination.pageSize }} columns={[
|
||||
<Table rowKey="episodeId" loading={episodes.loading} data={episodes.data.list} pagination={{ current: episodes.data.pagination.page, total: episodes.data.pagination.total, pageSize: episodes.data.pagination.pageSize, onChange: episodes.changePage }} columns={[
|
||||
{ title: '剧集ID', dataIndex: 'episodeId', width: 100 },
|
||||
{ title: '短剧ID', dataIndex: 'dramaId', width: 100 },
|
||||
{ title: '集数', dataIndex: 'episodeNo', width: 90 },
|
||||
@@ -81,7 +81,7 @@ function DataPage() {
|
||||
</Card>
|
||||
|
||||
<Card className="section-card" title="同步记录">
|
||||
<Table rowKey="id" loading={jobs.loading} data={jobs.data.list} pagination={{ total: jobs.data.pagination.total, pageSize: jobs.data.pagination.pageSize }} columns={[
|
||||
<Table rowKey="id" loading={jobs.loading} data={jobs.data.list} pagination={{ current: jobs.data.pagination.page, total: jobs.data.pagination.total, pageSize: jobs.data.pagination.pageSize, onChange: jobs.changePage }} columns={[
|
||||
{ title: '任务ID', dataIndex: 'jobId' },
|
||||
{ title: '状态', dataIndex: 'status', width: 120 },
|
||||
{ title: '短剧数', dataIndex: 'dramaCount', width: 120 },
|
||||
|
||||
@@ -1,27 +1,23 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Form,
|
||||
Grid,
|
||||
Input,
|
||||
InputNumber,
|
||||
InputTag,
|
||||
Message,
|
||||
Modal,
|
||||
Select,
|
||||
Space,
|
||||
Switch,
|
||||
Table,
|
||||
Tag,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Form,
|
||||
Grid,
|
||||
Input,
|
||||
InputNumber,
|
||||
InputTag,
|
||||
Message,
|
||||
Modal,
|
||||
Select,
|
||||
Space,
|
||||
Switch,
|
||||
Table,
|
||||
Tag,
|
||||
} from "@arco-design/web-react";
|
||||
import {
|
||||
IconArrowLeft,
|
||||
IconPlus,
|
||||
IconRefresh,
|
||||
} from "@arco-design/web-react/icon";
|
||||
import { IconArrowLeft, IconPlus, IconRefresh } from "@arco-design/web-react/icon";
|
||||
import type { ApiResponse, Drama, Episode, UploadTask } from "../api/types";
|
||||
import { api } from "../api/client";
|
||||
import { usePageData } from "../hooks/usePageData";
|
||||
@@ -29,450 +25,386 @@ import { usePageData } from "../hooks/usePageData";
|
||||
const { Row, Col } = Grid;
|
||||
|
||||
const STATUS_OPTIONS: { value: string; label: string }[] = [
|
||||
{ value: "draft", label: "草稿" },
|
||||
{ value: "scheduled", label: "定时发布" },
|
||||
{ value: "published", label: "已发布" },
|
||||
{ value: "offline", label: "已下线" },
|
||||
{ value: "draft", label: "草稿" },
|
||||
{ value: "scheduled", label: "定时发布" },
|
||||
{ value: "published", label: "已发布" },
|
||||
{ value: "offline", label: "已下线" },
|
||||
];
|
||||
|
||||
const REVIEW_STATUS_LABEL: Record<string, string> = {
|
||||
not_submitted: "未提交",
|
||||
pending: "待审核",
|
||||
reviewing: "审核中",
|
||||
approved: "已通过",
|
||||
rejected: "已拒绝",
|
||||
not_submitted: "未提交",
|
||||
pending: "待审核",
|
||||
reviewing: "审核中",
|
||||
approved: "已通过",
|
||||
rejected: "已拒绝",
|
||||
};
|
||||
|
||||
const PUBLISH_STATUS_LABEL: Record<string, string> = {
|
||||
draft: "草稿",
|
||||
scheduled: "定时发布",
|
||||
published: "已发布",
|
||||
offline: "已下线",
|
||||
draft: "草稿",
|
||||
scheduled: "定时发布",
|
||||
published: "已发布",
|
||||
offline: "已下线",
|
||||
};
|
||||
|
||||
function DramasPage() {
|
||||
const { id } = useParams();
|
||||
const { id } = useParams();
|
||||
|
||||
if (id) {
|
||||
return <DramaDetailPage dramaId={Number(id)} />;
|
||||
}
|
||||
if (id) {
|
||||
return <DramaDetailPage dramaId={Number(id)} />;
|
||||
}
|
||||
|
||||
return <DramaListPage />;
|
||||
return <DramaListPage />;
|
||||
}
|
||||
|
||||
function DramaListPage() {
|
||||
const navigate = useNavigate();
|
||||
const { data, loading, reload } = usePageData<Drama>("/api/admin/v1/dramas");
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [creating, setCreating] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const { data, loading, reload, changePage } = usePageData<Drama>("/api/admin/v1/dramas");
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [creating, setCreating] = useState(false);
|
||||
|
||||
const createDrama = async (values: Partial<Drama>) => {
|
||||
setCreating(true);
|
||||
try {
|
||||
await api.post("/api/admin/v1/dramas", values);
|
||||
Message.success("短剧创建成功");
|
||||
setVisible(false);
|
||||
await reload();
|
||||
} finally {
|
||||
setCreating(false);
|
||||
}
|
||||
};
|
||||
const createDrama = async (values: Partial<Drama>) => {
|
||||
setCreating(true);
|
||||
try {
|
||||
await api.post("/api/admin/v1/dramas", values);
|
||||
Message.success("短剧创建成功");
|
||||
setVisible(false);
|
||||
await reload();
|
||||
} finally {
|
||||
setCreating(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Card
|
||||
className="section-card"
|
||||
title="短剧管理"
|
||||
extra={
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<IconPlus />}
|
||||
onClick={() => setVisible(true)}
|
||||
return (
|
||||
<Card
|
||||
className="section-card"
|
||||
title="短剧管理"
|
||||
extra={
|
||||
<Button type="primary" icon={<IconPlus />} onClick={() => setVisible(true)}>
|
||||
新增短剧
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
新增短剧
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={loading}
|
||||
data={data.list}
|
||||
pagination={{
|
||||
total: data.pagination.total,
|
||||
pageSize: data.pagination.pageSize,
|
||||
}}
|
||||
columns={[
|
||||
{ title: "ID", dataIndex: "id", width: 80 },
|
||||
{ title: "标题", dataIndex: "title" },
|
||||
{ title: "地区", dataIndex: "region", width: 120 },
|
||||
{ title: "类型", dataIndex: "type", width: 140 },
|
||||
{ title: "总集数", dataIndex: "totalEpisodes", width: 100 },
|
||||
{ title: "已发布", dataIndex: "publishedEpisodes", width: 100 },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
width: 120,
|
||||
render: (status) => (
|
||||
<Tag color={status === "published" ? "green" : "gray"}>
|
||||
{PUBLISH_STATUS_LABEL[String(status)] || String(status)}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "推荐",
|
||||
dataIndex: "isRecommended",
|
||||
width: 100,
|
||||
render: (value) =>
|
||||
value ? <Tag color="arcoblue">是</Tag> : <Tag>否</Tag>,
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
width: 120,
|
||||
render: (_, record) => (
|
||||
<Button
|
||||
type="text"
|
||||
onClick={() => navigate(`/dramas/${record.id}`)}
|
||||
>
|
||||
详情
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Modal
|
||||
title="创建短剧"
|
||||
visible={visible}
|
||||
onCancel={() => setVisible(false)}
|
||||
footer={null}
|
||||
style={{ width: 640 }}
|
||||
>
|
||||
<Form
|
||||
layout="vertical"
|
||||
onSubmit={createDrama}
|
||||
initialValues={{
|
||||
status: "draft",
|
||||
isRecommended: false,
|
||||
sortOrder: 0,
|
||||
}}
|
||||
>
|
||||
<Form.Item label="标题" field="title" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入短剧标题" />
|
||||
</Form.Item>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item label="类型" field="type" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入类型" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item label="状态" field="status">
|
||||
<Select placeholder="请选择状态">
|
||||
{STATUS_OPTIONS.map((option) => (
|
||||
<Select.Option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<Form.Item
|
||||
label="封面地址"
|
||||
field="coverUrl"
|
||||
rules={[{ required: true }]}
|
||||
>
|
||||
<Input placeholder="请输入封面图片 URL" />
|
||||
</Form.Item>
|
||||
<Form.Item label="简介" field="description">
|
||||
<Input.TextArea
|
||||
placeholder="请输入短剧简介"
|
||||
autoSize={{ minRows: 2, maxRows: 4 }}
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={loading}
|
||||
data={data.list}
|
||||
pagination={{
|
||||
current: data.pagination.page,
|
||||
total: data.pagination.total,
|
||||
pageSize: data.pagination.pageSize,
|
||||
onChange: (page, pageSize) => changePage(page, pageSize),
|
||||
}}
|
||||
columns={[
|
||||
{ title: "ID", dataIndex: "id", width: 80 },
|
||||
{ title: "标题", dataIndex: "title" },
|
||||
{ title: "地区", dataIndex: "region", width: 120 },
|
||||
{ title: "类型", dataIndex: "type", width: 140 },
|
||||
{ title: "总集数", dataIndex: "totalEpisodes", width: 100 },
|
||||
{ title: "已发布", dataIndex: "publishedEpisodes", width: 100 },
|
||||
{
|
||||
title: "状态",
|
||||
dataIndex: "status",
|
||||
width: 120,
|
||||
render: (status) => (
|
||||
<Tag color={status === "published" ? "green" : "gray"}>{PUBLISH_STATUS_LABEL[String(status)] || String(status)}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "推荐",
|
||||
dataIndex: "isRecommended",
|
||||
width: 100,
|
||||
render: (value) => (value ? <Tag color="arcoblue">是</Tag> : <Tag>否</Tag>),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
width: 120,
|
||||
render: (_, record) => (
|
||||
<Button type="text" onClick={() => navigate(`/dramas/${record.id}`)}>
|
||||
详情
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="标签" field="tags">
|
||||
<InputTag placeholder="输入后回车添加标签" allowClear />
|
||||
</Form.Item>
|
||||
<Row gutter={16}>
|
||||
<Col span={8}>
|
||||
<Form.Item label="地区" field="region">
|
||||
<Input placeholder="如 中国" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Form.Item label="语言" field="language">
|
||||
<Input placeholder="如 zh-CN" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Form.Item label="年份" field="year">
|
||||
<InputNumber
|
||||
placeholder="如 2026"
|
||||
min={1900}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item label="排序权重" field="sortOrder">
|
||||
<InputNumber
|
||||
placeholder="数值越大越靠前"
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item
|
||||
label="推荐"
|
||||
field="isRecommended"
|
||||
triggerPropName="checked"
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<div className="modal-actions">
|
||||
<Button onClick={() => setVisible(false)}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" loading={creating}>
|
||||
创建
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Card>
|
||||
);
|
||||
<Modal title="创建短剧" visible={visible} onCancel={() => setVisible(false)} footer={null} style={{ width: 640 }}>
|
||||
<Form
|
||||
layout="vertical"
|
||||
onSubmit={createDrama}
|
||||
initialValues={{
|
||||
status: "draft",
|
||||
isRecommended: false,
|
||||
sortOrder: 0,
|
||||
}}
|
||||
>
|
||||
<Form.Item label="标题" field="title" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入短剧标题" />
|
||||
</Form.Item>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item label="类型" field="type" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入类型,如复仇、爱情、动作等" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item label="状态" field="status">
|
||||
<Select placeholder="请选择状态">
|
||||
{STATUS_OPTIONS.map((option) => (
|
||||
<Select.Option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<Form.Item label="封面地址" field="coverUrl" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入封面图片 URL" />
|
||||
</Form.Item>
|
||||
<Form.Item label="简介" field="description">
|
||||
<Input.TextArea placeholder="请输入短剧简介" autoSize={{ minRows: 2, maxRows: 4 }} />
|
||||
</Form.Item>
|
||||
<Form.Item label="标签" field="tags">
|
||||
<InputTag placeholder="输入后回车添加标签" allowClear />
|
||||
</Form.Item>
|
||||
<Row gutter={16}>
|
||||
<Col span={8}>
|
||||
<Form.Item label="地区" field="region">
|
||||
<Input placeholder="如 中国" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Form.Item label="语言" field="language">
|
||||
<Input placeholder="如 zh-CN" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Form.Item label="年份" field="year">
|
||||
<InputNumber placeholder="如 2026" min={1900} style={{ width: "100%" }} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item label="排序权重" field="sortOrder">
|
||||
<InputNumber placeholder="数值越大越靠前" style={{ width: "100%" }} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item label="推荐" field="isRecommended" triggerPropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
<div className="modal-actions">
|
||||
<Button onClick={() => setVisible(false)}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" loading={creating}>
|
||||
创建
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function DramaDetailPage({ dramaId }: { dramaId: number }) {
|
||||
const navigate = useNavigate();
|
||||
const [drama, setDrama] = useState<Drama | null>(null);
|
||||
const [episodes, setEpisodes] = useState<Episode[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [episodeCount, setEpisodeCount] = useState(1);
|
||||
const [uploadingEpisodeId, setUploadingEpisodeId] = useState<number | null>(
|
||||
null,
|
||||
);
|
||||
const navigate = useNavigate();
|
||||
const [drama, setDrama] = useState<Drama | null>(null);
|
||||
const [episodes, setEpisodes] = useState<Episode[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [episodeCount, setEpisodeCount] = useState(1);
|
||||
const [uploadingEpisodeId, setUploadingEpisodeId] = useState<number | null>(null);
|
||||
|
||||
const loadDetail = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [dramaResponse, episodeResponse] = await Promise.all([
|
||||
api.get<ApiResponse<Drama>>(`/api/admin/v1/dramas/${dramaId}`),
|
||||
api.get<ApiResponse<{ list: Episode[] }>>(
|
||||
`/api/admin/v1/dramas/${dramaId}/episodes?pageSize=200`,
|
||||
),
|
||||
]);
|
||||
setDrama(dramaResponse.data.data);
|
||||
setEpisodeCount(dramaResponse.data.data.totalEpisodes || 1);
|
||||
setEpisodes(episodeResponse.data.data.list);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void loadDetail();
|
||||
}, [dramaId]);
|
||||
|
||||
const configureEpisodes = async () => {
|
||||
await api.post(`/api/admin/v1/dramas/${dramaId}/episodes/batch`, {
|
||||
episodeCount,
|
||||
});
|
||||
Message.success("剧集数量已更新");
|
||||
await loadDetail();
|
||||
};
|
||||
|
||||
const updateDramaStatus = async (status: string) => {
|
||||
await api.patch(`/api/admin/v1/dramas/${dramaId}`, { status });
|
||||
Message.success("短剧状态已更新");
|
||||
await loadDetail();
|
||||
};
|
||||
|
||||
const uploadEpisodeVideo = async (episode: Episode, file: File) => {
|
||||
setUploadingEpisodeId(episode.id);
|
||||
try {
|
||||
const task = await api.post<ApiResponse<UploadTask>>(
|
||||
"/api/admin/v1/media/upload-tasks",
|
||||
{
|
||||
episodeId: episode.id,
|
||||
fileName: file.name,
|
||||
contentType: file.type || "video/mp4",
|
||||
fileSize: file.size,
|
||||
},
|
||||
);
|
||||
await api.patch(
|
||||
`/api/admin/v1/media/upload-tasks/${task.data.data.jobId}/complete`,
|
||||
{},
|
||||
);
|
||||
await api.post("/api/admin/v1/media/review-status/sync", {});
|
||||
Message.success("视频上传并审核通过");
|
||||
await loadDetail();
|
||||
} finally {
|
||||
setUploadingEpisodeId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const publishEpisode = async (episode: Episode) => {
|
||||
await api.patch(`/api/admin/v1/episodes/${episode.id}`, {
|
||||
publishStatus: "published",
|
||||
status: "published",
|
||||
});
|
||||
Message.success("剧集已发布");
|
||||
await loadDetail();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="page-stack">
|
||||
<Card
|
||||
className="section-card"
|
||||
loading={loading && !drama}
|
||||
title={
|
||||
<Space>
|
||||
<Button
|
||||
icon={<IconArrowLeft />}
|
||||
onClick={() => navigate("/dramas")}
|
||||
/>
|
||||
短剧详情
|
||||
</Space>
|
||||
const loadDetail = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [dramaResponse, episodeResponse] = await Promise.all([
|
||||
api.get<ApiResponse<Drama>>(`/api/admin/v1/dramas/${dramaId}`),
|
||||
api.get<ApiResponse<{ list: Episode[] }>>(`/api/admin/v1/dramas/${dramaId}/episodes?pageSize=200`),
|
||||
]);
|
||||
setDrama(dramaResponse.data.data);
|
||||
setEpisodeCount(dramaResponse.data.data.totalEpisodes || 1);
|
||||
setEpisodes(episodeResponse.data.data.list);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
extra={
|
||||
<Space>
|
||||
<Button icon={<IconRefresh />} onClick={loadDetail}>
|
||||
刷新
|
||||
</Button>
|
||||
<Button onClick={() => updateDramaStatus("draft")}>设为草稿</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={() => updateDramaStatus("published")}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
void loadDetail();
|
||||
}, [dramaId]);
|
||||
|
||||
const configureEpisodes = async () => {
|
||||
await api.post(`/api/admin/v1/dramas/${dramaId}/episodes/batch`, {
|
||||
episodeCount,
|
||||
});
|
||||
Message.success("剧集数量已更新");
|
||||
await loadDetail();
|
||||
};
|
||||
|
||||
const updateDramaStatus = async (status: string) => {
|
||||
await api.patch(`/api/admin/v1/dramas/${dramaId}`, { status });
|
||||
Message.success("短剧状态已更新");
|
||||
await loadDetail();
|
||||
};
|
||||
|
||||
const uploadEpisodeVideo = async (episode: Episode, file: File) => {
|
||||
setUploadingEpisodeId(episode.id);
|
||||
try {
|
||||
const task = await api.post<ApiResponse<UploadTask>>("/api/admin/v1/media/upload-tasks", {
|
||||
episodeId: episode.id,
|
||||
fileName: file.name,
|
||||
contentType: file.type || "video/mp4",
|
||||
fileSize: file.size,
|
||||
});
|
||||
await api.patch(`/api/admin/v1/media/upload-tasks/${task.data.data.jobId}/complete`, {});
|
||||
await api.post("/api/admin/v1/media/review-status/sync", {});
|
||||
Message.success("视频上传并审核通过");
|
||||
await loadDetail();
|
||||
} finally {
|
||||
setUploadingEpisodeId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const publishEpisode = async (episode: Episode) => {
|
||||
await api.patch(`/api/admin/v1/episodes/${episode.id}`, {
|
||||
publishStatus: "published",
|
||||
status: "published",
|
||||
});
|
||||
Message.success("剧集已发布");
|
||||
await loadDetail();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="page-stack">
|
||||
<Card
|
||||
className="section-card"
|
||||
loading={loading && !drama}
|
||||
title={
|
||||
<Space>
|
||||
<Button icon={<IconArrowLeft />} onClick={() => navigate("/dramas")} />
|
||||
短剧详情
|
||||
</Space>
|
||||
}
|
||||
extra={
|
||||
<Space>
|
||||
<Button icon={<IconRefresh />} onClick={loadDetail}>
|
||||
刷新
|
||||
</Button>
|
||||
<Button onClick={() => updateDramaStatus("draft")}>设为草稿</Button>
|
||||
<Button type="primary" onClick={() => updateDramaStatus("published")}>
|
||||
上架短剧
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
上架短剧
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{drama && (
|
||||
<Descriptions
|
||||
column={3}
|
||||
data={[
|
||||
{ label: "短剧ID", value: drama.id },
|
||||
{ label: "名称", value: drama.title },
|
||||
{ label: "地区", value: drama.region || "-" },
|
||||
{ label: "类型", value: drama.type },
|
||||
{ label: "总集数", value: drama.totalEpisodes || 0 },
|
||||
{ label: "已发布集数", value: drama.publishedEpisodes || 0 },
|
||||
{
|
||||
label: "状态",
|
||||
value: PUBLISH_STATUS_LABEL[drama.status] || drama.status,
|
||||
},
|
||||
{ label: "封面", value: drama.coverUrl },
|
||||
{ label: "简介", value: drama.description || "-" },
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
{drama && (
|
||||
<Descriptions
|
||||
column={3}
|
||||
data={[
|
||||
{ label: "短剧ID", value: drama.id },
|
||||
{ label: "名称", value: drama.title },
|
||||
{ label: "地区", value: drama.region || "-" },
|
||||
{ label: "类型", value: drama.type },
|
||||
{ label: "总集数", value: drama.totalEpisodes || 0 },
|
||||
{ label: "已发布集数", value: drama.publishedEpisodes || 0 },
|
||||
{
|
||||
label: "状态",
|
||||
value: PUBLISH_STATUS_LABEL[drama.status] || drama.status,
|
||||
},
|
||||
{ label: "封面", value: drama.coverUrl },
|
||||
{ label: "简介", value: drama.description || "-" },
|
||||
]}
|
||||
/>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
className="section-card"
|
||||
title="剧集配置"
|
||||
extra={
|
||||
<Space>
|
||||
<InputNumber
|
||||
min={1}
|
||||
max={500}
|
||||
value={episodeCount}
|
||||
onChange={(value) => setEpisodeCount(Number(value) || 1)}
|
||||
/>
|
||||
<Button type="primary" onClick={configureEpisodes}>
|
||||
保存集数
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={loading}
|
||||
data={episodes}
|
||||
pagination={false}
|
||||
columns={[
|
||||
{ title: "集数", dataIndex: "episodeNo", width: 80 },
|
||||
{ title: "标题", dataIndex: "title" },
|
||||
{
|
||||
title: "BytePlus VID",
|
||||
dataIndex: "byteplusVid",
|
||||
width: 180,
|
||||
render: (value) => value || "-",
|
||||
},
|
||||
{
|
||||
title: "尺寸",
|
||||
width: 120,
|
||||
render: (_, record) =>
|
||||
record.width && record.height
|
||||
? `${record.width}x${record.height}`
|
||||
: "-",
|
||||
},
|
||||
{
|
||||
title: "时长",
|
||||
dataIndex: "durationSeconds",
|
||||
width: 100,
|
||||
render: (value) => (value ? `${value}s` : "-"),
|
||||
},
|
||||
{
|
||||
title: "审核状态",
|
||||
dataIndex: "reviewStatus",
|
||||
width: 120,
|
||||
render: (status) => (
|
||||
<Tag color={status === "approved" ? "green" : "orange"}>
|
||||
{REVIEW_STATUS_LABEL[String(status)] || String(status)}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "发布状态",
|
||||
dataIndex: "publishStatus",
|
||||
width: 120,
|
||||
render: (status) => (
|
||||
<Tag color={status === "published" ? "green" : "gray"}>
|
||||
{PUBLISH_STATUS_LABEL[String(status)] || String(status)}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
width: 280,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Button loading={uploadingEpisodeId === record.id}>
|
||||
<label>
|
||||
上传视频
|
||||
<input
|
||||
type="file"
|
||||
accept="video/*"
|
||||
style={{ display: "none" }}
|
||||
onChange={(event) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (file) {
|
||||
void uploadEpisodeVideo(record, file);
|
||||
}
|
||||
event.target.value = "";
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
disabled={record.reviewStatus !== "approved"}
|
||||
onClick={() => publishEpisode(record)}
|
||||
>
|
||||
发布
|
||||
</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
<Card
|
||||
className="section-card"
|
||||
title="剧集配置"
|
||||
extra={
|
||||
<Space>
|
||||
<InputNumber min={1} max={500} value={episodeCount} onChange={(value) => setEpisodeCount(Number(value) || 1)} />
|
||||
<Button type="primary" onClick={configureEpisodes}>
|
||||
保存集数
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={loading}
|
||||
data={episodes}
|
||||
pagination={false}
|
||||
columns={[
|
||||
{ title: "集数", dataIndex: "episodeNo", width: 80 },
|
||||
{ title: "标题", dataIndex: "title" },
|
||||
{
|
||||
title: "BytePlus VID",
|
||||
dataIndex: "byteplusVid",
|
||||
width: 180,
|
||||
render: (value) => value || "-",
|
||||
},
|
||||
{
|
||||
title: "尺寸",
|
||||
width: 120,
|
||||
render: (_, record) => (record.width && record.height ? `${record.width}x${record.height}` : "-"),
|
||||
},
|
||||
{
|
||||
title: "时长",
|
||||
dataIndex: "durationSeconds",
|
||||
width: 100,
|
||||
render: (value) => (value ? `${value}s` : "-"),
|
||||
},
|
||||
{
|
||||
title: "审核状态",
|
||||
dataIndex: "reviewStatus",
|
||||
width: 120,
|
||||
render: (status) => (
|
||||
<Tag color={status === "approved" ? "green" : "orange"}>{REVIEW_STATUS_LABEL[String(status)] || String(status)}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "发布状态",
|
||||
dataIndex: "publishStatus",
|
||||
width: 120,
|
||||
render: (status) => (
|
||||
<Tag color={status === "published" ? "green" : "gray"}>{PUBLISH_STATUS_LABEL[String(status)] || String(status)}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
width: 280,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Button loading={uploadingEpisodeId === record.id}>
|
||||
<label>
|
||||
上传视频
|
||||
<input
|
||||
type="file"
|
||||
accept="video/*"
|
||||
style={{ display: "none" }}
|
||||
onChange={(event) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (file) {
|
||||
void uploadEpisodeVideo(record, file);
|
||||
}
|
||||
event.target.value = "";
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</Button>
|
||||
<Button type="text" disabled={record.reviewStatus !== "approved"} onClick={() => publishEpisode(record)}>
|
||||
发布
|
||||
</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default DramasPage;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { api } from '../api/client';
|
||||
import { usePageData } from '../hooks/usePageData';
|
||||
|
||||
function PersonnelPage() {
|
||||
const { data, loading, reload } = usePageData<AdminUser>('/api/admin/v1/admin-users');
|
||||
const { data, loading, reload, changePage } = usePageData<AdminUser>('/api/admin/v1/admin-users');
|
||||
const roles = usePageData<Role>('/api/admin/v1/roles');
|
||||
const [createForm] = Form.useForm();
|
||||
const [createVisible, setCreateVisible] = useState(false);
|
||||
@@ -77,7 +77,7 @@ function PersonnelPage() {
|
||||
|
||||
return (
|
||||
<Card className="section-card" title="人员管理" extra={<Button type="primary" icon={<IconPlus />} onClick={openCreate}>新增人员</Button>}>
|
||||
<Table rowKey="id" loading={loading} data={data.list} pagination={{ total: data.pagination.total, pageSize: data.pagination.pageSize }} columns={[
|
||||
<Table rowKey="id" loading={loading} data={data.list} pagination={{ current: data.pagination.page, total: data.pagination.total, pageSize: data.pagination.pageSize, onChange: changePage }} columns={[
|
||||
{ title: 'ID', dataIndex: 'id', width: 80 },
|
||||
{ title: '用户名', dataIndex: 'username' },
|
||||
{ title: '姓名', dataIndex: 'nickname' },
|
||||
|
||||
@@ -1,163 +1,156 @@
|
||||
import { useMemo } from 'react';
|
||||
import { Tree } from '@arco-design/web-react';
|
||||
import type { Permission } from '../api/types';
|
||||
import { useMemo } from "react";
|
||||
import { Tree } from "@arco-design/web-react";
|
||||
import type { Permission } from "../api/types";
|
||||
|
||||
type PermissionTreeNode = {
|
||||
key: string;
|
||||
title: string;
|
||||
children?: PermissionTreeNode[];
|
||||
key: string;
|
||||
title: string;
|
||||
children?: PermissionTreeNode[];
|
||||
};
|
||||
|
||||
type PermissionModuleConfig = {
|
||||
prefix: string;
|
||||
title: string;
|
||||
subject: string;
|
||||
prefix: string;
|
||||
title: string;
|
||||
subject: string;
|
||||
};
|
||||
|
||||
const systemPermissionModules: PermissionModuleConfig[] = [
|
||||
{ prefix: 'permission', title: '权限管理', subject: '权限' },
|
||||
{ prefix: 'role', title: '角色管理', subject: '角色' },
|
||||
{ prefix: 'admin-user', title: '人员管理', subject: '人员' },
|
||||
{ prefix: 'user', title: '用户管理', subject: '用户' },
|
||||
{ prefix: 'log', title: '日志管理', subject: '日志' },
|
||||
{ prefix: "permission", title: "权限管理", subject: "权限" },
|
||||
{ prefix: "role", title: "角色管理", subject: "角色" },
|
||||
{ prefix: "admin-user", title: "人员管理", subject: "人员" },
|
||||
{ prefix: "user", title: "用户管理", subject: "用户" },
|
||||
{ prefix: "log", title: "日志管理", subject: "日志" },
|
||||
];
|
||||
|
||||
const businessPermissionModules: PermissionModuleConfig[] = [
|
||||
{ prefix: 'drama', title: '短剧管理', subject: '短剧' },
|
||||
{ prefix: 'episode', title: '剧集管理', subject: '剧集' },
|
||||
{ prefix: 'media', title: '媒体管理', subject: '媒体' },
|
||||
{ prefix: 'payment', title: '支付管理', subject: '支付' },
|
||||
{ prefix: "drama", title: "短剧管理", subject: "短剧" },
|
||||
{ prefix: "episode", title: "剧集管理", subject: "剧集" },
|
||||
{ prefix: "media", title: "媒体管理", subject: "媒体" },
|
||||
{ prefix: "payment", title: "支付管理", subject: "支付" },
|
||||
];
|
||||
|
||||
const actionNames: Record<string, string> = {
|
||||
read: '查看',
|
||||
create: '创建',
|
||||
update: '更新',
|
||||
delete: '删除',
|
||||
manage: '管理',
|
||||
read: "查看",
|
||||
create: "创建",
|
||||
update: "更新",
|
||||
delete: "删除",
|
||||
manage: "管理",
|
||||
};
|
||||
|
||||
function permissionKey(id: number) {
|
||||
return `permission:${id}`;
|
||||
return `permission:${id}`;
|
||||
}
|
||||
|
||||
function permissionIdFromKey(key: string) {
|
||||
const id = Number(key.replace('permission:', ''));
|
||||
return Number.isInteger(id) ? id : null;
|
||||
const id = Number(key.replace("permission:", ""));
|
||||
return Number.isInteger(id) ? id : null;
|
||||
}
|
||||
|
||||
function getPermissionPrefix(code: string) {
|
||||
return code.split(':')[0];
|
||||
return code.split(":")[0];
|
||||
}
|
||||
|
||||
function getPermissionAction(code: string) {
|
||||
return code.split(':')[1] || code;
|
||||
return code.split(":")[1] || code;
|
||||
}
|
||||
|
||||
function getPermissionTitle(permission: Permission, module?: PermissionModuleConfig) {
|
||||
return permission.name || (module ? `${actionNames[getPermissionAction(permission.code)]}${module.subject}` : permission.code);
|
||||
return permission.name || (module ? `${actionNames[getPermissionAction(permission.code)]}${module.subject}` : permission.code);
|
||||
}
|
||||
|
||||
function buildPermissionModuleNode(
|
||||
permissions: Permission[],
|
||||
module: PermissionModuleConfig,
|
||||
): PermissionTreeNode | null {
|
||||
const children = permissions
|
||||
.filter((permission) => getPermissionPrefix(permission.code) === module.prefix)
|
||||
.map((permission) => ({
|
||||
key: permissionKey(permission.id),
|
||||
title: getPermissionTitle(permission, module),
|
||||
}));
|
||||
function buildPermissionModuleNode(permissions: Permission[], module: PermissionModuleConfig): PermissionTreeNode | null {
|
||||
const children = permissions
|
||||
.filter((permission) => getPermissionPrefix(permission.code) === module.prefix)
|
||||
.map((permission) => ({
|
||||
key: permissionKey(permission.id),
|
||||
title: getPermissionTitle(permission, module),
|
||||
}));
|
||||
|
||||
if (!children.length) {
|
||||
return null;
|
||||
}
|
||||
if (!children.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
key: `module:${module.prefix}`,
|
||||
title: module.title,
|
||||
children,
|
||||
};
|
||||
return {
|
||||
key: `module:${module.prefix}`,
|
||||
title: module.title,
|
||||
children,
|
||||
};
|
||||
}
|
||||
|
||||
function buildPermissionTree(permissions: Permission[]): PermissionTreeNode[] {
|
||||
const knownPrefixes = new Set([
|
||||
...systemPermissionModules.map((module) => module.prefix),
|
||||
...businessPermissionModules.map((module) => module.prefix),
|
||||
]);
|
||||
const systemChildren = systemPermissionModules
|
||||
.map((module) => buildPermissionModuleNode(permissions, module))
|
||||
.filter((node): node is PermissionTreeNode => Boolean(node));
|
||||
const businessChildren = businessPermissionModules
|
||||
.map((module) => buildPermissionModuleNode(permissions, module))
|
||||
.filter((node): node is PermissionTreeNode => Boolean(node));
|
||||
const otherPermissions = permissions
|
||||
.filter((permission) => !knownPrefixes.has(getPermissionPrefix(permission.code)))
|
||||
.map((permission) => ({
|
||||
key: permissionKey(permission.id),
|
||||
title: permission.name,
|
||||
}));
|
||||
const knownPrefixes = new Set([
|
||||
...systemPermissionModules.map((module) => module.prefix),
|
||||
...businessPermissionModules.map((module) => module.prefix),
|
||||
]);
|
||||
const systemChildren = systemPermissionModules
|
||||
.map((module) => buildPermissionModuleNode(permissions, module))
|
||||
.filter((node): node is PermissionTreeNode => Boolean(node));
|
||||
const businessChildren = businessPermissionModules
|
||||
.map((module) => buildPermissionModuleNode(permissions, module))
|
||||
.filter((node): node is PermissionTreeNode => Boolean(node));
|
||||
const otherPermissions = permissions
|
||||
.filter((permission) => !knownPrefixes.has(getPermissionPrefix(permission.code)))
|
||||
.map((permission) => ({
|
||||
key: permissionKey(permission.id),
|
||||
title: permission.name,
|
||||
}));
|
||||
|
||||
if (otherPermissions.length) {
|
||||
businessChildren.push({
|
||||
key: 'module:other',
|
||||
title: '其他权限',
|
||||
children: otherPermissions,
|
||||
});
|
||||
}
|
||||
if (otherPermissions.length) {
|
||||
businessChildren.push({
|
||||
key: "module:other",
|
||||
title: "其他权限",
|
||||
children: otherPermissions,
|
||||
});
|
||||
}
|
||||
|
||||
return [
|
||||
{ key: 'group:system', title: '系统权限', children: systemChildren },
|
||||
{ key: 'group:business', title: '业务权限', children: businessChildren },
|
||||
];
|
||||
return [
|
||||
{ key: "group:system", title: "系统权限", children: systemChildren },
|
||||
{ key: "group:business", title: "业务权限", children: businessChildren },
|
||||
];
|
||||
}
|
||||
|
||||
function collectExpandedKeys(nodes: PermissionTreeNode[]) {
|
||||
const keys: string[] = [];
|
||||
const visit = (items: PermissionTreeNode[]) => {
|
||||
items.forEach((item) => {
|
||||
if (item.children?.length) {
|
||||
keys.push(item.key);
|
||||
visit(item.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
visit(nodes);
|
||||
return keys;
|
||||
const keys: string[] = [];
|
||||
const visit = (items: PermissionTreeNode[]) => {
|
||||
items.forEach((item) => {
|
||||
if (item.children?.length) {
|
||||
keys.push(item.key);
|
||||
visit(item.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
visit(nodes);
|
||||
return keys;
|
||||
}
|
||||
|
||||
export function PermissionTreePicker({
|
||||
permissions,
|
||||
value,
|
||||
onChange,
|
||||
permissions,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
permissions: Permission[];
|
||||
value: number[];
|
||||
onChange: (permissionIds: number[]) => void;
|
||||
permissions: Permission[];
|
||||
value: number[];
|
||||
onChange: (permissionIds: number[]) => void;
|
||||
}) {
|
||||
const treeData = useMemo(() => buildPermissionTree(permissions), [permissions]);
|
||||
const expandedKeys = useMemo(() => collectExpandedKeys(treeData), [treeData]);
|
||||
const checkedKeys = value.map((id) => permissionKey(id));
|
||||
const treeData = useMemo(() => buildPermissionTree(permissions), [permissions]);
|
||||
const expandedKeys = useMemo(() => collectExpandedKeys(treeData), [treeData]);
|
||||
const checkedKeys = value.map((id) => permissionKey(id));
|
||||
|
||||
return (
|
||||
<div className="permission-tree-panel">
|
||||
<Tree
|
||||
blockNode
|
||||
checkable
|
||||
checkedStrategy="child"
|
||||
checkedKeys={checkedKeys}
|
||||
defaultExpandedKeys={expandedKeys}
|
||||
selectable={false}
|
||||
showLine
|
||||
treeData={treeData}
|
||||
onCheck={(keys) => {
|
||||
onChange(
|
||||
keys
|
||||
.map((key) => permissionIdFromKey(key))
|
||||
.filter((id): id is number => id !== null),
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className="permission-tree-panel">
|
||||
<Tree
|
||||
blockNode
|
||||
checkable
|
||||
checkedStrategy="child"
|
||||
checkedKeys={checkedKeys}
|
||||
defaultExpandedKeys={expandedKeys}
|
||||
selectable={false}
|
||||
showLine
|
||||
treeData={treeData}
|
||||
onCheck={(keys) => {
|
||||
onChange(keys.map((key) => permissionIdFromKey(key)).filter((id): id is number => id !== null));
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
.permission-tree-panel {
|
||||
height: 360px;
|
||||
overflow: auto;
|
||||
margin-bottom: 15px;
|
||||
padding: 12px 16px;
|
||||
border: 1px solid #e5e6eb;
|
||||
border-radius: 6px;
|
||||
|
||||
@@ -1,117 +1,147 @@
|
||||
import { useState } from 'react';
|
||||
import { Button, Card, Form, Input, Message, Modal, Space, Table, Tag } from '@arco-design/web-react';
|
||||
import { IconPlus } from '@arco-design/web-react/icon';
|
||||
import type { Permission, Role } from '../api/types';
|
||||
import { api } from '../api/client';
|
||||
import { usePageData } from '../hooks/usePageData';
|
||||
import { PermissionTreePicker } from './PermissionTreePicker';
|
||||
import './index.css';
|
||||
import { useState } from "react";
|
||||
import { Button, Card, Form, Input, Message, Modal, Space, Table, Tag } from "@arco-design/web-react";
|
||||
import { IconPlus } from "@arco-design/web-react/icon";
|
||||
import type { Permission, Role } from "../api/types";
|
||||
import { api } from "../api/client";
|
||||
import { usePageData } from "../hooks/usePageData";
|
||||
import { PermissionTreePicker } from "./PermissionTreePicker";
|
||||
import "./index.css";
|
||||
|
||||
function RolesPage() {
|
||||
const { data, loading, reload } = usePageData<Role>('/api/admin/v1/roles');
|
||||
const permissions = usePageData<Permission>('/api/admin/v1/permissions');
|
||||
const [createForm] = Form.useForm();
|
||||
const [createVisible, setCreateVisible] = useState(false);
|
||||
const [creatingRole, setCreatingRole] = useState(false);
|
||||
const [createPermissionIds, setCreatePermissionIds] = useState<number[]>([]);
|
||||
const [assignmentVisible, setAssignmentVisible] = useState(false);
|
||||
const [selectedRole, setSelectedRole] = useState<Role | null>(null);
|
||||
const [selectedPermissionIds, setSelectedPermissionIds] = useState<number[]>([]);
|
||||
const [savingPermissions, setSavingPermissions] = useState(false);
|
||||
const { data, loading, reload, changePage } = usePageData<Role>("/api/admin/v1/roles");
|
||||
const permissions = usePageData<Permission>("/api/admin/v1/permissions");
|
||||
const [createForm] = Form.useForm();
|
||||
const [createVisible, setCreateVisible] = useState(false);
|
||||
const [creatingRole, setCreatingRole] = useState(false);
|
||||
const [createPermissionIds, setCreatePermissionIds] = useState<number[]>([]);
|
||||
const [assignmentVisible, setAssignmentVisible] = useState(false);
|
||||
const [selectedRole, setSelectedRole] = useState<Role | null>(null);
|
||||
const [selectedPermissionIds, setSelectedPermissionIds] = useState<number[]>([]);
|
||||
const [savingPermissions, setSavingPermissions] = useState(false);
|
||||
|
||||
const openCreateRole = () => {
|
||||
createForm.resetFields();
|
||||
setCreatePermissionIds([]);
|
||||
setCreateVisible(true);
|
||||
};
|
||||
const openCreateRole = () => {
|
||||
createForm.resetFields();
|
||||
setCreatePermissionIds([]);
|
||||
setCreateVisible(true);
|
||||
};
|
||||
|
||||
const createRole = async (values: { code: string; name: string; description?: string }) => {
|
||||
setCreatingRole(true);
|
||||
try {
|
||||
await api.post('/api/admin/v1/roles', {
|
||||
...values,
|
||||
permissionIds: createPermissionIds,
|
||||
});
|
||||
Message.success('角色创建成功');
|
||||
setCreateVisible(false);
|
||||
await reload();
|
||||
} finally {
|
||||
setCreatingRole(false);
|
||||
}
|
||||
};
|
||||
const createRole = async (values: { code: string; name: string; description?: string }) => {
|
||||
setCreatingRole(true);
|
||||
try {
|
||||
await api.post("/api/admin/v1/roles", {
|
||||
...values,
|
||||
permissionIds: createPermissionIds,
|
||||
});
|
||||
Message.success("角色创建成功");
|
||||
setCreateVisible(false);
|
||||
await reload();
|
||||
} finally {
|
||||
setCreatingRole(false);
|
||||
}
|
||||
};
|
||||
|
||||
const openAssignPermissions = (role: Role) => {
|
||||
setSelectedRole(role);
|
||||
setSelectedPermissionIds(role.permissions.map((permission) => permission.id));
|
||||
setAssignmentVisible(true);
|
||||
};
|
||||
const openAssignPermissions = (role: Role) => {
|
||||
setSelectedRole(role);
|
||||
setSelectedPermissionIds(role.permissions.map((permission) => permission.id));
|
||||
setAssignmentVisible(true);
|
||||
};
|
||||
|
||||
const saveRolePermissions = async () => {
|
||||
if (!selectedRole) {
|
||||
return;
|
||||
}
|
||||
setSavingPermissions(true);
|
||||
try {
|
||||
await api.patch(`/api/admin/v1/roles/${selectedRole.id}/permissions`, {
|
||||
permissionIds: selectedPermissionIds,
|
||||
});
|
||||
Message.success('角色权限已更新');
|
||||
setAssignmentVisible(false);
|
||||
await reload();
|
||||
} finally {
|
||||
setSavingPermissions(false);
|
||||
}
|
||||
};
|
||||
const saveRolePermissions = async () => {
|
||||
if (!selectedRole) {
|
||||
return;
|
||||
}
|
||||
setSavingPermissions(true);
|
||||
try {
|
||||
await api.patch(`/api/admin/v1/roles/${selectedRole.id}/permissions`, {
|
||||
permissionIds: selectedPermissionIds,
|
||||
});
|
||||
Message.success("角色权限已更新");
|
||||
setAssignmentVisible(false);
|
||||
await reload();
|
||||
} finally {
|
||||
setSavingPermissions(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Card className="section-card" title="角色管理" extra={<Button type="primary" icon={<IconPlus />} onClick={openCreateRole}>新增角色</Button>}>
|
||||
<Table rowKey="id" loading={loading} data={data.list} pagination={{ total: data.pagination.total, pageSize: data.pagination.pageSize }} columns={[
|
||||
{ title: 'ID', dataIndex: 'id', width: 80 },
|
||||
{ title: '编码', dataIndex: 'code' },
|
||||
{ title: '名称', dataIndex: 'name' },
|
||||
{ title: '权限列表', render: (_, record: Role) => <Space wrap>{record.permissions.map((item) => <Tag key={item.id}>{item.name}</Tag>)}</Space> },
|
||||
{ title: '操作', width: 140, render: (_, record: Role) => <Button size="small" onClick={() => openAssignPermissions(record)}>分配权限</Button> },
|
||||
]} />
|
||||
<Modal title="新增角色" visible={createVisible} onCancel={() => setCreateVisible(false)} footer={null}>
|
||||
<Form form={createForm} layout="vertical" onSubmit={createRole}>
|
||||
<Form.Item label="角色编码" field="code" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入角色编码,例如 drama_operator" />
|
||||
</Form.Item>
|
||||
<div className="form-help">角色的唯一标识,创建后不可修改</div>
|
||||
<Form.Item label="角色名称" field="name" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入角色名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="角色描述" field="description">
|
||||
<Input.TextArea placeholder="请输入角色描述" autoSize={{ minRows: 2, maxRows: 4 }} />
|
||||
</Form.Item>
|
||||
<div className="form-label">权限设置</div>
|
||||
<PermissionTreePicker
|
||||
permissions={permissions.data.list}
|
||||
value={createPermissionIds}
|
||||
onChange={setCreatePermissionIds}
|
||||
/>
|
||||
<div className="form-help">为角色分配系统权限,决定拥有此角色的用户可以进行的操作</div>
|
||||
<div className="modal-actions">
|
||||
<Button onClick={() => setCreateVisible(false)}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" loading={creatingRole}>创建</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
<Modal
|
||||
title={`分配权限${selectedRole ? ` - ${selectedRole.name}` : ''}`}
|
||||
visible={assignmentVisible}
|
||||
confirmLoading={savingPermissions}
|
||||
onOk={saveRolePermissions}
|
||||
onCancel={() => setAssignmentVisible(false)}
|
||||
>
|
||||
<PermissionTreePicker
|
||||
permissions={permissions.data.list}
|
||||
value={selectedPermissionIds}
|
||||
onChange={setSelectedPermissionIds}
|
||||
/>
|
||||
</Modal>
|
||||
</Card>
|
||||
);
|
||||
return (
|
||||
<Card
|
||||
className="section-card"
|
||||
title="角色管理"
|
||||
extra={
|
||||
<Button type="primary" icon={<IconPlus />} onClick={openCreateRole}>
|
||||
新增角色
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
loading={loading}
|
||||
data={data.list}
|
||||
pagination={{
|
||||
current: data.pagination.page,
|
||||
total: data.pagination.total,
|
||||
pageSize: data.pagination.pageSize,
|
||||
onChange: changePage,
|
||||
}}
|
||||
columns={[
|
||||
{ title: "ID", dataIndex: "id", width: 80 },
|
||||
{ title: "编码", dataIndex: "code" },
|
||||
{ title: "名称", dataIndex: "name" },
|
||||
{
|
||||
title: "权限列表",
|
||||
render: (_, record: Role) => (
|
||||
<Space wrap>
|
||||
{record.permissions.map((item) => (
|
||||
<Tag key={item.id}>{item.name}</Tag>
|
||||
))}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "操作",
|
||||
width: 140,
|
||||
render: (_, record: Role) => (
|
||||
<Button size="small" onClick={() => openAssignPermissions(record)}>
|
||||
分配权限
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Modal title="新增角色" visible={createVisible} onCancel={() => setCreateVisible(false)} footer={null}>
|
||||
<Form form={createForm} layout="vertical" onSubmit={createRole}>
|
||||
<Form.Item label="角色编码" field="code" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入角色编码,例如 drama_operator" />
|
||||
</Form.Item>
|
||||
<div className="form-help">角色的唯一标识,创建后不可修改</div>
|
||||
<Form.Item label="角色名称" field="name" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入角色名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="角色描述" field="description">
|
||||
<Input.TextArea placeholder="请输入角色描述" autoSize={{ minRows: 2, maxRows: 4 }} />
|
||||
</Form.Item>
|
||||
<div className="form-label">权限设置</div>
|
||||
<PermissionTreePicker permissions={permissions.data.list} value={createPermissionIds} onChange={setCreatePermissionIds} />
|
||||
<div className="form-help">为角色分配系统权限,决定拥有此角色的用户可以进行的操作</div>
|
||||
<div className="modal-actions">
|
||||
<Button onClick={() => setCreateVisible(false)}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" loading={creatingRole}>
|
||||
创建
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
<Modal
|
||||
title={`分配权限${selectedRole ? ` - ${selectedRole.name}` : ""}`}
|
||||
visible={assignmentVisible}
|
||||
confirmLoading={savingPermissions}
|
||||
onOk={saveRolePermissions}
|
||||
onCancel={() => setAssignmentVisible(false)}
|
||||
>
|
||||
<PermissionTreePicker permissions={permissions.data.list} value={selectedPermissionIds} onChange={setSelectedPermissionIds} />
|
||||
</Modal>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
export default RolesPage;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { api } from '../api/client';
|
||||
import { usePageData } from '../hooks/usePageData';
|
||||
|
||||
function UsersPage() {
|
||||
const { data, loading, reload } = usePageData<AppUser>('/api/admin/v1/users');
|
||||
const { data, loading, reload, changePage } = usePageData<AppUser>('/api/admin/v1/users');
|
||||
const update状态 = async (id: number, status: 'active' | 'disabled') => {
|
||||
await api.patch(`/api/admin/v1/users/${id}/status`, { status });
|
||||
Message.success('用户状态已更新');
|
||||
@@ -13,7 +13,7 @@ function UsersPage() {
|
||||
|
||||
return (
|
||||
<Card className="section-card" title="小程序用户管理">
|
||||
<Table rowKey="id" loading={loading} data={data.list} pagination={{ total: data.pagination.total, pageSize: data.pagination.pageSize }} columns={[
|
||||
<Table rowKey="id" loading={loading} data={data.list} pagination={{ current: data.pagination.page, total: data.pagination.total, pageSize: data.pagination.pageSize, onChange: changePage }} columns={[
|
||||
{ title: 'ID', dataIndex: 'id', width: 80 },
|
||||
{ title: 'TikTok Open ID', dataIndex: 'tiktokOpenId' },
|
||||
{ title: '昵称', dataIndex: 'nickname' },
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import { Message } from '@arco-design/web-react';
|
||||
import type { ApiResponse, PageData } from './types';
|
||||
import axios, { AxiosError } from "axios";
|
||||
import { Message } from "@arco-design/web-react";
|
||||
import type { ApiResponse, PageData } from "./types";
|
||||
|
||||
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000';
|
||||
export const TOKEN_KEY = 'cth_tk_admin_token';
|
||||
export const API_BASE_URL =
|
||||
import.meta.env.VITE_API_BASE_URL || "http://localhost:3000";
|
||||
export const TOKEN_KEY = "cth_tk_admin_token";
|
||||
|
||||
export const api = axios.create({ baseURL: API_BASE_URL });
|
||||
|
||||
@@ -18,13 +19,17 @@ api.interceptors.request.use((config) => {
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error: AxiosError<ApiResponse<unknown>>) => {
|
||||
const message = error.response?.data?.message || error.message || '请求失败';
|
||||
const message =
|
||||
error.response?.data?.message || error.message || "请求失败";
|
||||
Message.error(message);
|
||||
return Promise.reject(error);
|
||||
},
|
||||
);
|
||||
|
||||
export async function fetchPage<T>(url: string): Promise<PageData<T>> {
|
||||
const response = await api.get<ApiResponse<PageData<T>>>(url);
|
||||
export async function fetchPage<T>(
|
||||
url: string,
|
||||
params?: { page?: number; pageSize?: number },
|
||||
): Promise<PageData<T>> {
|
||||
const response = await api.get<ApiResponse<PageData<T>>>(url, { params });
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
20
src/hooks/pageData.ts
Normal file
20
src/hooks/pageData.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { PageData } from '../api/types';
|
||||
|
||||
type PageQuery = {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
};
|
||||
|
||||
export function resolvePageData<T>(
|
||||
response: PageData<T>,
|
||||
query: PageQuery,
|
||||
): PageData<T> {
|
||||
return {
|
||||
list: response.list,
|
||||
pagination: {
|
||||
...response.pagination,
|
||||
page: query.page,
|
||||
pageSize: query.pageSize,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,31 +1,51 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { fetchPage } from '../api/client';
|
||||
import type { PageData } from '../api/types';
|
||||
import { useEffect, useState } from "react";
|
||||
import { fetchPage } from "../api/client";
|
||||
import type { PageData } from "../api/types";
|
||||
import { resolvePageData } from "./pageData";
|
||||
|
||||
type PageQuery = {
|
||||
page: number;
|
||||
pageSize: number;
|
||||
};
|
||||
|
||||
export function usePageData<T>(url: string, enabled = true) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [data, setData] = useState<PageData<T>>({
|
||||
list: [],
|
||||
pagination: { page: 1, pageSize: 20, total: 0 },
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [pageQuery, setPageQuery] = useState<PageQuery>({
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
});
|
||||
const [data, setData] = useState<PageData<T>>({
|
||||
list: [],
|
||||
pagination: { page: 1, pageSize: 20, total: 0 },
|
||||
});
|
||||
|
||||
const load = async () => {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
setData(await fetchPage<T>(url));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
const load = async (query = pageQuery) => {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await fetchPage<T>(url, query);
|
||||
setData(resolvePageData(response, query));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (enabled) {
|
||||
void load();
|
||||
}
|
||||
}, [url, enabled]);
|
||||
const changePage = (page: number, pageSize: number) => {
|
||||
setPageQuery({ page, pageSize });
|
||||
};
|
||||
|
||||
return { data, loading, reload: load };
|
||||
useEffect(() => {
|
||||
if (enabled) {
|
||||
void load(pageQuery);
|
||||
}
|
||||
}, [url, enabled, pageQuery.page, pageQuery.pageSize]);
|
||||
|
||||
return {
|
||||
data,
|
||||
loading,
|
||||
reload: () => load(pageQuery),
|
||||
changePage,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,117 +1,168 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import {
|
||||
Avatar,
|
||||
Button,
|
||||
Dropdown,
|
||||
Layout,
|
||||
Menu,
|
||||
Space,
|
||||
Typography,
|
||||
} from '@arco-design/web-react';
|
||||
import { IconMenuFold, IconMenuUnfold } from '@arco-design/web-react/icon';
|
||||
import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
||||
import type { ApiResponse, AdminProfile } from '../api/types';
|
||||
import { API_BASE_URL, TOKEN_KEY, api } from '../api/client';
|
||||
import { filterMenuItems, findCurrentMenu, menuItems, renderMenuItem } from './menu';
|
||||
import { PermissionRoute } from './PermissionRoute';
|
||||
import DashboardPage from '../Dashboard';
|
||||
import DramasPage from '../Drama';
|
||||
import DataPage from '../Data';
|
||||
import UsersPage from '../User';
|
||||
import RolesPage from '../Role';
|
||||
import PersonnelPage from '../Personnel';
|
||||
import ProfilePage from '../Profile';
|
||||
import LogsPage from '../Log';
|
||||
import './layout.css';
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Avatar, Button, Dropdown, Layout, Menu, Space, Typography } from "@arco-design/web-react";
|
||||
import { IconMenuFold, IconMenuUnfold } from "@arco-design/web-react/icon";
|
||||
import { Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom";
|
||||
import type { ApiResponse, AdminProfile } from "../api/types";
|
||||
import { TOKEN_KEY, api } from "../api/client";
|
||||
import { filterMenuItems, findCurrentMenu, menuItems, renderMenuItem } from "./menu";
|
||||
import { PermissionRoute } from "./PermissionRoute";
|
||||
import DashboardPage from "../Dashboard";
|
||||
import DramasPage from "../Drama";
|
||||
import DataPage from "../Data";
|
||||
import UsersPage from "../User";
|
||||
import RolesPage from "../Role";
|
||||
import PersonnelPage from "../Personnel";
|
||||
import ProfilePage from "../Profile";
|
||||
import LogsPage from "../Log";
|
||||
import "./layout.css";
|
||||
|
||||
const { Header, Sider, Content } = Layout;
|
||||
const { Text } = Typography;
|
||||
|
||||
export function AdminLayout() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [profile, setProfile] = useState<AdminProfile | null>(null);
|
||||
const current = useMemo(() => findCurrentMenu(location.pathname), [location.pathname]);
|
||||
const visibleMenuItems = useMemo(() => filterMenuItems(menuItems, profile), [profile]);
|
||||
const [openMenuKeys, setOpenMenuKeys] = useState<string[]>(current?.parent ? [current.parent.key] : []);
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [profile, setProfile] = useState<AdminProfile | null>(null);
|
||||
const current = useMemo(() => findCurrentMenu(location.pathname), [location.pathname]);
|
||||
const visibleMenuItems = useMemo(() => filterMenuItems(menuItems, profile), [profile]);
|
||||
const [openMenuKeys, setOpenMenuKeys] = useState<string[]>(current?.parent ? [current.parent.key] : []);
|
||||
|
||||
useEffect(() => {
|
||||
api.get<ApiResponse<AdminProfile>>('/api/admin/v1/auth/profile')
|
||||
.then((response) => setProfile(response.data.data))
|
||||
.catch(() => {
|
||||
useEffect(() => {
|
||||
api.get<ApiResponse<AdminProfile>>("/api/admin/v1/auth/profile")
|
||||
.then((response) => setProfile(response.data.data))
|
||||
.catch(() => {
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
navigate("/login", { replace: true });
|
||||
});
|
||||
}, [navigate]);
|
||||
|
||||
useEffect(() => {
|
||||
if (current?.parent && !openMenuKeys.includes(current.parent.key)) {
|
||||
setOpenMenuKeys((keys) => [...keys, current.parent!.key]);
|
||||
}
|
||||
}, [current, openMenuKeys]);
|
||||
|
||||
const logout = () => {
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
navigate('/login', { replace: true });
|
||||
});
|
||||
}, [navigate]);
|
||||
navigate("/login", { replace: true });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (current?.parent && !openMenuKeys.includes(current.parent.key)) {
|
||||
setOpenMenuKeys((keys) => [...keys, current.parent!.key]);
|
||||
}
|
||||
}, [current, openMenuKeys]);
|
||||
|
||||
const logout = () => {
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
navigate('/login', { replace: true });
|
||||
};
|
||||
|
||||
return (
|
||||
<Layout className="layout">
|
||||
<Sider className="sidebar" width={220} collapsed={collapsed} collapsible trigger={null}>
|
||||
<div className="logo-row">
|
||||
<span className="logo-mark">TK</span>
|
||||
{!collapsed && <span>TK短剧管理后台</span>}
|
||||
</div>
|
||||
<Menu
|
||||
selectedKeys={[current?.item.key || '/dashboard']}
|
||||
openKeys={openMenuKeys}
|
||||
onClickMenuItem={(key) => navigate(key)}
|
||||
onClickSubMenu={(_, openKeys) => setOpenMenuKeys(openKeys)}
|
||||
>
|
||||
{visibleMenuItems.map((item) => renderMenuItem(item))}
|
||||
</Menu>
|
||||
</Sider>
|
||||
<Layout>
|
||||
<Header className="header">
|
||||
<Space>
|
||||
<Button icon={collapsed ? <IconMenuUnfold /> : <IconMenuFold />} onClick={() => setCollapsed(!collapsed)} />
|
||||
<div className="header-title">
|
||||
<strong>{current?.item.label || '工作台'}</strong>
|
||||
<span>后端 API: {API_BASE_URL}</span>
|
||||
</div>
|
||||
</Space>
|
||||
<Dropdown
|
||||
position="br"
|
||||
trigger="click"
|
||||
droplist={(
|
||||
<Menu>
|
||||
<Menu.Item key="profile" onClick={() => navigate('/profile')}>个人中心</Menu.Item>
|
||||
<Menu.Item key="logout" onClick={logout}>退出登录</Menu.Item>
|
||||
</Menu>
|
||||
)}
|
||||
>
|
||||
<button className="user-menu-trigger" type="button">
|
||||
<Avatar size={28}>{profile?.username?.slice(0, 1).toUpperCase() || 'A'}</Avatar>
|
||||
<Text>{profile?.nickname || profile?.username || '管理员'}</Text>
|
||||
</button>
|
||||
</Dropdown>
|
||||
</Header>
|
||||
<Content className="content">
|
||||
<Routes>
|
||||
<Route path="/dashboard" element={<DashboardPage profile={profile} />} />
|
||||
<Route path="/dramas" element={<PermissionRoute profile={profile} requiredPermissions={['drama:read']}><DramasPage /></PermissionRoute>} />
|
||||
<Route path="/dramas/:id" element={<PermissionRoute profile={profile} requiredPermissions={['drama:read']}><DramasPage /></PermissionRoute>} />
|
||||
<Route path="/data" element={<PermissionRoute profile={profile} requiredPermissions={['data:read']}><DataPage /></PermissionRoute>} />
|
||||
<Route path="/users" element={<PermissionRoute profile={profile} requiredPermissions={['user:read']}><UsersPage /></PermissionRoute>} />
|
||||
<Route path="/roles" element={<PermissionRoute profile={profile} requiredPermissions={['role:read']}><RolesPage /></PermissionRoute>} />
|
||||
<Route path="/personnel" element={<PermissionRoute profile={profile} requiredPermissions={['admin-user:read']}><PersonnelPage /></PermissionRoute>} />
|
||||
<Route path="/profile" element={<PermissionRoute profile={profile}><ProfilePage /></PermissionRoute>} />
|
||||
<Route path="/logs" element={<PermissionRoute profile={profile} requiredPermissions={['log:read']}><LogsPage /></PermissionRoute>} />
|
||||
<Route path="*" element={<Navigate to="/dashboard" replace />} />
|
||||
</Routes>
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
);
|
||||
return (
|
||||
<Layout className="layout">
|
||||
<Sider className="sidebar" width={220} collapsed={collapsed} collapsible trigger={null}>
|
||||
<div className="logo-row">
|
||||
<span className="logo-mark">TK</span>
|
||||
{!collapsed && <span>TK短剧管理后台</span>}
|
||||
</div>
|
||||
<Menu
|
||||
selectedKeys={[current?.item.key || "/dashboard"]}
|
||||
openKeys={openMenuKeys}
|
||||
onClickMenuItem={(key) => navigate(key)}
|
||||
onClickSubMenu={(_, openKeys) => setOpenMenuKeys(openKeys)}
|
||||
>
|
||||
{visibleMenuItems.map((item) => renderMenuItem(item))}
|
||||
</Menu>
|
||||
</Sider>
|
||||
<Layout>
|
||||
<Header className="header">
|
||||
<Space>
|
||||
<Button icon={collapsed ? <IconMenuUnfold /> : <IconMenuFold />} onClick={() => setCollapsed(!collapsed)} />
|
||||
<div className="header-title">
|
||||
<strong>{current?.item.label || "工作台"}</strong>
|
||||
</div>
|
||||
</Space>
|
||||
<Dropdown
|
||||
position="br"
|
||||
trigger="click"
|
||||
droplist={
|
||||
<Menu>
|
||||
<Menu.Item key="profile" onClick={() => navigate("/profile")}>
|
||||
个人中心
|
||||
</Menu.Item>
|
||||
<Menu.Item key="logout" onClick={logout}>
|
||||
退出登录
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
<button className="user-menu-trigger" type="button">
|
||||
<Avatar size={28}>{profile?.username?.slice(0, 1).toUpperCase() || "A"}</Avatar>
|
||||
<Text>{profile?.nickname || profile?.username || "管理员"}</Text>
|
||||
</button>
|
||||
</Dropdown>
|
||||
</Header>
|
||||
<Content className="content">
|
||||
<Routes>
|
||||
<Route path="/dashboard" element={<DashboardPage profile={profile} />} />
|
||||
<Route
|
||||
path="/dramas"
|
||||
element={
|
||||
<PermissionRoute profile={profile} requiredPermissions={["drama:read"]}>
|
||||
<DramasPage />
|
||||
</PermissionRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/dramas/:id"
|
||||
element={
|
||||
<PermissionRoute profile={profile} requiredPermissions={["drama:read"]}>
|
||||
<DramasPage />
|
||||
</PermissionRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/data"
|
||||
element={
|
||||
<PermissionRoute profile={profile} requiredPermissions={["data:read"]}>
|
||||
<DataPage />
|
||||
</PermissionRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/users"
|
||||
element={
|
||||
<PermissionRoute profile={profile} requiredPermissions={["user:read"]}>
|
||||
<UsersPage />
|
||||
</PermissionRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/roles"
|
||||
element={
|
||||
<PermissionRoute profile={profile} requiredPermissions={["role:read"]}>
|
||||
<RolesPage />
|
||||
</PermissionRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/personnel"
|
||||
element={
|
||||
<PermissionRoute profile={profile} requiredPermissions={["admin-user:read"]}>
|
||||
<PersonnelPage />
|
||||
</PermissionRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/profile"
|
||||
element={
|
||||
<PermissionRoute profile={profile}>
|
||||
<ProfilePage />
|
||||
</PermissionRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/logs"
|
||||
element={
|
||||
<PermissionRoute profile={profile} requiredPermissions={["log:read"]}>
|
||||
<LogsPage />
|
||||
</PermissionRoute>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<Navigate to="/dashboard" replace />} />
|
||||
</Routes>
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user