浏览代码

新增区域管理功能,采集任务和平台账号增加区域筛选,采集任务增加完成账号字段

hechuanqi 1 月之前
父节点
当前提交
9ac4fa4884

+ 7 - 0
.umirc.ts

@@ -62,6 +62,13 @@ export default defineConfig({
       icon: 'AppstoreOutlined',
       component: './PlatformManage',
     },
+    // 区域管理
+    {
+      name: '区域管理',
+      path: '/region_manage',
+      icon: 'EnvironmentOutlined',
+      component: './RegionManage',
+    },
     // 平台账号(仅查看和启用/禁用,账号由心跳上报自动维护)
     {
       name: '平台账号',

+ 26 - 0
src/pages/CollectionTask/index.tsx

@@ -20,6 +20,9 @@ const CollectionTask: React.FC = () => {
   const [platformOptions, setPlatformOptions] = useState<
     { label: string; value: number }[]
   >([]);
+  const [regionOptions, setRegionOptions] = useState<
+    { label: string; value: number }[]
+  >([]);
 
   useEffect(() => {
     API.CollectPlatform.selectOptions().then((res: any) => {
@@ -27,6 +30,11 @@ const CollectionTask: React.FC = () => {
         setPlatformOptions(res.data || []);
       }
     });
+    API.CollectRegion.selectOptions().then((res: any) => {
+      if (res?.code === 'success') {
+        setRegionOptions(res.data || []);
+      }
+    });
   }, []);
 
   const columns: ProColumns[] = [
@@ -50,6 +58,17 @@ const CollectionTask: React.FC = () => {
       fieldProps: { options: platformOptions },
       renderText: (_, record: any) => record?.platform_name ?? '-',
     },
+    {
+      title: '区域',
+      dataIndex: 'region_id',
+      key: 'region_id',
+      valueType: 'select',
+      fieldProps: { options: regionOptions },
+      renderText: (_, record: any) => {
+        if (!record?.region_id || record.region_id === 0) return '不限区域';
+        return record?.region_name ?? '-';
+      },
+    },
     {
       title: '采集日期',
       dataIndex: 'date_range',
@@ -112,6 +131,13 @@ const CollectionTask: React.FC = () => {
       hideInSearch: true,
       key: 'account_username',
     },
+    {
+      title: '完成账号',
+      dataIndex: 'completed_account_username',
+      hideInSearch: true,
+      key: 'completed_account_username',
+      renderText: (val) => val ?? '-',
+    },
     {
       title: '任务状态',
       dataIndex: 'status',

+ 19 - 0
src/pages/PlatformAccount/index.tsx

@@ -21,6 +21,9 @@ const PlatformAccount: React.FC = () => {
   const [platformOptions, setPlatformOptions] = useState<
     { label: string; value: number }[]
   >([]);
+  const [regionOptions, setRegionOptions] = useState<
+    { label: string; value: number }[]
+  >([]);
 
   useEffect(() => {
     API.CollectPlatform.selectOptions().then((res: any) => {
@@ -28,6 +31,11 @@ const PlatformAccount: React.FC = () => {
         setPlatformOptions(res.data || []);
       }
     });
+    API.CollectRegion.selectOptions().then((res: any) => {
+      if (res?.code === 'success') {
+        setRegionOptions(res.data || []);
+      }
+    });
   }, []);
 
   const columns: ProColumns[] = [
@@ -46,6 +54,17 @@ const PlatformAccount: React.FC = () => {
       fieldProps: { options: platformOptions },
       renderText: (_, record: any) => record?.platform_name ?? '-',
     },
+    {
+      title: '区域',
+      dataIndex: 'region_id',
+      key: 'region_id',
+      valueType: 'select',
+      fieldProps: { options: regionOptions },
+      renderText: (_, record: any) => {
+        if (!record?.region_id || record.region_id === 0) return '不限区域';
+        return record?.region_name ?? '-';
+      },
+    },
     {
       title: '账号名称',
       dataIndex: 'account_username',

+ 190 - 0
src/pages/RegionManage/index.tsx

@@ -0,0 +1,190 @@
+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';
+
+/**
+ * 区域管理
+ * 后端接口(CollectRegionController):
+ * - GET  /region/list          区域列表(可选 status 过滤)
+ * - POST /region/add           新增区域(name 必填)
+ * - POST /region/edit          编辑区域(id 必填)
+ * - POST /region/set_status    设置区域状态
+ */
+const RegionManage: React.FC = () => {
+  const actionRef = useRef<ActionType>();
+  const proTableFormRef = 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: 'name',
+              type: 'input',
+            },
+          ]}
+          ref={modiyFormModalRef}
+          getDetail={() => ({
+            name: data?.name,
+          })}
+        />
+      ),
+      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 = {
+          name: String(values.name).trim(),
+        };
+        const response =
+          type === 'create'
+            ? await API.CollectRegion.add(payload)
+            : await API.CollectRegion.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: 'name',
+      key: 'name',
+      hideInSearch: true,
+    },
+    {
+      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.CollectRegion.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) => {
+        const res = await API.CollectRegion.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 RegionManage;

+ 53 - 0
src/services/collect_region.ts

@@ -0,0 +1,53 @@
+import BaseAPI from './BaseAPI';
+
+/**
+ * 采集区域 Service
+ * 后端接口(CollectRegionController):
+ * - GET  /region/select_options     区域下拉选项(仅启用)
+ * - GET  /region/list               区域列表(可选 status 过滤)
+ * - POST /region/add                新增区域
+ * - POST /region/edit               编辑区域
+ * - POST /region/set_status         设置区域状态
+ */
+class CollectRegionAPI extends BaseAPI {
+  constructor() {
+    super(``);
+  }
+
+  /** 区域下拉选项(仅启用,返回 [{value, label}]) */
+  selectOptions() {
+    return this._get({ path: `/region/select_options` }).then((data) => {
+      return data;
+    });
+  }
+
+  /** 查询区域列表(status 可选:0=启用,1=禁用,不传=全部) */
+  list(data?: any) {
+    return this._get({ path: `/region/list`, data }).then((data) => {
+      return data;
+    });
+  }
+
+  /** 新增区域 */
+  add(data: { name: string; status?: number }) {
+    return this._post({ path: `/region/add`, data }).then((data) => {
+      return data;
+    });
+  }
+
+  /** 编辑区域 */
+  edit(data: { id: number; name?: string; status?: number }) {
+    return this._post({ path: `/region/edit`, data }).then((data) => {
+      return data;
+    });
+  }
+
+  /** 设置区域状态(0=启用,1=禁用) */
+  setStatus(data: { id: number; status: number }) {
+    return this._post({ path: `/region/set_status`, data }).then((data) => {
+      return data;
+    });
+  }
+}
+
+export default new CollectRegionAPI();

+ 2 - 0
src/services/index.ts

@@ -1,5 +1,6 @@
 import CollectPlatform from './collect_platform';
 import CollectPlatformAccount from './collect_platform_account';
+import CollectRegion from './collect_region';
 import CollectTask from './collect_task';
 import Dashboard from './dashboard';
 import Login from './login';
@@ -10,6 +11,7 @@ export default {
   CollectTask,
   CollectPlatform,
   CollectPlatformAccount,
+  CollectRegion,
   Dashboard,
   PlatformConfig,
 };