亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

react拖拽組件react-sortable-hoc的使用

瀏覽:104日期:2022-06-01 17:55:24
目錄
  • 1.文件1
  • 2.文件2
  • 3.使用

使用react-sortable-hoc實現拖拽

如圖:

提示:下面案例可供參考

1.文件1

代碼如下(示例):文件名稱:./dragcomponents

import * as React from "react"import {    sortableContainer,    sortableElement,    sortableHandle,} from "react-sortable-hoc"; // 拖拽的關鍵組件const Sortable: React.FC<any> = (props) => {    const { dataSource = [], ComSortItem, sortEnd } = props;    // 拖拽時原列表替換    function arrayMoveMutable(array, fromIndex, toIndex) {const startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex;if (startIndex >= 0 && startIndex < array.length) {    const endIndex = toIndex < 0 ? array.length + toIndex : toIndex;    const [item] = array.splice(fromIndex, 1);    array.splice(endIndex, 0, item);}    }    // 拖拽時返回新數組    function arrayMoveImmutable(array, fromIndex, toIndex) {array = [...array];arrayMoveMutable(array, fromIndex, toIndex);return array;    }    // 拖拽容器    const SortableContainer = sortableContainer(({ children }) => {return <div>{children}</div>;    });    // 拖拽ico    const DragHandle = sortableHandle((value1, sortIndex1) => (<div id="ListItem" className="ListItem" >    <div className="ChildCom"><ComSortItem data={value1} index={sortIndex1} updateData={updateData} />    </div></div>    ));    function handleDelete(index) {const List = [...dataSource];List.splice(index, 1)sortEnd(List);    }    // 數據更新    function updateData(val, index) {const List = [...dataSource];List[index] = val;sortEnd(List);    }    // 拖拽體    const SortableItem = sortableElement(({ value, sortIndex }) => {return (    // <div id="ListItem" className="ListItem" >    //     <DragHandle value1={value} sortIndex1={sortIndex} />    // </div>    <DragHandle valuedata={value} sortIndexdata={sortIndex} />);    });    // 拖拽后回調    const onSortEnd = ({ oldIndex, newIndex }) => {const List = arrayMoveImmutable(dataSource, oldIndex, newIndex);sortEnd(List);    };    return (<>    <SortableContainer onSortEnd={onSortEnd} useDragHandle helperClass="row-dragging-item">{dataSource.length > 0 &&    dataSource.map((value, index) => (<SortableItem    key={`sortable-item-${index}`}    index={index}    value={value}    sortIndex={index}/>    ))}    </SortableContainer></>    );}export default Sortable;

2.文件2

代碼如下(示例):文件名稱’./usedrag’

import * as React from "react"import { Checkbox } from "antd"import Sortable from "./dragcomponents"import "./index.scss"const _ = require("lodash")import store from "./store"import { SAVE_RENDER_ALL_DATA } from "./actionType"const Usedrag: React.FC<any> = (props) => {    const { state, dispatch } = React.useContext(store);    // 自定義拖拽體    const {upDateRenderData} = props    const showdata ={...props.renderData}    function AddForm(showdata) {return (    < div className="ItemBox"><div className="name"><span className="icon iconfont iconyidongshu"></span>{showdata.data.valuedata.fieldName}</div><div className="Opt">    <span>控件標簽顯示名稱<span>{showdata.data.valuedata.labelName}</span></span>    <span>所占列寬<span>{showdata.data.valuedata.span}</span></span>    {/* <Checkbox onChange={changeChecked} checked={checked} ></Checkbox> */}</div>    </div>)    }    const updateSource = (val) => {const arrdata: any = _.cloneDeep(props.renderData)const arr: any = _.cloneDeep(val)if(JSON.stringify(arrdata) !== JSON.stringify(arr)){    for (let i = 0; i <= arr.length - 1; i++) {arr[i].edit = 1;    }}// upDateRenderData(arr)dispatch({    type: SAVE_RENDER_ALL_DATA,    value: arr})    }    return (<div className="RightBox" >    <div className="item-con" style={{ overflow: "auto" }}><Sortable    className="sortable"    dataSource={...props.renderData}    ComSortItem={(p) => <AddForm {...p} />}    sortEnd={(val) => {updateSource(val)    }}/>    </div></div>    );};export default Usedrag

3.使用

代碼如下(示例):

import Usedrag from "./usedrag";<Usedrag renderData={renderData}/>

到此這篇關于react拖拽組件react-sortable-hoc的使用的文章就介紹到這了,更多相關react拖拽組件react-sortable-hoc內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: JavaScript
主站蜘蛛池模板: 6969精品视频在线观看 | 一区二区在线精品免费视频 | 国产精品一区高清在线观看 | 蜜桃视频一区二区在线观看 | 日本韩国一级 | 日本美女黄色片 | 精品国产理论在线观看不卡 | a三级黄色片 | 国产原创一区 | 老湿机一区午夜精品免费福利 | 亚洲欧美一区二区三区久久 | 成人午夜大片免费视频77777 | 97视频免费看 | 国产大尺度福利视频在线观看 | 日韩欧美精品综合一区二区三区 | 美美女高清毛片视频黄的一免费 | 欧美亚洲一区 | 一 级 黄 中国色 片 | 国产在线视频www片 国产在线视频www色 | 高清日韩在线 | 欧美一级亚洲一级 | 91视频看看| 日日好吊妞 | 国产精品福利一区二区亚瑟 | 国内精品视频区在线2021 | 全免费a级毛片免费毛视频 全免费a级毛片免费看 | 538prom在线| 国产精品免费大片一区二区 | 国内精品一区二区 | 综合激情区视频一区视频二区 | 国产网红在线视频 | 亚洲精品99久久久久久欧美版 | aaa黑人一级毛片 | 国产成人综合一区精品 | 黑人狂躁日本妞中文字幕 | 色播久久| 精品日韩欧美国产一区二区 | 久久这里只有精品99 | 久久国产精品老人性 | 大胆国模一区二区三区伊人 | 久久国产乱子伦精品免 |