Commit a05bea12 authored by Chunchi Che's avatar Chunchi Che

update checkCardModal.tsx

parent 21cd9e99
Pipeline #21011 passed with stages
in 22 minutes and 20 seconds
...@@ -13,15 +13,14 @@ import { ...@@ -13,15 +13,14 @@ import {
resetCheckCardModal, resetCheckCardModal,
setCheckCardModalIsOpen, setCheckCardModalIsOpen,
} from "../../reducers/duel/mod"; } from "../../reducers/duel/mod";
import { Modal, Button, Row, Col, Popover } from "antd"; import { Button, Row, Col, Popover } from "antd";
import { CheckCard } from "@ant-design/pro-components"; import { CheckCard } from "@ant-design/pro-components";
import { import {
sendSelectCardResponse, sendSelectCardResponse,
sendSelectChainResponse, sendSelectChainResponse,
} from "../../api/ocgcore/ocgHelper"; } from "../../api/ocgcore/ocgHelper";
import type { DraggableData, DraggableEvent } from "react-draggable";
import Draggable from "react-draggable";
import NeosConfig from "../../../neos.config.json"; import NeosConfig from "../../../neos.config.json";
import DragModal from "./dragModal";
const CheckCardModal = () => { const CheckCardModal = () => {
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -36,27 +35,7 @@ const CheckCardModal = () => { ...@@ -36,27 +35,7 @@ const CheckCardModal = () => {
// Draggable 相关 // Draggable 相关
const [draggable, setDraggable] = useState(false); const [draggable, setDraggable] = useState(false);
const [bounds, setBounds] = useState({
left: 0,
top: 0,
bottom: 0,
right: 0,
});
const draggleRef = useRef<HTMLDivElement>(null); const draggleRef = useRef<HTMLDivElement>(null);
const onStart = (_event: DraggableEvent, uiData: DraggableData) => {
const { clientWidth, clientHeight } = window.document.documentElement;
const targetRect = draggleRef.current?.getBoundingClientRect();
if (!targetRect) {
return;
}
setBounds({
left: -targetRect.left + uiData.x,
right: clientWidth - (targetRect.right - uiData.x),
top: -targetRect.top + uiData.y,
bottom: clientHeight - (targetRect.bottom - uiData.y),
});
};
const onMouseOver = () => { const onMouseOver = () => {
if (draggable) { if (draggable) {
setDraggable(false); setDraggable(false);
...@@ -86,32 +65,17 @@ const CheckCardModal = () => { ...@@ -86,32 +65,17 @@ const CheckCardModal = () => {
}; };
return ( return (
<Modal <DragModal
title={`请选择${min}到${max}张卡片`} modalProps={{
open={isOpen} title: `请选择${min}到${max}张卡片`,
closable={false} open: isOpen,
footer={ closable: false,
<> footer: (
<Button <>
disabled={response.length < min || response.length > max}
onClick={() => {
sendResponseHandler(onSubmit, response);
dispatch(setCheckCardModalIsOpen(false));
dispatch(resetCheckCardModal());
}}
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
onFocus={() => {}}
onBlur={() => {}}
>
submit
</Button>
{cancelAble ? (
<Button <Button
disabled={response.length < min || response.length > max}
onClick={() => { onClick={() => {
if (cancelResponse) { sendResponseHandler(onSubmit, response);
sendResponseHandler(onSubmit, [cancelResponse]);
}
dispatch(setCheckCardModalIsOpen(false)); dispatch(setCheckCardModalIsOpen(false));
dispatch(resetCheckCardModal()); dispatch(resetCheckCardModal());
}} }}
...@@ -120,19 +84,33 @@ const CheckCardModal = () => { ...@@ -120,19 +84,33 @@ const CheckCardModal = () => {
onFocus={() => {}} onFocus={() => {}}
onBlur={() => {}} onBlur={() => {}}
> >
cancel submit
</Button> </Button>
) : ( {cancelAble ? (
<></> <Button
)} onClick={() => {
</> if (cancelResponse) {
} sendResponseHandler(onSubmit, [cancelResponse]);
modalRender={(modal) => ( }
<Draggable disabled={!draggable} bounds={bounds} onStart={onStart}> dispatch(setCheckCardModalIsOpen(false));
<div ref={draggleRef}>{modal}</div> dispatch(resetCheckCardModal());
</Draggable> }}
)} onMouseOver={onMouseOver}
width={800} onMouseOut={onMouseOut}
onFocus={() => {}}
onBlur={() => {}}
>
cancel
</Button>
) : (
<></>
)}
</>
),
width: 800,
}}
dragRef={draggleRef}
draggable={draggable}
> >
<CheckCard.Group <CheckCard.Group
multiple multiple
...@@ -181,7 +159,7 @@ const CheckCardModal = () => { ...@@ -181,7 +159,7 @@ const CheckCardModal = () => {
); );
})} })}
</CheckCard.Group> </CheckCard.Group>
</Modal> </DragModal>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment