Browse Source

feat: 任务中心

张敬 5 years ago
parent
commit
6176c75dda

+ 5 - 0
.prettierrc.js

@@ -0,0 +1,5 @@
+const fabric = require('@umijs/fabric');
+
+module.exports = {
+  ...fabric.prettier,
+};

+ 14 - 23
src/conf/config.js

@@ -1,29 +1,20 @@
-let dc = '/back-apit/api'
-let tc = '/back-apit/api'
-let us = '/back-apit/api'
-const apiCdn = 'http://cdn01t.weipaitang.com/img/'
-let auth = '/back-autht/api'
-const hostDev = `${window.location.protocol}//${window.location.host}`
-const sTaskJobLog = 'http://ms-trace.weipaitang.com' // 定时任务日志跳转
-let thanos = '/thanos-admint/api'
+let dc = '/back-apit/api';
+let tc = '/back-apit/api';
+let us = '/back-apit/api';
+const apiCdn = 'http://cdn01t.weipaitang.com/img/';
+let auth = '/back-autht/api';
+const hostDev = `${window.location.protocol}//${window.location.host}`;
+const sTaskJobLog = 'http://ms-trace.weipaitang.com'; // 定时任务日志跳转
+let thanos = '/thanos-admint/api';
 // let thanos = 'http://localhost:7070'
 
 if (document.domain === 'back-admin.weipaitang.com') {
-  dc = '/back-api/api'
-  tc = '/back-api/api'
-  auth = '/back-auth/api'
-  us = '/back-api/api'
+  dc = '/back-api/api';
+  tc = '/back-api/api';
+  auth = '/back-auth/api';
+  us = '/back-api/api';
   // sTaskJobLog = '/ms-trace/api' // 定时任务日志跳转
-  thanos = '/thanos-admin/api'
+  thanos = '/thanos-admin/api';
 }
 
-export {
-  dc,
-  tc,
-  us,
-  apiCdn,
-  auth,
-  hostDev,
-  sTaskJobLog,
-  thanos
-}
+export { dc, tc, us, apiCdn, auth, hostDev, sTaskJobLog, thanos };

+ 2 - 2
src/conf/proxyMap.js

@@ -8,5 +8,5 @@ module.exports = {
   '/back-auth/api': 'https://back-auth.weipaitang.com',
   '/back-api/api': 'http://back-api.weipaitang.com',
   '/ms-trace/api': 'http://ms-trace.weipaitang.com',
-  '/thanos-admin/api': 'http://thanos-admin.weipaitang.com'
-}
+  '/thanos-admin/api': 'http://thanos-admin.weipaitang.com',
+};

+ 206 - 0
src/pages/Task/eventManage/index.js

@@ -0,0 +1,206 @@
+import React, { useEffect, useState } from 'react';
+import { FilterTable, FormItem } from 'wptpc-design';
+import { message, Divider, Modal, Popconfirm } from 'antd';
+import { taskApi, dc } from '@/conf/config';
+import { fetchApi_get } from '@/apis/';
+import { addItem, editItem, delItem } from './services';
+
+let localrefresh = null;
+export default function EventManage() {
+  const apiUrl = `${dc}/ts/web/get-event-list`;
+
+  const [visible, setVisible] = useState(false);
+  const [confirmLoading, setConfirmLoading] = useState(false);
+  const [formParams, setFormParams] = useState({});
+  const [typeNum, setTypeNum] = useState({}); // 编辑3 添加4
+
+  const add = (e, record, index) => {
+    setFormParams({});
+    setTypeNum(2);
+    setVisible(true);
+  };
+
+  //
+
+  const edit = text => {
+    setFormParams(text);
+    setTypeNum(3);
+    setVisible(true);
+  };
+
+  const confirm = (e, text) => {
+    delItem({ id: text.id }).then(res => {
+      if (res && res.code === 0) {
+        message.success(res.msg);
+        localrefresh();
+      }
+    });
+  };
+
+  const onParamsChange = (key, value) => {
+    setFormParams({ ...formParams, [key]: value });
+  };
+
+  const handleOk = () => {
+    if (
+      // !formParams.eventName ||
+      Object.keys(formParams).length < typeNum ||
+      formParams.eventName?.length < 2 ||
+      // !formParams.eventType ||
+      formParams.eventType?.length < 2
+      // !formParams.remarks ||
+      // formParams.remarks?.length < 2
+    ) {
+      message.warning('字段全部必填,2-20个字符');
+      return;
+    }
+    setConfirmLoading(true);
+    if (typeNum === 2) {
+      addItem(formParams).then(res => {
+        if (res && res.code === 0) {
+          message.success(res.msg);
+          localrefresh();
+        }
+      });
+    } else {
+      editItem(formParams).then(res => {
+        if (res && res.code === 0) {
+          message.success(res.msg);
+          localrefresh();
+        }
+      });
+    }
+    localrefresh();
+    setVisible(false);
+    setConfirmLoading(false);
+  };
+
+  const filterSetting = {
+    beforeSearchFunc: params => {},
+    hasClearBtn: false,
+    perWidthUnit: 240,
+    formFields: [
+      {
+        label: '事件标识:',
+        key: 'senderId',
+        type: 'input',
+      },
+      {
+        label: '事件名称:',
+        key: 'userinfoId',
+        type: 'input',
+      },
+    ],
+  };
+  const tableColumns = [
+    {
+      title: 'ID',
+      dataIndex: 'id',
+    },
+
+    {
+      title: '事件标识',
+      dataIndex: 'eventType',
+    },
+    {
+      title: '事件名称',
+      dataIndex: 'eventName',
+    },
+    {
+      title: '备注',
+      dataIndex: 'remarks',
+    },
+    {
+      title: '操作',
+      dataIndex: 'time',
+      render: (e, text, index) => {
+        return (
+          <span key={index}>
+            <a
+              onClick={() => {
+                edit(text);
+              }}
+            >
+              编辑
+            </a>
+            <Divider type="vertical" />
+            <Popconfirm
+              title="确定删除该任务吗?"
+              onConfirm={() => {
+                confirm(e, text);
+              }}
+              //   onCancel={cancel}
+              okText="Yes"
+              cancelText="No"
+            >
+              <a>删除</a>
+            </Popconfirm>
+          </span>
+        );
+      },
+    },
+  ];
+  const tableSetting = {
+    getRefresh: refresh => {
+      localrefresh = refresh;
+    },
+    columnConfig: tableColumns,
+    rowKey: 'id',
+    batchBtns: [{ label: '添加', enabled: true, onClick: add, type: 'primary' }],
+  };
+  const formSetting = [
+    {
+      label: '事件标识',
+      isRequired: true,
+      type: 'input',
+      key: 'eventType',
+      maxLength: 50,
+      placeholder: '2-50个字符',
+      disabled: typeNum === 3,
+    },
+    {
+      label: '事件名称',
+      isRequired: true,
+      type: 'input',
+      key: 'eventName',
+      maxLength: 50,
+      placeholder: '2-50个字符',
+    },
+    {
+      label: '备注',
+      // isRequired: true,
+      type: 'input',
+      key: 'remarks',
+      // maxLength: 50,
+      // placeholder: '2-20个字符',
+    },
+  ];
+  let getCheck = null;
+  return (
+    <>
+      <FilterTable
+        fetchApi={fetchApi_get}
+        fetctWhenMount={true}
+        filterSetting={filterSetting}
+        tableSetting={tableSetting}
+        apiUrl={apiUrl}
+      />
+      <Modal
+        title="编辑"
+        visible={visible}
+        onOk={handleOk}
+        confirmLoading={confirmLoading}
+        onCancel={() => {
+          setVisible(false);
+        }}
+      >
+        <FormItem
+          formSetting={formSetting}
+          params={formParams}
+          onChange={onParamsChange}
+          getCheck={cb => (getCheck = cb)}
+        />
+      </Modal>
+    </>
+  );
+}

+ 22 - 0
src/pages/Task/eventManage/services.js

@@ -0,0 +1,22 @@
+import { fetchApi } from "@/apis/";
+import { dc } from "@/conf/config";
+
+export async function addItem(params) {
+  const url = `${dc}/ts/web/add-event`;
+  return fetchApi(url, params);
+}
+
+export async function editItem(params) {
+  const url = `${dc}/ts/web/edit-event`;
+  return fetchApi(url, params);
+}
+
+export async function delItem(params) {
+  console.log(params,990);
+  const url = `${dc}/ts/web/del-event`;
+  return fetchApi(url, params);
+}
+// export async function getBails(params) {
+//   const url = `${apiWptManage}/withdraw/bails`;
+//   return fetchApi(url, params);
+// }

+ 184 - 0
src/pages/Task/historyManage/index.js

@@ -0,0 +1,184 @@
+import React, { useEffect, useState } from 'react';
+import { FilterTable, FormItem, LongText } from 'wptpc-design';
+import { message, Modal } from 'antd';
+import { dc } from '@/conf/config';
+import moment from 'moment';
+import { fetchApi_get } from '@/apis/';
+import {} from './services';
+
+function HistoryManage(props) {
+  const apiUrl = `${dc}/ts/web/get-task-history`;
+  const [visible, setVisible] = useState(false);
+  const [confirmLoading, setConfirmLoading] = useState(false);
+  const [formParams, setFormParams] = useState({});
+
+  const onParamsChange = (key, value) => {
+    setFormParams({ ...formParams, [key]: value });
+  };
+
+  const handleOk = () => {
+    if (
+      // !formParams.eventName ||
+      Object.keys(formParams).length < 4 ||
+      formParams.eventName?.length < 2 ||
+      // !formParams.eventType ||
+      formParams.eventType?.length < 2 ||
+      // !formParams.remarks ||
+      formParams.remarks?.length < 2
+    ) {
+      message.warning('字段全部必填,2-20个字符');
+      return;
+    }
+    setConfirmLoading(true);
+    setTimeout(() => {
+      setVisible(false);
+      setConfirmLoading(false);
+    }, 2000);
+  };
+
+  const filterSetting = {
+    beforeSearchFunc: params => {
+      if (params.rangePicker.length === 0) {
+        params.startTime = '';
+        params.startTime = '';
+      } else {
+        const newTime = params.rangePicker.split(',');
+        params.startTime = moment(newTime[0] * 1).format('YYYY-MM-DD HH:mm:ss');
+        params.endTime = moment(newTime[1] * 1).format('YYYY-MM-DD HH:mm:ss');
+      }
+      delete params.rangePicker;
+    },
+
+    hasClearBtn: false,
+    perWidthUnit: 240,
+    formFields: [
+      {
+        label: '用户ID:',
+        type: 'input',
+        key: 'promoterId',
+        reg: 'id',
+      },
+      {
+        label: '事件标识:',
+        type: 'input',
+        key: 'eventType',
+        reg: 'number',
+      },
+      {
+        label: '任务状态:',
+        type: 'select',
+        option: [{ value: '0', label: '未上线' }, { value: '1', label: '已上线' }],
+        key: 'isOnline',
+      },
+      {
+        label: '任务时间:',
+        type: 'rangePicker',
+        key: 'rangePicker',
+        format: 'YYYY-MM-DD HH:mm:ss',
+        // defaultValue: [moment(), moment()],
+      },
+    ],
+  };
+  const tableColumns = [
+    {
+      title: 'ID',
+      dataIndex: 'id',
+    },
+    {
+      title: '用户ID',
+      dataIndex: 'userinfoId',
+    },
+    {
+      title: '事件标识',
+      dataIndex: 'eventType',
+    },
+    {
+      title: '回调',
+      dataIndex: 'callback',
+    },
+    {
+      title: '用户ID',
+      dataIndex: 'userid',
+    },
+    {
+      title: '完成状态',
+      dataIndex: 'isFinished',
+      render: (e, text) => {
+        return text.isOnline ? <span>已上线</span> : <span>未上线</span>;
+      },
+    },
+    {
+      title: '完成时间',
+      dataIndex: 'finishedTime',
+    },
+    {
+      title: '扩展数据',
+      dataIndex: 'customData',
+      render: text => {
+        if (text) return <LongText text={text} limit={16} overlayStyle={{ maxWidth: 200 }} />;
+        return '-';
+      },
+    },
+  ];
+
+  const tableSetting = {
+    columnConfig: tableColumns,
+    rowKey: 'id',
+  };
+  const formSetting = [
+    {
+      label: '事件标识',
+      isRequired: true,
+      type: 'input',
+      key: 'eventType',
+      maxLength: 20,
+      placeholder: '2-20个字符',
+    },
+    {
+      label: '事件名称',
+      isRequired: true,
+      type: 'input',
+      key: 'eventName',
+      maxLength: 20,
+      placeholder: '2-20个字符',
+    },
+    {
+      label: '备注',
+      isRequired: true,
+      type: 'input',
+      key: 'remarks',
+      maxLength: 20,
+      placeholder: '2-20个字符',
+    },
+  ];
+  useEffect(() => {}, []);
+  let getCheck = null;
+  return (
+    <>
+      <FilterTable
+        fetchApi={fetchApi_get}
+        fetctWhenMount={true}
+        filterSetting={filterSetting}
+        tableSetting={tableSetting}
+        apiUrl={apiUrl}
+      />
+      <Modal
+        title="Title"
+        visible={visible}
+        onOk={handleOk}
+        confirmLoading={confirmLoading}
+        onCancel={() => {
+          setVisible(false);
+        }}
+      >
+        <FormItem
+          formSetting={formSetting}
+          params={formParams}
+          onChange={onParamsChange}
+          getCheck={cb => (getCheck = cb)}
+        />
+      </Modal>
+    </>
+  );
+}
+export default HistoryManage;

+ 7 - 0
src/pages/Task/historyManage/services.js

@@ -0,0 +1,7 @@
+import { fetchApi } from "@/apis/";
+import { dc } from "@/conf/config";
+
+export async function addItem(params) {
+  const url = `${dc}/ts/web/get-task-history`;
+  return fetchApi(url, params);
+}

+ 310 - 0
src/pages/Task/taskmanage/index.js

@@ -0,0 +1,310 @@
+import React, { useEffect, useState } from 'react';
+import { FilterTable, FormItem, LongText } from 'wptpc-design';
+import { message, Divider, Modal, Button, Popconfirm } from 'antd';
+import { dc } from '@/conf/config';
+import { fetchApi_get } from '@/apis/';
+import { addItem, editItem, delItem, selectData } from './services';
+
+let localrefresh = null;
+
+export default function EventManage() {
+  const apiUrl = `${dc}/ts/web/get-task-list`;
+  const [visible, setVisible] = useState(false);
+  const [confirmLoading, setConfirmLoading] = useState(false);
+  const [formParams, setFormParams] = useState({});
+  const [selectDataList, setSelectList] = useState();
+  const [subType, setSubType] = useState();
+
+  const add = (e, record, index) => {
+    setFormParams({});
+    setVisible(true);
+    setSubType('add');
+  };
+
+  const getSelectData = () => {
+    selectData({ getAll: 1 }).then(res => {
+      if (res) {
+        let dataList = res.data.list.map(item => {
+          return {
+            value: item.id,
+            label: item.eventName,
+          };
+        });
+        setSelectList(dataList);
+      }
+    });
+  };
+
+  const edit = text => {
+    setFormParams(text);
+    setVisible(true);
+    setSubType('edit');
+    // setFormParams({ id: text.id });
+  };
+
+  function confirm(type, id) {
+    if (type === 'offline') {
+      let param = { ...id, isOnline: 0 };
+      editItem(param).then(res => {
+        message.success(res.msg);
+        localrefresh();
+      });
+    } else if (type === 'online') {
+      let param = { ...id, isOnline: 1 };
+      editItem(param).then(res => {
+        message.success(res.msg);
+        localrefresh();
+      });
+    } else {
+      delItem({ id }).then(res => {
+        message.success(res.msg);
+        localrefresh();
+      });
+    }
+  }
+
+  const onParamsChange = (key, value) => {
+    setFormParams({ ...formParams, [key]: value });
+  };
+
+  const handleOk = () => {
+    formParams.delayTime = formParams.delayTime.toString();
+    formParams.isOnline = formParams?.isOnline.toString();
+    if (
+      !formParams?.callback ||
+      !formParams?.isOnline ||
+      !formParams?.delayTime ||
+      !formParams?.eventId
+    ) {
+      message.warning('红心字段必填!');
+      return;
+    }
+    setConfirmLoading(true);
+    if (subType === 'edit') {
+      editItem(formParams).then(res => {
+        if (res && res.code === 0) {
+          message.success(res.msg);
+          localrefresh();
+        }
+      });
+    } else {
+      addItem(formParams).then(res => {
+        if (res && res.code === 0) {
+          message.success(res.msg);
+          localrefresh();
+        }
+      });
+    }
+    setVisible(false);
+    setConfirmLoading(false);
+  };
+
+  const filterSetting = {
+    beforeSearchFunc: params => {},
+
+    hasClearBtn: false,
+    perWidthUnit: 240,
+    formFields: [
+      {
+        label: '事件:',
+        key: 'eventType',
+        type: 'input',
+      },
+      {
+        label: '回调:',
+        key: 'callback',
+        type: 'input',
+      },
+    ],
+  };
+  const tableColumns = [
+    {
+      title: 'ID',
+      dataIndex: 'id',
+    },
+
+    {
+      title: '事件',
+      dataIndex: 'eventType',
+    },
+    {
+      title: '回调',
+      dataIndex: 'callback',
+    },
+    {
+      title: '任务状态',
+      dataIndex: 'isOnline',
+      render: (e, text) => {
+        return text.isOnline ? <span>已上线</span> : <span>未上线</span>;
+      },
+    },
+    {
+      title: '扩展数据',
+      dataIndex: 'customData',
+    },
+    {
+      title: '延时',
+      dataIndex: 'delayTime',
+    },
+    {
+      title: '备注',
+      dataIndex: 'remarks',
+    },
+    {
+      title: '操作',
+      dataIndex: 'time',
+      render: (e, text) => {
+        return (
+          <span>
+            <a
+              onClick={() => {
+                edit(text);
+              }}
+            >
+              编辑
+            </a>
+            <Divider type="vertical" />
+            <Popconfirm
+              title="确定删除该任务吗?"
+              onConfirm={() => {
+                confirm('delete', text.id);
+              }}
+              //   onCancel={cancel}
+              okText="Yes"
+              cancelText="No"
+            >
+              <a>删除</a>
+            </Popconfirm>
+            {text.isOnline ? (
+              <Popconfirm
+                title="确定下线该任务吗?"
+                onConfirm={() => {
+                  confirm('offline', text);
+                }}
+                //   onCancel={cancel}
+                okText="Yes"
+                cancelText="No"
+              >
+                <Divider type="vertical" />
+                <a>下线</a>
+              </Popconfirm>
+            ) : (
+              <Popconfirm
+                title="确定下线该任务吗?"
+                onConfirm={() => {
+                  confirm('online', text);
+                }}
+                //   onCancel={cancel}
+                okText="Yes"
+                cancelText="No"
+              >
+                <Divider type="vertical" />
+                <a>上线</a>
+              </Popconfirm>
+            )}
+          </span>
+        );
+      },
+    },
+  ];
+  const tableSetting = {
+    getRefresh: refresh => {
+      localrefresh = refresh;
+    },
+    columnConfig: tableColumns,
+    rowKey: 'saleId',
+    batchBtns: [{ label: '添加', enabled: true, onClick: add, type: 'primary' }],
+  };
+  const formSetting = [
+    {
+      label: '事件',
+      isRequired: true,
+      type: 'select',
+      key: 'eventId',
+      placeholder: '请选择',
+      options: selectDataList,
+      disabled: subType === 'edit',
+    },
+    {
+      label: '回调',
+      isRequired: true,
+      type: 'input',
+      key: 'callback',
+      maxLength: 20,
+      placeholder: '请输入',
+    },
+    {
+      label: '状态',
+      isRequired: true,
+      type: 'select',
+      key: 'isOnline',
+      placeholder: '请选择',
+      options: [
+        {
+          // select框的下拉项
+          value: 0,
+          label: '未上线',
+        },
+        {
+          value: 1,
+          label: '已上线',
+        },
+      ],
+    },
+    {
+      label: '延时',
+      isRequired: true,
+      type: 'input',
+      key: 'delayTime',
+      placeholder: '单位:秒',
+    },
+    {
+      label: '拓展数据',
+      //   isRequired: true,
+      type: 'textarea',
+      key: 'customData',
+      maxLength: 200,
+      placeholder: '请输入json格式',
+    },
+    {
+      label: '备注',
+      //   isRequired: true,
+      type: 'textarea',
+      key: 'remarks',
+      maxLength: 200,
+    },
+  ];
+  useEffect(() => {
+    getSelectData();
+  }, []);
+
+  let getCheck = null;
+  return (
+    <>
+      <FilterTable
+        fetchApi={fetchApi_get}
+        fetctWhenMount={true}
+        filterSetting={filterSetting}
+        tableSetting={tableSetting}
+        apiUrl={apiUrl}
+      />
+      <Modal
+        title="编辑"
+        visible={visible}
+        onOk={handleOk}
+        confirmLoading={confirmLoading}
+        onCancel={() => {
+          setVisible(false);
+        }}
+      >
+        <FormItem
+          //   fetchApi={fetchApi_get}
+          formSetting={formSetting}
+          params={formParams}
+          onChange={onParamsChange}
+          getCheck={cb => (getCheck = cb)}
+        />
+      </Modal>
+    </>
+  );
+}

+ 27 - 0
src/pages/Task/taskmanage/services.js

@@ -0,0 +1,27 @@
+import { fetchApi } from '@/apis/';
+import { dc } from '@/conf/config';
+
+export async function addItem(params) {
+  const url = `${dc}/ts/web/add-task`;
+  return fetchApi(url, params);
+}
+
+export async function editItem(params) {
+  const url = `${dc}/ts/web/edit-task`;
+  return fetchApi(url, params);
+}
+
+export async function delItem(params) {
+  const url = `${dc}/ts/web/del-task`;
+  return fetchApi(url, params);
+}
+
+export async function selectData(params) {
+  const url = `${dc}/ts/web/get-event-list`;
+  return fetchApi(url, params);
+}
+
+// export async function getBails(params) {
+//   const url = `${apiWptManage}/withdraw/bails`;
+//   return fetchApi(url, params);
+// }

+ 1 - 0
src/utils/getRealUrl.js

@@ -15,4 +15,5 @@ export default function (url) {
   } else {
     return url
   }
+  
 }