import React, { useCallback, useEffect, useMemo, useState } from "react"; import styles from "./index.module.scss"; import { Button, Modal, Table } from "antd"; import { B2_APIlookReDo } from "@/store/action/B2Scene"; import { MessageFu } from "@/utils/message"; import dayjs from "dayjs"; import ExportJsonExcel from "js-export-excel"; type ListType = { id: string; city: string; province: string; region: string; roomNum: string; sceneCode: string; }; type Props = { closePageFu: () => void; }; function LookReDo({ closePageFu }: Props) { const [list, setList] = useState([]); const geiListFu = useCallback(async () => { const res = await B2_APIlookReDo(); if (res.code === 0) { setList( res.data.map((v: ListType) => ({ ...v, id: v.city + "" + v.province + v.region + v.roomNum + v.sceneCode, })) ); } }, []); useEffect(() => { geiListFu(); }, [geiListFu]); const column = useMemo(() => { return [ { title: "机房编码", render: (item: ListType) => item.roomNum || "空", }, { title: "站址地区", render: (item: ListType) => !item.province && !item.city && !item.region ? "(空)" : `${item.province}-${item.city}-${item.region}`, }, { title: "场景码", render: (item: ListType) => item.sceneCode || "空", }, ]; }, []); // 点击导出 const deriveFu = useCallback(async () => { if (list.length === 0) return MessageFu.warning("当前搜索条件没有数据!"); const name = "重复场景" + dayjs(new Date()).format("YYYY-MM-DD HH:mm"); const option = { fileName: name, datas: [ { sheetData: list.map((v) => ({ ...v, myCity: !v.province && !v.city && !v.region ? "(空)" : `${v.province}-${v.city}-${v.region}`, })), sheetName: name, sheetFilter: ["roomNum", "myCity", "sceneCode"], sheetHeader: ["机房编码", "站址地区", "场景码"], columnWidths: [10, 10, 10], }, ], }; const toExcel = new ExportJsonExcel(option); //new toExcel.saveExcel(); //保存 }, [list]); return (
重复场景
} footer={ [] // 设置footer为空,去掉 取消 确定默认按钮 } >
{/* 右下角的列表数量 */}
{list.length} 条数据
); } const MemoLookReDo = React.memo(LookReDo); export default MemoLookReDo;