index.jsx 11.2 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 9 10 11 12 13
import React, { memo, useEffect, useRef, useState, useReducer } from "react";
import {
  Image,
  Divider,
  Menu,
  Dropdown,
  Button,
  Modal,
  Row,
  Col,
  Tooltip,
  Drawer,
} from "antd";
wuhao's avatar
wuhao committed
14
import { connect, useRequest } from "umi";
wuhao's avatar
wuhao committed
15 16 17
import AutoTable from "@/components/AutoTable";
import getPrem from "@/utils/getPrem"; //权限判断fn
import { doFetch } from "@/utils/doFetch";
wuhao's avatar
wuhao committed
18 19 20 21 22
import { paBusinessMsgScene, paBusinessMsgOption } from "@/services/platform";
import { addFields } from "./fields";
import Formpage from "./Formpage";
import Details from "@/components/Details";
const initState = {
wuhao's avatar
wuhao committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  vs: false,
  fields: {},
  iftype: {},
  details: {
    totalTitle: "",
    visible: false,
    dataSource: {},
    totalCard: [],
  },
  shown: false,
  rowMessage: {},
};

function reducer(state, action) {
  if (action.type == "add") {
    return {
      ...state,
      vs: true,
      fields: action.fields,
      iftype: {
        val: "add",
        title: "新增推送配置",
      },
      rowMessage: {},
    };
  } else if (action.type == "close") {
    return {
      ...state,
      vs: false,
      iftype: {},
      fields: {},
      details: {
wuhao's avatar
wuhao committed
55 56 57
        totalTitle: "",
        visible: false,
        dataSource: {},
wuhao's avatar
wuhao committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
        totalCard: [],
      },
      shown: false,
    };
  } else if (action.type == "edit") {
    return {
      ...state,
      vs: true,
      fields: action.fields,
      iftype: {
        val: "edit",
        title: "修改推送配置",
        id: action.rowMessage.id,
      },
      rowMessage: action.rowMessage,
    };
  } else if (action.type == "seeDetails") {
    return {
      ...state,
      details: {
        totalTitle: "推送详情",
        visible: true,
        dataSource: { ...action.dataSource },
        totalCard: [...action.totalCard],
      },
    };
  } else if (action.type == "changeShown") {
    return {
      ...state,
      shown: action.shown,
    };
  }
wuhao's avatar
wuhao committed
90 91 92
}

const Pushdeploy = (props) => {
wuhao's avatar
wuhao committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
  let actionRef = useRef(),
    ChildRef = null;
  function reload() {
    actionRef?.current?.reload();
    ChildRef?.onRefresh();
  }
  const [state, dispatch] = useReducer(reducer, initState),
    { vs, fields, iftype, details, shown, rowMessage } = state,
    columns = [
      {
        title: "推送类型",
        dataIndex: "msgSceneName",
        key: "businessMsgSceneId",
        valueType: "select",
        render: (_, row) => {
          return (
            <div
              style={{
                padding: "3px 0",
                overflow: "hidden",
                whiteSpace: "nowrap",
                textOverflow: "ellipsis",
              }}
            >
              <Tooltip title={row.msgSceneName}>
                <a
                  onClick={() => {
                    let commons = [
                        {
                          title: "推送类型",
                          key: "msgSceneName",
                        },
                        {
                          title: "推送方式",
                          key: "sendMethodName",
                        },
                        {
                          title: "适用类型",
                          key: "fitFieldName",
                        },
                      ],
                      table = {
                        key: "detailList",
                        col: { span: 24 },
                        type: "table",
                        columns: [
                          {
                            title: "推送流程",
                            dataIndex: "sendProcessName",
                            key: "sendProcessName",
                            search: false,
                          },
                          {
                            title: "推送对象",
                            dataIndex: "sendToName",
                            key: "sendToName",
                            search: false,
                          },
                          {
                            title: "选择对象",
                            dataIndex: "targetNames",
                            key: "targetNames",
                            search: false,
                          },
                          {
                            title: "初始触发时长",
                            dataIndex: "initialTime",
                            key: "initialTime",
                            search: false,
                          },
                          {
                            title: "初始触发时长单位",
                            dataIndex: "initialUnitName",
                            key: "initialUnitName",
                            search: false,
                          },
                          {
                            title: "间隔时长",
                            dataIndex: "intervalTime",
                            key: "intervalTime",
                            search: false,
                          },
                          {
                            title: "间隔时长单位",
                            dataIndex: "intervalUnitName",
                            key: "intervalUnitName",
                            search: false,
                          },
                          {
                            title: "触发次数",
                            dataIndex: "sendNum",
                            key: "sendNum",
                            search: false,
                          },
                        ],
                      },
                      totalCardsc,
                      contentMsg,
                      fieldMsg;
                    contentMsg = {
                      title: "推送内容",
                      key: "sendContent",
                      col: { span: 24 },
                    };
                    if (row.fitField == 1) {
                      fieldMsg = null;
                    } else {
                      fieldMsg = {
                        title: "类型名称",
                        key: "fieldName",
                      };
wuhao's avatar
wuhao committed
204
                    }
wuhao's avatar
wuhao committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
                    totalCardsc = [
                      {
                        cardTitle: "推送信息",
                        itemData: [
                          ...commons,
                          fieldMsg && { ...fieldMsg },
                          contentMsg && { ...contentMsg },
                        ],
                      },
                      {
                        cardTitle: "基础配置",
                        itemData: [{ ...table }],
                      },
                    ];
                    totalCardsc.map((it) => {
                      let newData = it.itemData.filter((item) => item);
                      it.itemData = [...newData];
                    });
                    paBusinessMsgOption({ id: row.id }).then((res) => {
                      if (res.code == "0000") {
                        let data = res?.data?.data || {};
                        dispatch({
                          type: "seeDetails",
                          totalCard: [...totalCardsc],
                          dataSource: { ...data },
                        });
                      }
                    });
                  }}
                >
                  {row.msgSceneName}
                </a>
              </Tooltip>
wuhao's avatar
wuhao committed
238
            </div>
wuhao's avatar
wuhao committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
          );
        },
        options: {
          database: paBusinessMsgScene,
          params: {},
        },
      },
      {
        title: "推送方式",
        dataIndex: "sendMethodName",
        key: "sendMethodName",
        search: false,
      },
      {
        title: "适用类型",
        dataIndex: "fitFieldName",
        key: "fitField",
        valueType: "select",
        options: [
          {
            label: "全部",
            value: 1,
          },
          {
            label: "工厂",
            value: 2,
          },
          {
            label: "组织",
            value: 3,
          },
          {
            label: "仓库",
            value: 4,
          },
        ],
      },
      {
        title: "类型名称",
        dataIndex: "fieldName",
        key: "fieldName",
      },
      {
        title: "推送内容",
        dataIndex: "sendContent",
        key: "sendContent",
        search: false,
      },
      {
        title: "操作",
        valueType: "option",
        width: 150,
        render: (text, row, _, action) => extraAction(text, row, _, action),
      },
    ],
    { run, loading } = useRequest(doFetch, {
      manual: true,
      formatResult: (res) => res,
      onSuccess: (result, params) => {
        if (result.code == "0000") {
          reload();
          dispatch({ type: "close" });
        }
      },
    });
  function extraAction(text, record, _, action) {
    return (
      <div>
        {getPrem("paBusinessMsgOption_save", action, "修改", () => {
          paBusinessMsgOption({ id: record.id }).then((res) => {
            if (res.code == "0000") {
              let data = res?.data?.data || {};
              for (let i in addFields) {
                addFields[i].value = data[i];
              }
              dispatch({ type: "edit", rowMessage: data, fields: addFields });
wuhao's avatar
wuhao committed
315
            }
wuhao's avatar
wuhao committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
          });
        })}
        {getPrem("paBusinessMsgOption_save", "ifs") && (
          <Divider type="vertical" />
        )}
        {getPrem("paBusinessMsgOption_deleteById", action, "删除", null, {
          title: "确认删除该推送配置?",
          onConfirm: () => {
            run({
              url: "/ngic-base-business/paBusinessMsgOption/deleteById",
              params: { id: record.id },
            });
          },
        })}
      </div>
    );
  }
  function reset() {
    reload();
    dispatch({ type: "close" });
  }
  let extrarender = [
    <Button
      disabled={!getPrem("paBusinessMsgOption_save", "ifs")}
      size={"middle"}
      type="primary"
      onClick={() => {
        for (let i in addFields) {
          addFields[i].value = null;
        }
        dispatch({ type: "add", fields: addFields });
      }}
    >
      新增
    </Button>,
  ];
  return (
    <div>
      <AutoTable
        pagetitle={props.route.name}
        pageextra={extrarender}
        columns={columns}
        bordered={false}
        actionRef={actionRef}
        onRef={(node) => (ChildRef = node)}
        path="/ngic-base-business/paBusinessMsgOption/queryList"
      ></AutoTable>
      <Drawer
        title={iftype.title}
        closable={true}
        visible={vs}
        onClose={() => dispatch({ type: "close" })}
        destroyOnClose={true}
        getContainer={false}
        afterVisibleChange={(v) => {
          dispatch({ type: "changeShown", shown: v });
        }}
        style={{ position: "absolute" }}
        width="100%"
      >
        {shown && (
          <Formpage
            fields={fields}
            rowMessage={rowMessage}
            reset={reset}
            iftypeParent={iftype}
          />
        )}
      </Drawer>
      <Details
        {...details}
        title={details.totalTitle}
        onClose={() => dispatch({ type: "close" })}
        getContainer={false}
        style={{ position: "absolute" }}
        width={800}    
      ></Details>

     
wuhao's avatar
wuhao committed
395
    </div>
wuhao's avatar
wuhao committed
396 397 398
  );
};
export default Pushdeploy;