|
@@ -1,314 +0,0 @@
|
|
|
-import React, { useEffect, useState } from 'react';
|
|
|
-import { FilterTable, FormItem } from 'wptpc-design';
|
|
|
-import { message, Divider, Modal, Popconfirm } from 'antd';
|
|
|
-import { dc } from '@/conf/config';
|
|
|
-import { fetchApiGet } 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: 'eventName',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '回调',
|
|
|
- dataIndex: 'callback',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '任务状态',
|
|
|
- dataIndex: 'isOnline',
|
|
|
- render: (e, text) => {
|
|
|
- return text.isOnline ? <span>已上线</span> : <span>未上线</span>;
|
|
|
- },
|
|
|
- },
|
|
|
-
|
|
|
- {
|
|
|
- title: '延时',
|
|
|
- dataIndex: 'delayTime',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '备注',
|
|
|
- dataIndex: 'remarks',
|
|
|
- },
|
|
|
- {
|
|
|
- title: '扩展数据',
|
|
|
- dataIndex: 'customData',
|
|
|
- },
|
|
|
- {
|
|
|
- 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={fetchApiGet}
|
|
|
- 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>
|
|
|
- </>
|
|
|
- );
|
|
|
-}
|