|
@@ -3,6 +3,7 @@ import ModiyFormModal from '@/components/ModiyFormModal';
|
|
|
import ProTable from '@/components/ProTable';
|
|
import ProTable from '@/components/ProTable';
|
|
|
import { ModalTitleMap } from '@/constants/BasicConstants';
|
|
import { ModalTitleMap } from '@/constants/BasicConstants';
|
|
|
import { PlatformConstants } from '@/constants/PlatformConstants';
|
|
import { PlatformConstants } from '@/constants/PlatformConstants';
|
|
|
|
|
+import { ConfigStatusConstants } from '@/constants/StatusConstants';
|
|
|
import API from '@/services';
|
|
import API from '@/services';
|
|
|
import { guid } from '@/utils/utils';
|
|
import { guid } from '@/utils/utils';
|
|
|
import { PlusOutlined } from '@ant-design/icons';
|
|
import { PlusOutlined } from '@ant-design/icons';
|
|
@@ -10,16 +11,46 @@ import type { ActionType, ProColumns } from '@ant-design/pro-table';
|
|
|
import { Button, message, Space, Typography } from 'antd';
|
|
import { Button, message, Space, Typography } from 'antd';
|
|
|
import React, { useRef } from 'react';
|
|
import React, { useRef } from 'react';
|
|
|
|
|
|
|
|
-// 禁止挂网商品
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 平台配置
|
|
|
|
|
+ * 后端接口:
|
|
|
|
|
+ * - GET /collect_platform_config/index?page=&limit=
|
|
|
|
|
+ * - POST /collect_platform_config/add
|
|
|
|
|
+ * - POST /collect_platform_config/edit
|
|
|
|
|
+ * - POST /collect_platform_config/set_status
|
|
|
|
|
+ *
|
|
|
|
|
+ * 备注:后端 config 为统一 JSON 配置,约定 key:
|
|
|
|
|
+ * rest_duration(休息时长,分钟)、daily_max_pages(每日最大页数/条数,0=不限)
|
|
|
|
|
+ */
|
|
|
const PlatformConfig: React.FC = () => {
|
|
const PlatformConfig: React.FC = () => {
|
|
|
const actionRef = useRef<ActionType>();
|
|
const actionRef = useRef<ActionType>();
|
|
|
const proTableFormRef = useRef<any>();
|
|
const proTableFormRef = useRef<any>();
|
|
|
const downloadRef = useRef<any>({});
|
|
const downloadRef = useRef<any>({});
|
|
|
const modiyFormModalRef = useRef<any>();
|
|
const modiyFormModalRef = useRef<any>();
|
|
|
|
|
|
|
|
|
|
+ const flattenConfig = (record: any) => {
|
|
|
|
|
+ // 将后端返回的 config Map 拍平到 rowData,方便表单回显
|
|
|
|
|
+ const cfg = record?.config || {};
|
|
|
|
|
+ return {
|
|
|
|
|
+ platform: record?.platform,
|
|
|
|
|
+ rest_duration: cfg.rest_duration ?? 0,
|
|
|
|
|
+ daily_max_pages: cfg.daily_max_pages ?? 0,
|
|
|
|
|
+ status: record?.status,
|
|
|
|
|
+ };
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const buildConfigBody = (values: any) => {
|
|
|
|
|
+ // 将表单字段组装为后端要求的 config Map
|
|
|
|
|
+ return {
|
|
|
|
|
+ rest_duration: Number(values.rest_duration ?? 0),
|
|
|
|
|
+ daily_max_pages: Number(values.daily_max_pages ?? 0),
|
|
|
|
|
+ };
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const modiyManage = (type: 'create' | 'update', data: any = {}) => {
|
|
const modiyManage = (type: 'create' | 'update', data: any = {}) => {
|
|
|
const { hide } = Modal.show({
|
|
const { hide } = Modal.show({
|
|
|
- title: `${ModalTitleMap[type]}设备`,
|
|
|
|
|
|
|
+ title: `${ModalTitleMap[type]}平台配置`,
|
|
|
|
|
+ width: 560,
|
|
|
content: (
|
|
content: (
|
|
|
<ModiyFormModal
|
|
<ModiyFormModal
|
|
|
type={type}
|
|
type={type}
|
|
@@ -30,46 +61,29 @@ const PlatformConfig: React.FC = () => {
|
|
|
isRequired: true,
|
|
isRequired: true,
|
|
|
value: 'platform',
|
|
value: 'platform',
|
|
|
type: 'select',
|
|
type: 'select',
|
|
|
- options: Object?.entries(PlatformConstants)?.map(
|
|
|
|
|
- ([key, value]) => ({
|
|
|
|
|
- label: value,
|
|
|
|
|
|
|
+ options: Object?.entries(PlatformConstants)
|
|
|
|
|
+ ?.filter(([key]) => Number(key) !== 0)
|
|
|
|
|
+ ?.map(([key, value]) => ({
|
|
|
|
|
+ label: value as string,
|
|
|
value: Number(key),
|
|
value: Number(key),
|
|
|
- }),
|
|
|
|
|
- ),
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- label: '设备运行时长(分钟)',
|
|
|
|
|
- isRequired: true,
|
|
|
|
|
- value: 'duration',
|
|
|
|
|
- type: 'number',
|
|
|
|
|
|
|
+ })),
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- label: '运行后休息时长',
|
|
|
|
|
|
|
+ label: '休息时长(分钟)',
|
|
|
isRequired: true,
|
|
isRequired: true,
|
|
|
value: 'rest_duration',
|
|
value: 'rest_duration',
|
|
|
type: 'number',
|
|
type: 'number',
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- label: '每天运行次数',
|
|
|
|
|
- isRequired: true,
|
|
|
|
|
- value: 'day_number',
|
|
|
|
|
- type: 'number',
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- label: '每分钟采集数量',
|
|
|
|
|
- isRequired: true,
|
|
|
|
|
- value: 'minute_size',
|
|
|
|
|
- type: 'number',
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- label: '每页数量',
|
|
|
|
|
|
|
+ label: '每日最大页数/条数',
|
|
|
isRequired: true,
|
|
isRequired: true,
|
|
|
- value: 'page_size',
|
|
|
|
|
|
|
+ value: 'daily_max_pages',
|
|
|
type: 'number',
|
|
type: 'number',
|
|
|
|
|
+ help: '0 表示不限制',
|
|
|
},
|
|
},
|
|
|
]}
|
|
]}
|
|
|
ref={modiyFormModalRef}
|
|
ref={modiyFormModalRef}
|
|
|
- getDetail={() => data}
|
|
|
|
|
|
|
+ getDetail={() => flattenConfig(data)}
|
|
|
/>
|
|
/>
|
|
|
),
|
|
),
|
|
|
onOk: async () => {
|
|
onOk: async () => {
|
|
@@ -82,18 +96,19 @@ const PlatformConfig: React.FC = () => {
|
|
|
throw new Error('表单校验未通过');
|
|
throw new Error('表单校验未通过');
|
|
|
}
|
|
}
|
|
|
const values = formInstance.getData();
|
|
const values = formInstance.getData();
|
|
|
- const response = ['create'].includes(type)
|
|
|
|
|
- ? await API.CollectTask.addCollectPlatformConfig(values)
|
|
|
|
|
- : await API.CollectTask.editCollectPlatformConfig({
|
|
|
|
|
- id: data.id,
|
|
|
|
|
- ...values,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const config = buildConfigBody(values);
|
|
|
|
|
+ const platform = Number(values.platform);
|
|
|
|
|
+ const payload = { platform, config };
|
|
|
|
|
+ const response =
|
|
|
|
|
+ type === 'create'
|
|
|
|
|
+ ? await API.PlatformConfig.add(payload)
|
|
|
|
|
+ : await API.PlatformConfig.edit({ id: data.id, ...payload });
|
|
|
if (response.code === 'success') {
|
|
if (response.code === 'success') {
|
|
|
- message.success('操作成功');
|
|
|
|
|
|
|
+ message.success(type === 'create' ? '创建成功' : '更新成功');
|
|
|
actionRef.current?.reload();
|
|
actionRef.current?.reload();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- throw new Error(response?.message || '操作失败');
|
|
|
|
|
|
|
+ throw new Error(response?.msg || '操作失败');
|
|
|
},
|
|
},
|
|
|
onCancel: () => {
|
|
onCancel: () => {
|
|
|
hide();
|
|
hide();
|
|
@@ -117,45 +132,47 @@ const PlatformConfig: React.FC = () => {
|
|
|
valueEnum: PlatformConstants,
|
|
valueEnum: PlatformConstants,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- title: '每次任务时长(分钟)',
|
|
|
|
|
- dataIndex: 'duration',
|
|
|
|
|
- key: 'duration',
|
|
|
|
|
- hideInSearch: true,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title: '每次任务休息时长(分钟)',
|
|
|
|
|
- dataIndex: 'rest_duration',
|
|
|
|
|
|
|
+ title: '休息时长(分钟)',
|
|
|
|
|
+ dataIndex: ['config', 'rest_duration'],
|
|
|
key: 'rest_duration',
|
|
key: 'rest_duration',
|
|
|
hideInSearch: true,
|
|
hideInSearch: true,
|
|
|
|
|
+ renderText: (_, record: any) => record?.config?.rest_duration ?? '-',
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- title: '每天任务次数',
|
|
|
|
|
- dataIndex: 'day_number',
|
|
|
|
|
- key: 'day_number',
|
|
|
|
|
|
|
+ title: '每日最大页数/条数',
|
|
|
|
|
+ dataIndex: ['config', 'daily_max_pages'],
|
|
|
|
|
+ key: 'daily_max_pages',
|
|
|
hideInSearch: true,
|
|
hideInSearch: true,
|
|
|
|
|
+ renderText: (_, record: any) =>
|
|
|
|
|
+ record?.config?.daily_max_pages === 0
|
|
|
|
|
+ ? '不限'
|
|
|
|
|
+ : record?.config?.daily_max_pages ?? '-',
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- title: '每分钟采集数量/条',
|
|
|
|
|
- dataIndex: 'minute_size',
|
|
|
|
|
- key: 'minute_size',
|
|
|
|
|
|
|
+ title: '状态',
|
|
|
|
|
+ dataIndex: 'status',
|
|
|
|
|
+ key: 'status',
|
|
|
hideInSearch: true,
|
|
hideInSearch: true,
|
|
|
|
|
+ valueType: 'select',
|
|
|
|
|
+ valueEnum: ConfigStatusConstants,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- title: '每页数量',
|
|
|
|
|
- dataIndex: 'page_size',
|
|
|
|
|
- key: 'page_size',
|
|
|
|
|
|
|
+ title: '创建时间',
|
|
|
|
|
+ dataIndex: 'insert_time',
|
|
|
|
|
+ key: 'insert_time',
|
|
|
hideInSearch: true,
|
|
hideInSearch: true,
|
|
|
|
|
+ valueType: 'dateTime',
|
|
|
|
|
+ renderText: (val) =>
|
|
|
|
|
+ typeof val === 'number' && val < 1e12 ? val * 1000 : val,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- title: '状态',
|
|
|
|
|
- dataIndex: 'status',
|
|
|
|
|
- key: 'status',
|
|
|
|
|
|
|
+ title: '更新时间',
|
|
|
|
|
+ dataIndex: 'update_time',
|
|
|
|
|
+ key: 'update_time',
|
|
|
hideInSearch: true,
|
|
hideInSearch: true,
|
|
|
- valueType: 'select',
|
|
|
|
|
- valueEnum: {
|
|
|
|
|
- 0: '启用',
|
|
|
|
|
- 1: '禁用',
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ valueType: 'dateTime',
|
|
|
|
|
+ renderText: (val) =>
|
|
|
|
|
+ typeof val === 'number' && val < 1e12 ? val * 1000 : val,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
title: '操作',
|
|
title: '操作',
|
|
@@ -165,23 +182,21 @@ const PlatformConfig: React.FC = () => {
|
|
|
fixed: 'right',
|
|
fixed: 'right',
|
|
|
render: (text, record) => {
|
|
render: (text, record) => {
|
|
|
void text;
|
|
void text;
|
|
|
- void record;
|
|
|
|
|
return (
|
|
return (
|
|
|
<Space key={guid()}>
|
|
<Space key={guid()}>
|
|
|
<Typography.Link
|
|
<Typography.Link
|
|
|
style={{ color: record.status == 0 ? 'red' : 'green' }}
|
|
style={{ color: record.status == 0 ? 'red' : 'green' }}
|
|
|
onClick={async () => {
|
|
onClick={async () => {
|
|
|
- const response =
|
|
|
|
|
- await API.CollectTask.setCollectPlatformConfigStatus({
|
|
|
|
|
- id: record.id,
|
|
|
|
|
- status: record.status == 0 ? 1 : 0,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const response = await API.PlatformConfig.setStatus({
|
|
|
|
|
+ id: record.id,
|
|
|
|
|
+ status: record.status == 0 ? 1 : 0,
|
|
|
|
|
+ });
|
|
|
if (response.code === 'success') {
|
|
if (response.code === 'success') {
|
|
|
message.success('操作成功');
|
|
message.success('操作成功');
|
|
|
actionRef.current?.reload();
|
|
actionRef.current?.reload();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- throw new Error(response?.message || '操作失败');
|
|
|
|
|
|
|
+ throw new Error(response?.msg || '操作失败');
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
{record.status == 0 ? '禁用' : '启用'}
|
|
{record.status == 0 ? '禁用' : '启用'}
|
|
@@ -202,7 +217,7 @@ const PlatformConfig: React.FC = () => {
|
|
|
formRef={proTableFormRef}
|
|
formRef={proTableFormRef}
|
|
|
request={async (params) => {
|
|
request={async (params) => {
|
|
|
downloadRef.current = params;
|
|
downloadRef.current = params;
|
|
|
- const res = await API.CollectTask.collectPlatformConfig(params);
|
|
|
|
|
|
|
+ const res = await API.PlatformConfig.list(params);
|
|
|
return {
|
|
return {
|
|
|
data: res.data?.data || [],
|
|
data: res.data?.data || [],
|
|
|
total: res.data?.total || 0,
|
|
total: res.data?.total || 0,
|
|
@@ -217,14 +232,14 @@ const PlatformConfig: React.FC = () => {
|
|
|
toolbar={{
|
|
toolbar={{
|
|
|
actions: [
|
|
actions: [
|
|
|
<Button
|
|
<Button
|
|
|
- key="export_excel"
|
|
|
|
|
|
|
+ key="add"
|
|
|
type="primary"
|
|
type="primary"
|
|
|
icon={<PlusOutlined />}
|
|
icon={<PlusOutlined />}
|
|
|
onClick={() => {
|
|
onClick={() => {
|
|
|
modiyManage('create');
|
|
modiyManage('create');
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
- 新增设备
|
|
|
|
|
|
|
+ 新增平台配置
|
|
|
</Button>,
|
|
</Button>,
|
|
|
],
|
|
],
|
|
|
}}
|
|
}}
|