mirror of
https://github.com/MrXujiang/h5-Dooring.git
synced 2025-12-15 04:12:49 +00:00
🎨 删除暂时还有bug问题 todo
This commit is contained in:
parent
937a0d9bf3
commit
64b4e9b4ef
@ -7,6 +7,7 @@ import React, {
|
|||||||
useMemo,
|
useMemo,
|
||||||
useState,
|
useState,
|
||||||
createRef,
|
createRef,
|
||||||
|
useDebugValue,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { useDrop } from 'react-dnd';
|
import { useDrop } from 'react-dnd';
|
||||||
import Draggable, { DraggableData, DraggableEvent } from 'react-draggable';
|
import Draggable, { DraggableData, DraggableEvent } from 'react-draggable';
|
||||||
@ -20,7 +21,11 @@ import { Dispatch } from 'umi';
|
|||||||
import { StateWithHistory } from 'redux-undo';
|
import { StateWithHistory } from 'redux-undo';
|
||||||
import { dooringContext } from '@/layouts';
|
import { dooringContext } from '@/layouts';
|
||||||
interface SourceBoxProps {
|
interface SourceBoxProps {
|
||||||
pstate: { pointData: { id: string; item: any; point: any; isMenu?: any }[]; curPoint: any };
|
pstate: {
|
||||||
|
pointData: { id: string; item: any; point: any; isMenu?: any }[];
|
||||||
|
curPoint: any;
|
||||||
|
status: string;
|
||||||
|
};
|
||||||
cstate: { pointData: { id: string; item: any; point: any }[]; curPoint: any };
|
cstate: { pointData: { id: string; item: any; point: any }[]; curPoint: any };
|
||||||
scaleNum: number;
|
scaleNum: number;
|
||||||
canvasId: string;
|
canvasId: string;
|
||||||
@ -33,19 +38,30 @@ interface SourceBoxProps {
|
|||||||
y: number;
|
y: number;
|
||||||
}>
|
}>
|
||||||
>;
|
>;
|
||||||
|
pointData: { id: string; item: any; point: any; isMenu?: any }[];
|
||||||
|
setPointData: React.Dispatch<
|
||||||
|
React.SetStateAction<
|
||||||
|
{
|
||||||
|
id: string;
|
||||||
|
item: any;
|
||||||
|
point: any;
|
||||||
|
isMenu?: any;
|
||||||
|
}[]
|
||||||
|
>
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SourceBox = memo((props: SourceBoxProps) => {
|
const SourceBox = memo((props: SourceBoxProps) => {
|
||||||
const { pstate, scaleNum, canvasId, allType, dispatch, dragState, setDragState, cstate } = props;
|
const { pstate, scaleNum, canvasId, allType, dispatch, dragState, setDragState, cstate } = props;
|
||||||
const context = useContext(dooringContext);
|
const context = useContext(dooringContext);
|
||||||
|
|
||||||
let pointData = pstate ? pstate.pointData : [];
|
const dataState = pstate ? pstate.pointData : [];
|
||||||
const cpointData = cstate ? cstate.pointData : [];
|
const cpointData = cstate ? cstate.pointData : [];
|
||||||
|
|
||||||
const [canvasRect, setCanvasRect] = useState<number[]>([]);
|
const [canvasRect, setCanvasRect] = useState<number[]>([]);
|
||||||
const [isShowTip, setIsShowTip] = useState(true);
|
const [isShowTip, setIsShowTip] = useState(true);
|
||||||
const [clonePointData, setPointData] = useState(pointData);
|
|
||||||
const [isMenu, setIsMenu] = useState(false);
|
const [pointData, setPointData] = useState(dataState);
|
||||||
|
// const [isCurrentCard, setCurrentCard] = useState(false);
|
||||||
const [{ isOver }, drop] = useDrop({
|
const [{ isOver }, drop] = useDrop({
|
||||||
accept: allType,
|
accept: allType,
|
||||||
drop: (item: { h: number; type: string; x: number }, monitor) => {
|
drop: (item: { h: number; type: string; x: number }, monitor) => {
|
||||||
@ -148,6 +164,45 @@ const SourceBox = memo((props: SourceBoxProps) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [context.theme, cpointData, dispatch, pointData]);
|
}, [context.theme, cpointData, dispatch, pointData]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let { width, height } = document.getElementById(canvasId)!.getBoundingClientRect();
|
||||||
|
console.log(width, height);
|
||||||
|
setCanvasRect([width, height]);
|
||||||
|
}, [canvasId, context.theme]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let timer = window.setTimeout(() => {
|
||||||
|
setIsShowTip(false);
|
||||||
|
}, 3000);
|
||||||
|
return () => {
|
||||||
|
window.clearTimeout(timer);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// let isCuurentPoint = pointData.some(item => +item.id === (pstate.curPoint && +pstate.curPoint.id))
|
||||||
|
// if(isCuurentPoint && pstate.curPoint.status === 'inToCanvas') {
|
||||||
|
// setPointData(dataState)
|
||||||
|
// }
|
||||||
|
if (pointData.some(item => item.isMenu)) {
|
||||||
|
//.
|
||||||
|
} else {
|
||||||
|
setPointData(dataState);
|
||||||
|
}
|
||||||
|
}, [dataState]);
|
||||||
|
|
||||||
|
const handleDelete: Function = useMemo(() => {
|
||||||
|
return (id: any) => {
|
||||||
|
dispatch({
|
||||||
|
type: 'editorModal/delPointData',
|
||||||
|
payload: { id },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}, [dispatch]);
|
||||||
|
|
||||||
|
const opacity = isOver ? 0.7 : 1;
|
||||||
|
|
||||||
const initSelect: any = (data: any = []) => {
|
const initSelect: any = (data: any = []) => {
|
||||||
return (
|
return (
|
||||||
data &&
|
data &&
|
||||||
@ -157,40 +212,22 @@ const SourceBox = memo((props: SourceBoxProps) => {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
|
||||||
let { width, height } = document.getElementById(canvasId)!.getBoundingClientRect();
|
|
||||||
console.log(width, height);
|
|
||||||
setCanvasRect([width, height]);
|
|
||||||
}, [canvasId, context.theme]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setPointData(initSelect(pointData));
|
|
||||||
let timer = window.setTimeout(() => {
|
|
||||||
setIsShowTip(false);
|
|
||||||
}, 3000);
|
|
||||||
return () => {
|
|
||||||
window.clearTimeout(timer);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
const opacity = isOver ? 0.7 : 1;
|
|
||||||
const handleCurrentCard: Function = useCallback(
|
const handleCurrentCard: Function = useCallback(
|
||||||
(e: Event, status: boolean, index: number) => {
|
(e: Event, status: boolean, index: number) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsMenu(false);
|
let pointDataOnMenu: any;
|
||||||
if (status) {
|
(pointDataOnMenu = initSelect(dataState)) &&
|
||||||
setIsMenu(true);
|
Object.keys(pointDataOnMenu).map(keyId => {
|
||||||
} else {
|
(+pointDataOnMenu[+keyId].id === +index && (pointDataOnMenu[+keyId].isMenu = status)) ||
|
||||||
setIsMenu(false);
|
(pointDataOnMenu[+keyId].isMenu = false);
|
||||||
}
|
|
||||||
(pointData = initSelect(pointData)) &&
|
|
||||||
Object.keys(pointData).map(keyId => {
|
|
||||||
(+pointData[+keyId].id === +index && (pointData[+keyId].isMenu = status)) ||
|
|
||||||
(pointData[+keyId].isMenu = false);
|
|
||||||
});
|
});
|
||||||
setPointData(pointData);
|
setPointData(pointDataOnMenu);
|
||||||
|
// setCurrentCard(true)
|
||||||
},
|
},
|
||||||
[status, pointData],
|
[status],
|
||||||
);
|
);
|
||||||
|
|
||||||
const render = useMemo(() => {
|
const render = useMemo(() => {
|
||||||
if (context.theme === 'h5') {
|
if (context.theme === 'h5') {
|
||||||
return (
|
return (
|
||||||
@ -251,19 +288,21 @@ const SourceBox = memo((props: SourceBoxProps) => {
|
|||||||
className={value.isMenu ? styles.selected : styles.dragItem}
|
className={value.isMenu ? styles.selected : styles.dragItem}
|
||||||
key={value.id}
|
key={value.id}
|
||||||
data-grid={value.point}
|
data-grid={value.point}
|
||||||
|
onMouseDownCapture={e => handleCurrentCard(e, true, value.id)}
|
||||||
|
onDragLeave={e => handleCurrentCard(e, false, value.id)}
|
||||||
>
|
>
|
||||||
<DynamicEngine {...value.item} isTpl={false} />
|
<DynamicEngine {...value.item} isTpl={false} />
|
||||||
{/* <div
|
<div
|
||||||
className={styles.tooltip}
|
className={styles.tooltip}
|
||||||
style={{ display: value.isMenu ? 'block' : 'none' }}
|
style={{ display: value.isMenu ? 'block' : 'none' }}
|
||||||
>
|
>
|
||||||
<div className="tooltipRow1">
|
<div className={styles.tooltipRow1}>
|
||||||
<a>恢复</a>
|
<a>恢复</a>
|
||||||
</div>
|
</div>
|
||||||
<div className="tooltipRow2">
|
<div className={styles.tooltipRow2}>
|
||||||
<a>删除</a>
|
<Button onClick={handleDelete.bind(this, value.id)}>删除</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div> */}
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
@ -396,7 +435,6 @@ const SourceBox = memo((props: SourceBoxProps) => {
|
|||||||
pointData,
|
pointData,
|
||||||
scaleNum,
|
scaleNum,
|
||||||
setDragState,
|
setDragState,
|
||||||
clonePointData,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return <>{render}</>;
|
return <>{render}</>;
|
||||||
|
|||||||
@ -142,9 +142,26 @@
|
|||||||
border: 2px solid #06c;
|
border: 2px solid #06c;
|
||||||
.tooltip {
|
.tooltip {
|
||||||
position: relative;
|
position: relative;
|
||||||
// z-index: 999999;
|
width: 161px;
|
||||||
width: 388px;
|
height: 80px;
|
||||||
text-align: right;
|
background: #ffffff;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid #dbdbdb;
|
||||||
|
text-align: center;
|
||||||
|
.tooltipRow1 {
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
a {
|
||||||
|
color: #4a4a4a;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.tooltipRow2 {
|
||||||
|
a {
|
||||||
|
color: #ff001f;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
* @Autor: dragon
|
* @Autor: dragon
|
||||||
* @Date: 2020-09-24 10:11:24
|
* @Date: 2020-09-24 10:11:24
|
||||||
* @LastEditors: dragon
|
* @LastEditors: dragon
|
||||||
* @LastEditTime: 2020-10-08 16:12:26
|
* @LastEditTime: 2020-10-13 01:08:08
|
||||||
*/
|
*/
|
||||||
const pointData = localStorage.getItem('userData') || '[]';
|
const pointData = localStorage.getItem('userData') || '[]';
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user