|
|
@@ -0,0 +1,228 @@
|
|
|
+import Modal from '@/components/Modal';
|
|
|
+import ModiyFormModal from '@/components/ModiyFormModal';
|
|
|
+import ProTable from '@/components/ProTable';
|
|
|
+import { ModalTitleMap } from '@/constants/BasicConstants';
|
|
|
+import { ConfigStatusConstants } from '@/constants/StatusConstants';
|
|
|
+import API from '@/services';
|
|
|
+import { guid } from '@/utils/utils';
|
|
|
+import { PlusOutlined } from '@ant-design/icons';
|
|
|
+import type { ActionType, ProColumns } from '@ant-design/pro-table';
|
|
|
+import { Button, message, Space, Typography } from 'antd';
|
|
|
+import React, { useRef } from 'react';
|
|
|
+
|
|
|
+/**
|
|
|
+ * 平台维护
|
|
|
+ * 后端接口(CollectPlatformController):
|
|
|
+ * - GET /collect_platform/list 平台列表(可选 status 过滤)
|
|
|
+ * - POST /collect_platform/add 新增平台(code + name 必填)
|
|
|
+ * - POST /collect_platform/edit 编辑平台(id 必填)
|
|
|
+ * - POST /collect_platform/set_status 设置平台状态
|
|
|
+ *
|
|
|
+ * VO 字段:id, code, name, sort_order, status, insert_time, update_time
|
|
|
+ * DTO 字段:id, code, name, sortOrder, status
|
|
|
+ */
|
|
|
+const PlatformManage: React.FC = () => {
|
|
|
+ const actionRef = useRef<ActionType>();
|
|
|
+ const proTableFormRef = useRef<any>();
|
|
|
+ const downloadRef = useRef<any>({});
|
|
|
+ const modiyFormModalRef = useRef<any>();
|
|
|
+
|
|
|
+ const modiyManage = (type: 'create' | 'update', data: any = {}) => {
|
|
|
+ const { hide } = Modal.show({
|
|
|
+ title: `${ModalTitleMap[type]}平台`,
|
|
|
+ width: 560,
|
|
|
+ content: (
|
|
|
+ <ModiyFormModal
|
|
|
+ type={type}
|
|
|
+ formOptions={{ labelCol: 8, labelAlign: 'right' }}
|
|
|
+ formList={[
|
|
|
+ {
|
|
|
+ label: '平台编码',
|
|
|
+ isRequired: true,
|
|
|
+ value: 'code',
|
|
|
+ type: 'number',
|
|
|
+ help: '全局唯一编码,创建后不可修改',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '平台名称',
|
|
|
+ isRequired: true,
|
|
|
+ value: 'name',
|
|
|
+ type: 'input',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '排序',
|
|
|
+ isRequired: false,
|
|
|
+ value: 'sort_order',
|
|
|
+ type: 'number',
|
|
|
+ help: '值越小越靠前,默认为 0',
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ ref={modiyFormModalRef}
|
|
|
+ getDetail={() => ({
|
|
|
+ code: data?.code,
|
|
|
+ name: data?.name,
|
|
|
+ sort_order: data?.sort_order ?? 0,
|
|
|
+ })}
|
|
|
+ />
|
|
|
+ ),
|
|
|
+ onOk: async () => {
|
|
|
+ const formInstance = modiyFormModalRef.current;
|
|
|
+ if (!formInstance) {
|
|
|
+ throw new Error('表单未初始化');
|
|
|
+ }
|
|
|
+ const isFormValid = await formInstance.validateForm();
|
|
|
+ if (!isFormValid) {
|
|
|
+ throw new Error('表单校验未通过');
|
|
|
+ }
|
|
|
+ const values = formInstance.getData();
|
|
|
+ const payload = {
|
|
|
+ code: Number(values.code),
|
|
|
+ name: String(values.name).trim(),
|
|
|
+ sortOrder: Number(values.sort_order ?? 0),
|
|
|
+ };
|
|
|
+ const response =
|
|
|
+ type === 'create'
|
|
|
+ ? await API.CollectPlatform.add(payload)
|
|
|
+ : await API.CollectPlatform.edit({ id: data.id, ...payload });
|
|
|
+ if (response.code === 'success') {
|
|
|
+ message.success(type === 'create' ? '创建成功' : '更新成功');
|
|
|
+ actionRef.current?.reload();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ throw new Error(response?.msg || '操作失败');
|
|
|
+ },
|
|
|
+ onCancel: () => {
|
|
|
+ hide();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const columns: ProColumns[] = [
|
|
|
+ {
|
|
|
+ title: 'ID',
|
|
|
+ dataIndex: 'id',
|
|
|
+ key: 'id',
|
|
|
+ hideInSearch: true,
|
|
|
+ width: 80,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '平台编码',
|
|
|
+ dataIndex: 'code',
|
|
|
+ key: 'code',
|
|
|
+ hideInSearch: true,
|
|
|
+ width: 100,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '平台名称',
|
|
|
+ dataIndex: 'name',
|
|
|
+ key: 'name',
|
|
|
+ hideInSearch: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '排序',
|
|
|
+ dataIndex: 'sort_order',
|
|
|
+ key: 'sort_order',
|
|
|
+ hideInSearch: true,
|
|
|
+ width: 80,
|
|
|
+ renderText: (_, record: any) => record?.sort_order ?? '-',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '状态',
|
|
|
+ dataIndex: 'status',
|
|
|
+ key: 'status',
|
|
|
+ hideInSearch: true,
|
|
|
+ valueType: 'select',
|
|
|
+ valueEnum: ConfigStatusConstants,
|
|
|
+ width: 100,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '创建时间',
|
|
|
+ dataIndex: 'insert_time',
|
|
|
+ key: 'insert_time',
|
|
|
+ hideInSearch: true,
|
|
|
+ valueType: 'dateTime',
|
|
|
+ renderText: (val) =>
|
|
|
+ typeof val === 'number' && val < 1e12 ? val * 1000 : val,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '更新时间',
|
|
|
+ dataIndex: 'update_time',
|
|
|
+ key: 'update_time',
|
|
|
+ hideInSearch: true,
|
|
|
+ valueType: 'dateTime',
|
|
|
+ renderText: (val) =>
|
|
|
+ typeof val === 'number' && val < 1e12 ? val * 1000 : val,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'option',
|
|
|
+ key: 'option',
|
|
|
+ valueType: 'option',
|
|
|
+ fixed: 'right',
|
|
|
+ width: 140,
|
|
|
+ render: (text, record) => {
|
|
|
+ void text;
|
|
|
+ return (
|
|
|
+ <Space key={guid()}>
|
|
|
+ <Typography.Link
|
|
|
+ style={{ color: record.status === 0 ? 'red' : 'green' }}
|
|
|
+ onClick={async () => {
|
|
|
+ const response = await API.CollectPlatform.setStatus({
|
|
|
+ id: record.id,
|
|
|
+ status: record.status === 0 ? 1 : 0,
|
|
|
+ });
|
|
|
+ if (response.code === 'success') {
|
|
|
+ message.success('操作成功');
|
|
|
+ actionRef.current?.reload();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ throw new Error(response?.msg || '操作失败');
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {record.status === 0 ? '禁用' : '启用'}
|
|
|
+ </Typography.Link>
|
|
|
+ <Typography.Link onClick={() => modiyManage('update', record)}>
|
|
|
+ 编辑
|
|
|
+ </Typography.Link>
|
|
|
+ </Space>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+
|
|
|
+ return (
|
|
|
+ <ProTable
|
|
|
+ columns={columns}
|
|
|
+ actionRef={actionRef}
|
|
|
+ formRef={proTableFormRef}
|
|
|
+ request={async (params) => {
|
|
|
+ downloadRef.current = params;
|
|
|
+ const res = await API.CollectPlatform.list(params);
|
|
|
+ return {
|
|
|
+ data: res.data || [],
|
|
|
+ total: res.data?.length || 0,
|
|
|
+ success: true,
|
|
|
+ };
|
|
|
+ }}
|
|
|
+ editable={{ type: 'multiple' }}
|
|
|
+ scroll={{ x: '120%' }}
|
|
|
+ noSearch
|
|
|
+ toolbar={{
|
|
|
+ actions: [
|
|
|
+ <Button
|
|
|
+ key="add"
|
|
|
+ type="primary"
|
|
|
+ icon={<PlusOutlined />}
|
|
|
+ onClick={() => {
|
|
|
+ modiyManage('create');
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 新增平台
|
|
|
+ </Button>,
|
|
|
+ ],
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default PlatformManage;
|