当前位置: 首页 > wzjs >正文

婚庆网站源码扬州恒通建设网站

婚庆网站源码,扬州恒通建设网站,芯火信息做网站怎么样,腾讯网站安全检测分享原因 由于项目中需要使用拖曳组件(需求:全局,跨组件,跨数据),我选择了react-dnd 概念 React DnD 是一组 React 高阶组件,我们在使用的时候只需要将目标元素进行包裹,就可以实现目标元素具有拖动或接受拖动的功能。…

分享原因

由于项目中需要使用拖曳组件(需求:全局,跨组件,跨数据),我选择了react-dnd

概念

React DnD 是一组 React 高阶组件,我们在使用的时候只需要将目标元素进行包裹,就可以实现目标元素具有拖动或接受拖动的功能。它将整个拖动的事件完整的描述了出来,这使得我们在使用的过程变得简单易用和扩展上有了无限的可能,在处理复杂拖曳和丰富需求的时候强烈建议使用它。
官网 https://react-dnd.github.io/react-dnd/

基本

  • Item type:跟redux或其他组件一样,item用来描述拖动dom的数据对象,type用来标识一组可拖动和接收
  • Backend:用来表现dom拖动现象,我使用了HTML5Backend
  • Monitors:用来查询当前拖动状态(数据,dom,位置等),强大的收集功能
  • Connectors:用于Backend和组件状态之间的连接
  • hook:useDrag 将组件作为可拖动的来源注册到dnd useDrop 将组件作为可接收拖动来源注册到dnd

使用方法

导入
npm install react-dnd react-dnd-html5-backend
初始化

import { HTML5Backend } from 'react-dnd-html5-backend';<DndProvider backend={HTML5Backend}>....</>

组件参数type.ts

export type DragProps = {name: string; //名称标记type: string; //暂用于标记拖拽类型,接收者和发送者一致role: string; //data: any; //绑定的数据用于拖曳后操作数据content: JSX.Element; //绑定的元素onDragFinished: Function; //拖动结束回调.
};export type AcceptorProps = {name: string; //名称标记type: string; //暂用于标记拖拽类型,接收者和发送者一致role: string; //data: any; //绑定的数据用于拖曳后操作数据content: JSX.Element; //绑定的元素styleType: 'background' | 'border';// customStyle:{//     canDrop:string,//     isActive:string// }onHover: Function; //移入区域.
};

组件MyDrag.ts

import { useDrag, useDrop } from 'react-dnd';
import { DragProps, AcceptorProps } from './type';
export const Dragger = function Dragger(option: DragProps) {const { name, data, type, onDragFinished } = option;const [{ isDragging }, drag] = useDrag(() => ({type: type,item: { name: name, data: data },end: (item, monitor, ...arg) => {console.log(arg);const dropResult = monitor.getDropResult();if (item && dropResult) {console.log('source:', item);console.log('target:', dropResult);}if (onDragFinished) {onDragFinished(item, dropResult);}},collect: (monitor) => ({isDragging: monitor.isDragging(),handlerId: monitor.getHandlerId(),}),}));const opacity = isDragging ? 0.4 : 1;return (<divref={drag}role={option.role}style={{ opacity }}data-id={`${option.name}`}>{option.content}</div>);
};
export const Acceptor = (option: AcceptorProps) => {const { name, data, type, styleType, onHover } = option;const [{ canDrop, isOver }, drop] = useDrop(() => ({accept: type,drop: () => option,hover: () => {if (onHover) {onHover();}},collect: (monitor) => ({isOver: monitor.isOver(),canDrop: monitor.canDrop(),}),}));const isActive = canDrop && isOver;let backgroundColor = '#222';let borderBottom = '0px solid rgba(31, 92, 206, 0)';if (isActive) {backgroundColor = 'rgba(64, 224, 208, 0.3)';borderBottom = '1px solid #26BD11';} else if (canDrop) {backgroundColor = 'rgba(100, 149, 277, 0.3)';borderBottom = '1px solid #2063AF';}return (<divref={drop}role={'Acceptor'}style={styleType === 'background'? { backgroundColor }: { borderBottom }}>{option.content}</div>);
};
//同一list之间拖动
export const dragList = (list: Array<any>,crtIndex: number,willIndex: number,
) => {let targetItem = list[crtIndex];let delIndex = crtIndex < willIndex ? crtIndex : crtIndex + 1;list.splice(willIndex, 0, targetItem);list.splice(delIndex, 1);return list;
};
//来自不同list之间拖动,1.删除原来  2不删除原来
export const dragToList = (list: Array<any>,targetList: Array<any>,crtIndex: number,willIndex: number,del: 1 | 2,
) => {let targetItem = list[crtIndex];targetList.splice(willIndex, 0, targetItem);if (del === 1) {list.splice(crtIndex, 1);}return { list, targetList };
};

具体使用

import { Dragger, Acceptor, dragList } from '@/components/Drag';
//同列表之间拖曳handleDrag(crt: number, target: number) {conslog.log(dragList(newPanels, crt, target);)}renderDrag(item: ItemProps, children) {<Acceptorkey={item.type}name={item.title}data={item}type="xxx"role="xxxAccept"onHover={() => {}}content={<Draggername={item.title}data={item}type="xxx"role="xxxDrag"content={children}onDragFinished={(source: any, target: any) => {console.log(source, target, '回调');if (target) {this.handleDrag(source.data.sort,target.data.sort,);}}}/>}styleType="border"/>}


喜欢的朋友记得点赞、收藏、关注哦!!!


文章转载自:

http://JD072ImY.mnkhk.cn
http://y0B6z6fn.mnkhk.cn
http://XzzjzFzW.mnkhk.cn
http://fkV7QAcN.mnkhk.cn
http://QfxT9d5s.mnkhk.cn
http://28Mu4nqX.mnkhk.cn
http://fhUsMW1C.mnkhk.cn
http://yQaUsT8n.mnkhk.cn
http://lsu9jrJg.mnkhk.cn
http://3XxNFt6M.mnkhk.cn
http://Xa84asEH.mnkhk.cn
http://ptdEgBZ2.mnkhk.cn
http://iu5QHzvL.mnkhk.cn
http://uJHrBfzV.mnkhk.cn
http://ymAdupmz.mnkhk.cn
http://jhIoPYkC.mnkhk.cn
http://WWX2WeIE.mnkhk.cn
http://rsSvDoeZ.mnkhk.cn
http://Zoci0fDF.mnkhk.cn
http://IcT9lHEs.mnkhk.cn
http://IpTFg25L.mnkhk.cn
http://pmC7RJcS.mnkhk.cn
http://YMz9iMZQ.mnkhk.cn
http://MptT4ro9.mnkhk.cn
http://E4lUqumc.mnkhk.cn
http://iTr95zhq.mnkhk.cn
http://mTTzc1qb.mnkhk.cn
http://e9N3UgEP.mnkhk.cn
http://s4gfurDq.mnkhk.cn
http://opCrZKKG.mnkhk.cn
http://www.dtcms.com/wzjs/624195.html

相关文章:

  • 河南省招生网站服务平台免费网站的代码
  • 嵊州哪里可以做网站创意网页设计模板
  • 网站建设合同 费用网站维护多少钱一个月
  • python做网站用什么惠山网站建设
  • dede程序网站如何查看百度蜘蛛分析网页设计
  • 怎样分析网站做seo网络工具
  • 网站服务包括什么网站短信通知
  • 网站推广的10种方法wordpress拖曳组件
  • 新手学做网站难吗wordpress 主页文件
  • 深圳企业网站建设哪家专业江门网站建设设计
  • 网站违反了 google 质量指南网站模块 带采集
  • 做微信的网站叫什么米厦门网站建设114
  • 柳州住房和城乡建设厅网站网页制作实践 做网站
  • 理县网站建设开发直播平台网站
  • 东莞网站推广优化网站关于网站设计的价格
  • 帝国cms能建设视频网站吗建设旅游网站需要多少钱
  • 怎样建立企业网站用wordpress建站多少钱
  • 东莞凤岗哪里有学做网站的贵阳微网站建设公司哪家好
  • 山西网站开发培训网站未备案wordpress链接
  • 分析电子商务网站建设需求教案最好的买房app排行榜
  • 宝塔面板做网站不能打开PHP显示404报名网站如何做
  • 电脑网站安全证书有问题如何解决如何做双版网站
  • 郑州网站关不干胶网站做最好的
  • 通州区建设局网站手表网站功能设计
  • 网站引导页怎么做的微信公众号的微网站开发
  • 企业设计网站公司长春哪家网络公司做网站专业
  • 怀远县建设局门户网站大连企业做网站
  • 做影视网站须要注意什么关于网站建设营销类文章
  • 电子商务网站建设和管理腾讯云服务器免费
  • 网站创建域名海南省住房建设厅网站首页