优化excel导出
parent
14aa36fb66
commit
85d7346394
|
|
@ -31,7 +31,7 @@
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-to-print": "^3.2.0",
|
"react-to-print": "^3.2.0",
|
||||||
"zy-react-library": "^1.1.10"
|
"zy-react-library": "^1.1.12"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "^5.4.1",
|
"@antfu/eslint-config": "^5.4.1",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { Permission } from "@cqsjjb/jjb-common-decorator/permission";
|
import { Permission } from "@cqsjjb/jjb-common-decorator/permission";
|
||||||
import { Connect } from "@cqsjjb/jjb-dva-runtime";
|
import { Connect } from "@cqsjjb/jjb-dva-runtime";
|
||||||
import { Button, Form, message, Modal, Space, Spin } from "antd";
|
import { Button, Checkbox, Form, message, Modal, Space } from "antd";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { useReactToPrint } from "react-to-print";
|
import { useReactToPrint } from "react-to-print";
|
||||||
import FormBuilder from "zy-react-library/components/FormBuilder";
|
import FormBuilder from "zy-react-library/components/FormBuilder";
|
||||||
import AddIcon from "zy-react-library/components/Icon/AddIcon";
|
import AddIcon from "zy-react-library/components/Icon/AddIcon";
|
||||||
|
|
@ -18,7 +18,7 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
|
||||||
import { HIDDEN_RECTIFICATION_TYPE_ENUM, HIDDEN_SOURCE_ENUM, HIDDEN_STATE_ENUM } from "zy-react-library/enum/hidden/gwj";
|
import { HIDDEN_RECTIFICATION_TYPE_ENUM, HIDDEN_SOURCE_ENUM, HIDDEN_STATE_ENUM } from "zy-react-library/enum/hidden/gwj";
|
||||||
import useDownloadBlob from "zy-react-library/hooks/useDownloadBlob";
|
import useDownloadBlob from "zy-react-library/hooks/useDownloadBlob";
|
||||||
import useTable from "zy-react-library/hooks/useTable";
|
import useTable from "zy-react-library/hooks/useTable";
|
||||||
import { getLabelName } from "zy-react-library/utils";
|
import { getLabelName, getUnmatchedItems } from "zy-react-library/utils";
|
||||||
import { IS_RELATED_ENUM } from "~/enumerate/constant";
|
import { IS_RELATED_ENUM } from "~/enumerate/constant";
|
||||||
import { NS_LEDGER } from "~/enumerate/namespace";
|
import { NS_LEDGER } from "~/enumerate/namespace";
|
||||||
import "./index.less";
|
import "./index.less";
|
||||||
|
|
@ -28,7 +28,6 @@ function List(props) {
|
||||||
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
const [selectedRowKeys, setSelectedRowKeys] = useState([]);
|
||||||
const [exportByColumnModalOpen, setExportByColumnModalOpen] = useState(false);
|
const [exportByColumnModalOpen, setExportByColumnModalOpen] = useState(false);
|
||||||
const [printModalOpen, setPrintModalOpen] = useState(false);
|
const [printModalOpen, setPrintModalOpen] = useState(false);
|
||||||
const { loading: downloadBlobLoading, downloadBlob } = useDownloadBlob();
|
|
||||||
const { tableProps, getData } = useTable(props["ledgerList"], {
|
const { tableProps, getData } = useTable(props["ledgerList"], {
|
||||||
form,
|
form,
|
||||||
transform: formData => ({
|
transform: formData => ({
|
||||||
|
|
@ -51,31 +50,8 @@ function List(props) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onExportExcel = async () => {
|
|
||||||
const hiddenFindTime = form.getFieldValue("hiddenFindTime");
|
|
||||||
if (!hiddenFindTime) {
|
|
||||||
message.error("请选择隐患发现时间");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (hiddenFindTime.filter(Boolean).length === 0) {
|
|
||||||
message.error("请选择隐患发现时间");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Modal.confirm({
|
|
||||||
title: "导出确认",
|
|
||||||
content: "确定要导出excel吗?",
|
|
||||||
onOk: async () => {
|
|
||||||
await downloadBlob("/hidden/hidden/exportHidden", {
|
|
||||||
params: { hiddenFindTime: hiddenFindTime[0], hiddenFindTimeLe: hiddenFindTime[1] },
|
|
||||||
});
|
|
||||||
message.success("导出成功");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page isShowAllAction={false}>
|
<Page isShowAllAction={false}>
|
||||||
<Spin spinning={downloadBlobLoading}>
|
|
||||||
<Search
|
<Search
|
||||||
options={[
|
options={[
|
||||||
{ name: "source", label: "隐患来源", render: FORM_ITEM_RENDER_ENUM.SELECT, items: HIDDEN_SOURCE_ENUM },
|
{ name: "source", label: "隐患来源", render: FORM_ITEM_RENDER_ENUM.SELECT, items: HIDDEN_SOURCE_ENUM },
|
||||||
|
|
@ -99,7 +75,7 @@ function List(props) {
|
||||||
name: "state",
|
name: "state",
|
||||||
label: "隐患状态",
|
label: "隐患状态",
|
||||||
render: FORM_ITEM_RENDER_ENUM.SELECT,
|
render: FORM_ITEM_RENDER_ENUM.SELECT,
|
||||||
items: HIDDEN_STATE_ENUM.filter(item => !["98", "102"].includes(item.bianma)),
|
items: getUnmatchedItems({ list: HIDDEN_STATE_ENUM, value: ["98", "102"] }),
|
||||||
},
|
},
|
||||||
{ name: "confirmUserName", label: "确认人" },
|
{ name: "confirmUserName", label: "确认人" },
|
||||||
{ name: "rectificationUserName", label: "整改人" },
|
{ name: "rectificationUserName", label: "整改人" },
|
||||||
|
|
@ -158,37 +134,16 @@ function List(props) {
|
||||||
打印
|
打印
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{props.permission("fgs-tz-dc") && (
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
icon={<ExportIcon />}
|
|
||||||
ghost
|
|
||||||
onClick={() => {
|
|
||||||
onExportExcel();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
导出
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{props.permission("fgs-tz-aldc") && (
|
{props.permission("fgs-tz-aldc") && (
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
icon={<ExportIcon />}
|
icon={<ExportIcon />}
|
||||||
ghost
|
ghost
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const hiddenFindTime = form.getFieldValue("hiddenFindTime");
|
|
||||||
if (!hiddenFindTime) {
|
|
||||||
message.error("请选择隐患发现时间");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (hiddenFindTime.filter(Boolean).length === 0) {
|
|
||||||
message.error("请选择隐患发现时间");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setExportByColumnModalOpen(true);
|
setExportByColumnModalOpen(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
按列导出
|
导出
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|
@ -289,16 +244,16 @@ function List(props) {
|
||||||
]}
|
]}
|
||||||
{...tableProps}
|
{...tableProps}
|
||||||
/>
|
/>
|
||||||
</Spin>
|
|
||||||
{exportByColumnModalOpen && (
|
{exportByColumnModalOpen && (
|
||||||
<ExportByColumnModal
|
<ExportByColumnModal
|
||||||
hiddenFindTime={form.getFieldValue("hiddenFindTime")}
|
hiddenFindTime={form.getFieldValue("hiddenFindTime")}
|
||||||
|
selectedRowKeys={selectedRowKeys}
|
||||||
onCancel={() => setExportByColumnModalOpen(false)}
|
onCancel={() => setExportByColumnModalOpen(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{printModalOpen && (
|
{printModalOpen && (
|
||||||
<PrintModal
|
<PrintModal
|
||||||
data={selectedRowKeys}
|
selectedRowKeys={selectedRowKeys}
|
||||||
onCancel={() => setPrintModalOpen(false)}
|
onCancel={() => setPrintModalOpen(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
@ -308,32 +263,89 @@ function List(props) {
|
||||||
|
|
||||||
const ExportByColumnModalComponent = (props) => {
|
const ExportByColumnModalComponent = (props) => {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
const exportFields = Form.useWatch("exportFields", form);
|
||||||
const { loading, downloadBlob } = useDownloadBlob();
|
const { loading, downloadBlob } = useDownloadBlob();
|
||||||
const [items, setItems] = useState([]);
|
const [items, setItems] = useState([]);
|
||||||
|
|
||||||
|
const indeterminate = useMemo(
|
||||||
|
() => {
|
||||||
|
if (!exportFields)
|
||||||
|
return false;
|
||||||
|
return exportFields.length > 0 && exportFields.length < items.length;
|
||||||
|
},
|
||||||
|
[exportFields],
|
||||||
|
);
|
||||||
|
|
||||||
const getExportColumn = async () => {
|
const getExportColumn = async () => {
|
||||||
const { data } = await props["hiddenExportColumn"]();
|
const { data } = await props["hiddenExportColumn"]();
|
||||||
setItems(data.map(item => ({ bianma: item, name: item })));
|
setItems(data.map(item => ({ bianma: item, name: item })));
|
||||||
|
|
||||||
|
const defaultExportFields = data.filter(item => !item.includes("图片"));
|
||||||
|
form.setFieldsValue({ exportFields: [...defaultExportFields] });
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getExportColumn();
|
getExportColumn();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onSubmit = async (values) => {
|
const onSubmit = async (values) => {
|
||||||
|
const hiddenFindTime = props.hiddenFindTime;
|
||||||
|
const selectedRowKeys = props.selectedRowKeys;
|
||||||
|
|
||||||
|
// 检查导出字段是否包含"图片"
|
||||||
|
const hasPictureField = values.exportFields && values.exportFields.some(field => field.includes("图片"));
|
||||||
|
|
||||||
|
if (hasPictureField) {
|
||||||
|
// 包含图片字段的验证逻辑
|
||||||
|
if (!selectedRowKeys || selectedRowKeys.length === 0) {
|
||||||
|
message.error("请选择要导出的数据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedRowKeys.length > 10) {
|
||||||
|
message.error("选择的数据超过10条,请重新选择");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行导出
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: "导出确认",
|
title: "导出确认",
|
||||||
content: "确定要导出excel吗?",
|
content: "确定要导出excel吗?",
|
||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
await downloadBlob("/hidden/hidden/exportHidden", {
|
await downloadBlob("/hidden/hidden/exportHidden", {
|
||||||
params: { hiddenFindTime: props.hiddenFindTime[0], hiddenFindTimeLe: props.hiddenFindTime[1], ...values },
|
params: { ids: props.selectedRowKeys.join(","), ...values },
|
||||||
});
|
});
|
||||||
message.success("导出成功");
|
message.success("导出成功");
|
||||||
props.onCancel();
|
props.onCancel();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 不包含图片字段的验证逻辑
|
||||||
|
if (!hiddenFindTime || hiddenFindTime.length === 0) {
|
||||||
|
message.error("请选择隐患发现时间");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行导出
|
||||||
|
Modal.confirm({
|
||||||
|
title: "导出确认",
|
||||||
|
content: "确定要导出excel吗?",
|
||||||
|
onOk: async () => {
|
||||||
|
await downloadBlob("/hidden/hidden/exportHidden", {
|
||||||
|
params: { hiddenFindTime: hiddenFindTime[0], hiddenFindTimeLe: hiddenFindTime[1], ...values },
|
||||||
|
});
|
||||||
|
message.success("导出成功");
|
||||||
|
props.onCancel();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title="按列导出"
|
title="导出"
|
||||||
width={600}
|
width={800}
|
||||||
open
|
open
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
onCancel={props.onCancel}
|
onCancel={props.onCancel}
|
||||||
|
|
@ -344,18 +356,38 @@ const ExportByColumnModalComponent = (props) => {
|
||||||
loading={loading}
|
loading={loading}
|
||||||
form={form}
|
form={form}
|
||||||
span={24}
|
span={24}
|
||||||
labelCol={{ span: 8 }}
|
labelCol={{ span: 6 }}
|
||||||
showActionButtons={false}
|
showActionButtons={false}
|
||||||
onFinish={onSubmit}
|
onFinish={onSubmit}
|
||||||
options={[
|
options={[
|
||||||
|
{
|
||||||
|
key: "indeterminate",
|
||||||
|
label: "",
|
||||||
|
render: (
|
||||||
|
<Checkbox
|
||||||
|
indeterminate={indeterminate}
|
||||||
|
onChange={(e) => {
|
||||||
|
const checked = e.target.checked;
|
||||||
|
if (checked) {
|
||||||
|
form.setFieldsValue({ exportFields: items.map(item => item.bianma) });
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
form.setFieldsValue({ exportFields: [] });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
checked={items.length === (exportFields || []).length}
|
||||||
|
>
|
||||||
|
全选(为保障导出效率,导出带图片的excel最多10条)
|
||||||
|
</Checkbox>
|
||||||
|
),
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "exportFields",
|
name: "exportFields",
|
||||||
label: "导出内容",
|
label: "导出内容",
|
||||||
render: FORM_ITEM_RENDER_ENUM.SELECT,
|
render: FORM_ITEM_RENDER_ENUM.CHECKBOX,
|
||||||
items,
|
items,
|
||||||
componentProps: {
|
checkboxCol: 6,
|
||||||
mode: "multiple",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
@ -384,7 +416,7 @@ const PrintModalComponent = (props) => {
|
||||||
|
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
const { data } = await props["hiddenPrintList"]({
|
const { data } = await props["hiddenPrintList"]({
|
||||||
ids: props.data.join(","),
|
ids: props.selectedRowKeys.join(","),
|
||||||
});
|
});
|
||||||
setList(data);
|
setList(data);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import { HIDDEN_RECTIFICATION_TYPE_ENUM, HIDDEN_SOURCE_ENUM, HIDDEN_STATE_ENUM }
|
||||||
import useDownloadBlob from "zy-react-library/hooks/useDownloadBlob";
|
import useDownloadBlob from "zy-react-library/hooks/useDownloadBlob";
|
||||||
import useGetUrlQuery from "zy-react-library/hooks/useGetUrlQuery";
|
import useGetUrlQuery from "zy-react-library/hooks/useGetUrlQuery";
|
||||||
import useTable from "zy-react-library/hooks/useTable";
|
import useTable from "zy-react-library/hooks/useTable";
|
||||||
import { getLabelName } from "zy-react-library/utils";
|
import { getLabelName, getUnmatchedItems } from "zy-react-library/utils";
|
||||||
import { IS_RELATED_ENUM } from "~/enumerate/constant";
|
import { IS_RELATED_ENUM } from "~/enumerate/constant";
|
||||||
import { NS_AVERAGE } from "~/enumerate/namespace";
|
import { NS_AVERAGE } from "~/enumerate/namespace";
|
||||||
import "../../../../BranchCompany/Average/Ledger/List/index.less";
|
import "../../../../BranchCompany/Average/Ledger/List/index.less";
|
||||||
|
|
@ -86,7 +86,7 @@ function HiddenList(props) {
|
||||||
name: "state",
|
name: "state",
|
||||||
label: "隐患状态",
|
label: "隐患状态",
|
||||||
render: FORM_ITEM_RENDER_ENUM.SELECT,
|
render: FORM_ITEM_RENDER_ENUM.SELECT,
|
||||||
items: HIDDEN_STATE_ENUM.filter(item => !["98", "102"].includes(item.bianma)),
|
items: getUnmatchedItems({ list: HIDDEN_STATE_ENUM, value: ["98", "102"] }),
|
||||||
},
|
},
|
||||||
{ name: "confirmUserName", label: "确认人" },
|
{ name: "confirmUserName", label: "确认人" },
|
||||||
{ name: "rectificationUserName", label: "整改人" },
|
{ name: "rectificationUserName", label: "整改人" },
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue