123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- import { PageContainer } from '@ant-design/pro-components';
- import React, { useEffect, useState } from 'react';
- import { Button, Card, Form, Input, message, Modal, Select, Space, Table } from 'antd';
- import { PlusCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
- import Edit from '@/pages/EditionManagement/edit';
- import type { ColumnsType } from 'antd/es/table';
- import moment from 'moment/moment';
- import { delEdition, queryEdition } from '@/services/EditionManagement';
- interface DataType {
- version: string;
- platform: string;
- creator: string;
- download_url: string;
- created_at: string;
- record_id: string;
- content: string;
- }
- /**
- * 版本管理
- * @constructor
- */
- const EditionManagement: 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,
- };
- queryEdition(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);
- });
- };
- useEffect(() => {
- getList();
- }, [searchData]);
- // 重置
- 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,
- };
- queryEdition(params).then((res) => {
- if (res.code === 0) {
- setDataList(res.data.list);
- setPagination(res.data.pagination);
- setLoading(false);
- }
- });
- };
- // 删除
- const toDel = (record: any) => {
- Modal.confirm({
- title: '删除',
- content: `是否确认删除${record.version}版本`,
- onOk: () => {
- delEdition(record?.record_id)
- .then((res) => {
- if (res.code === 0) {
- message.success('删除成功');
- } else {
- message.error('删除失败');
- }
- getList();
- })
- .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: 'version',
- key: 'version',
- },
- {
- title: '设备类型',
- dataIndex: 'platform',
- key: 'platform',
- render: (v) => v && <span>{{ ANDROID: '安卓', IOS: 'iphone' }[v]}</span>,
- },
- {
- title: '是否强制更新',
- dataIndex: 'force_update',
- key: 'force_update',
- render: (v) => (
- <span style={{ color: `${v ? 'red' : 'green'}` }}>{v ? '强制' : '不强制'}</span>
- ),
- },
- {
- title: '创建时间',
- dataIndex: 'created_at',
- key: 'created_at',
- render: (v) => v && <span>{moment(v).format('YYYY-MM-DD HH:mm')}</span>,
- },
- {
- title: 'apk下载地址',
- dataIndex: 'download_url',
- key: 'download_url',
- render: (v) =>
- v && (
- <a href={v} target="_blank" rel="noreferrer">
- {v}
- </a>
- ),
- },
- {
- title: '更新内容',
- dataIndex: 'content',
- key: 'content',
- },
- {
- title: '创建者',
- dataIndex: 'creator',
- key: 'creator',
- },
- {
- 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="version" label="版本号">
- <Input placeholder="请输入版本号" />
- </Form.Item>
- <Form.Item name="platform" label="设备类型">
- <Select placeholder="请选择设备类型" style={{ width: '175px' }}>
- <Select.Option value="IOS">iphone</Select.Option>
- <Select.Option value="ANDROID">安卓</Select.Option>
- </Select>
- </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 EditionManagement;
|