|
@@ -0,0 +1,214 @@
|
|
|
|
+import React, { useEffect, useState } from 'react';
|
|
|
|
+import { Button, Card, Form, Input, message, Modal, Space, Table } from 'antd';
|
|
|
|
+import type { ColumnsType } from 'antd/es/table';
|
|
|
|
+import moment from 'moment/moment';
|
|
|
|
+import { PlusCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
|
|
|
|
+import Edit from '@/pages/cms/ArticleManagement/edit';
|
|
|
|
+import { PageContainer } from '@ant-design/pro-components';
|
|
|
|
+import { queryArticle, delArticle } from '@/services/cms/ArticleManagement';
|
|
|
|
+
|
|
|
|
+interface DataType {
|
|
|
|
+ title: string;
|
|
|
|
+ content: string;
|
|
|
|
+ created_at: string;
|
|
|
|
+ creator: string;
|
|
|
|
+ record_id: string;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 文章管理
|
|
|
|
+ * @constructor
|
|
|
|
+ */
|
|
|
|
+const ArticleManagement: React.FC = () => {
|
|
|
|
+ const [form] = Form.useForm();
|
|
|
|
+ const [loading, setLoading] = useState(false);
|
|
|
|
+ const [searchData, setSearchData] = useState<object | null>({});
|
|
|
|
+ const [visible, setVisible] = useState(false);
|
|
|
|
+ const [editData, setEditData] = useState(null);
|
|
|
|
+ const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 });
|
|
|
|
+ const [dataList, setDataList]: any = useState([]);
|
|
|
|
+
|
|
|
|
+ // 获取列表数据
|
|
|
|
+ const getList = () => {
|
|
|
|
+ const params = {
|
|
|
|
+ q: 'page',
|
|
|
|
+ current: pagination.current,
|
|
|
|
+ pageSize: pagination.pageSize,
|
|
|
|
+ ...searchData,
|
|
|
|
+ };
|
|
|
|
+ queryArticle(params).then((res) => {
|
|
|
|
+ if (res && res.code === 0) {
|
|
|
|
+ setDataList(res.data.list);
|
|
|
|
+ setPagination(res.data.pagination);
|
|
|
|
+ setLoading(false);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ setLoading(true);
|
|
|
|
+ getList();
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
|
|
+ // 搜索
|
|
|
|
+ const onFinish = () => {
|
|
|
|
+ form.validateFields().then((data) => {
|
|
|
|
+ setLoading(true);
|
|
|
|
+ setSearchData(data);
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+ // 重置
|
|
|
|
+ const onReset = () => {
|
|
|
|
+ form.resetFields();
|
|
|
|
+ setLoading(true);
|
|
|
|
+ setSearchData(null);
|
|
|
|
+ };
|
|
|
|
+ // 新增弹框
|
|
|
|
+ const onAdd = () => {
|
|
|
|
+ setEditData(null);
|
|
|
|
+ setVisible(true);
|
|
|
|
+ };
|
|
|
|
+ // 打开编辑弹框
|
|
|
|
+ const toEdit = (data: any) => {
|
|
|
|
+ setEditData(data);
|
|
|
|
+ setVisible(true);
|
|
|
|
+ };
|
|
|
|
+ // 分页切换
|
|
|
|
+ const tableChange = (page: any) => {
|
|
|
|
+ setLoading(true);
|
|
|
|
+ const params = {
|
|
|
|
+ q: 'page',
|
|
|
|
+ current: page.current,
|
|
|
|
+ pageSize: page.pageSize,
|
|
|
|
+ ...searchData,
|
|
|
|
+ };
|
|
|
|
+ queryArticle(params).then((res) => {
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
+ setDataList(res.data.list);
|
|
|
|
+ setPagination(res.data.pagination);
|
|
|
|
+ setLoading(false);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+ // 删除
|
|
|
|
+ const toDel = (record: any) => {
|
|
|
|
+ console.log(record);
|
|
|
|
+ Modal.confirm({
|
|
|
|
+ title: '删除',
|
|
|
|
+ content: `确认删除项目:[${record.name}]`,
|
|
|
|
+ onOk: () => {
|
|
|
|
+ delArticle(record?.record_id)
|
|
|
|
+ .then((res) => {
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
+ message.success('删除成功');
|
|
|
|
+ } else {
|
|
|
|
+ message.error('删除失败');
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((e) => {
|
|
|
|
+ message.error(e?.message);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+ // 编辑弹框回调
|
|
|
|
+ const handleEdit = () => {
|
|
|
|
+ setVisible(false);
|
|
|
|
+ getList();
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const columns: ColumnsType<DataType> = [
|
|
|
|
+ {
|
|
|
|
+ title: '序号',
|
|
|
|
+ align: 'center',
|
|
|
|
+ key: 'index',
|
|
|
|
+ render: (_: any, row: any, index: number) => index + 1,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '文章标题',
|
|
|
|
+ dataIndex: 'title',
|
|
|
|
+ key: 'title',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '创建者',
|
|
|
|
+ dataIndex: 'creator',
|
|
|
|
+ key: 'creator',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '创建时间',
|
|
|
|
+ dataIndex: 'created_at',
|
|
|
|
+ key: 'created_at',
|
|
|
|
+ render: (v) => v && <span>{moment(v).format('YYYY-MM-DD HH:mm')}</span>,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '操作',
|
|
|
|
+ key: 'action',
|
|
|
|
+ render: (_, record) => (
|
|
|
|
+ <Space size="middle">
|
|
|
|
+ <a
|
|
|
|
+ onClick={() => {
|
|
|
|
+ toEdit(record);
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ 编辑
|
|
|
|
+ </a>
|
|
|
|
+ <a
|
|
|
|
+ style={{ color: 'red' }}
|
|
|
|
+ onClick={() => {
|
|
|
|
+ toDel(record);
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ 删除
|
|
|
|
+ </a>
|
|
|
|
+ </Space>
|
|
|
|
+ ),
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+ const paginationProps = {
|
|
|
|
+ showSizeChanger: true,
|
|
|
|
+ showQuickJumper: true,
|
|
|
|
+ showTotal: (total: number) => {
|
|
|
|
+ return <span> 共 {total}条 </span>;
|
|
|
|
+ },
|
|
|
|
+ ...pagination,
|
|
|
|
+ };
|
|
|
|
+ return (
|
|
|
|
+ <PageContainer>
|
|
|
|
+ <div>
|
|
|
|
+ <Card>
|
|
|
|
+ <Form form={form} layout="inline" onFinish={onFinish}>
|
|
|
|
+ <Form.Item name="title" label="文章标题">
|
|
|
|
+ <Input placeholder="请输入文章标题" />
|
|
|
|
+ </Form.Item>
|
|
|
|
+ <Form.Item style={{ marginBottom: '10px' }}>
|
|
|
|
+ <Space>
|
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
|
+ <SearchOutlined />
|
|
|
|
+ 查询
|
|
|
|
+ </Button>
|
|
|
|
+ <Button htmlType="button" onClick={onReset}>
|
|
|
|
+ <ReloadOutlined />
|
|
|
|
+ 重置
|
|
|
|
+ </Button>
|
|
|
|
+ </Space>
|
|
|
|
+ </Form.Item>
|
|
|
|
+ </Form>
|
|
|
|
+ <Button htmlType="button" type="primary" style={{ margin: '20px 0' }} onClick={onAdd}>
|
|
|
|
+ <PlusCircleOutlined />
|
|
|
|
+ 新增文章
|
|
|
|
+ </Button>
|
|
|
|
+ <Table
|
|
|
|
+ columns={columns}
|
|
|
|
+ dataSource={dataList}
|
|
|
|
+ rowKey={(record) => record.record_id}
|
|
|
|
+ pagination={paginationProps}
|
|
|
|
+ loading={loading}
|
|
|
|
+ onChange={tableChange}
|
|
|
|
+ />
|
|
|
|
+ {visible && <Edit visible={visible} editCallback={handleEdit} params={editData} />}
|
|
|
|
+ </Card>
|
|
|
|
+ </div>
|
|
|
|
+ </PageContainer>
|
|
|
|
+ );
|
|
|
|
+};
|
|
|
|
+export default ArticleManagement;
|