LookReDo.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import React, { useCallback, useEffect, useMemo, useState } from "react";
  2. import styles from "./index.module.scss";
  3. import { Button, Modal, Table } from "antd";
  4. import { B2_APIlookReDo } from "@/store/action/B2Scene";
  5. import { MessageFu } from "@/utils/message";
  6. import dayjs from "dayjs";
  7. import ExportJsonExcel from "js-export-excel";
  8. type ListType = {
  9. id: string;
  10. city: string;
  11. province: string;
  12. region: string;
  13. roomNum: string;
  14. sceneCode: string;
  15. };
  16. type Props = {
  17. closePageFu: () => void;
  18. };
  19. function LookReDo({ closePageFu }: Props) {
  20. const [list, setList] = useState<ListType[]>([]);
  21. const geiListFu = useCallback(async () => {
  22. const res = await B2_APIlookReDo();
  23. if (res.code === 0) {
  24. setList(
  25. res.data.map((v: ListType) => ({
  26. ...v,
  27. id: v.city + "" + v.province + v.region + v.roomNum + v.sceneCode,
  28. }))
  29. );
  30. }
  31. }, []);
  32. useEffect(() => {
  33. geiListFu();
  34. }, [geiListFu]);
  35. const column = useMemo(() => {
  36. return [
  37. {
  38. title: "机房编码",
  39. render: (item: ListType) => item.roomNum || "空",
  40. },
  41. {
  42. title: "站址地区",
  43. render: (item: ListType) =>
  44. !item.province && !item.city && !item.region
  45. ? "(空)"
  46. : `${item.province}-${item.city}-${item.region}`,
  47. },
  48. {
  49. title: "场景码",
  50. render: (item: ListType) => item.sceneCode || "空",
  51. },
  52. ];
  53. }, []);
  54. // 点击导出
  55. const deriveFu = useCallback(async () => {
  56. if (list.length === 0) return MessageFu.warning("当前搜索条件没有数据!");
  57. const name = "重复场景" + dayjs(new Date()).format("YYYY-MM-DD HH:mm");
  58. const option = {
  59. fileName: name,
  60. datas: [
  61. {
  62. sheetData: list.map((v) => ({
  63. ...v,
  64. myCity:
  65. !v.province && !v.city && !v.region
  66. ? "(空)"
  67. : `${v.province}-${v.city}-${v.region}`,
  68. })),
  69. sheetName: name,
  70. sheetFilter: ["roomNum", "myCity", "sceneCode"],
  71. sheetHeader: ["机房编码", "站址地区", "场景码"],
  72. columnWidths: [10, 10, 10],
  73. },
  74. ],
  75. };
  76. const toExcel = new ExportJsonExcel(option); //new
  77. toExcel.saveExcel(); //保存
  78. }, [list]);
  79. return (
  80. <Modal
  81. wrapClassName={styles.LookReDo}
  82. open={true}
  83. title={
  84. <div className="B2Mtitle">
  85. <div>重复场景</div>
  86. <div>
  87. <Button
  88. type="primary"
  89. disabled={list.length === 0}
  90. onClick={deriveFu}
  91. >
  92. 导出表格
  93. </Button>
  94. </div>
  95. </div>
  96. }
  97. footer={
  98. [] // 设置footer为空,去掉 取消 确定默认按钮
  99. }
  100. >
  101. <div className="B2Mmain">
  102. <div className="B1MTable">
  103. <Table
  104. size="small"
  105. scroll={{ y: 578 }}
  106. dataSource={list}
  107. columns={column}
  108. rowKey="id"
  109. pagination={false}
  110. />
  111. </div>
  112. <div className="B2Mbtn">
  113. <Button onClick={closePageFu}>关闭</Button>
  114. {/* 右下角的列表数量 */}
  115. <div className="tableNumBox">
  116. 共 <span>{list.length}</span> 条数据
  117. </div>
  118. </div>
  119. </div>
  120. </Modal>
  121. );
  122. }
  123. const MemoLookReDo = React.memo(LookReDo);
  124. export default MemoLookReDo;