在實現(xiàn)復制前,對之前的拖拽排序組件屬性進行了修改。
拖拽復制的效果如下:
由于實現(xiàn)組件的核心是根據(jù)value數(shù)據(jù)來渲染頁面,因此實現(xiàn)拖拽復制功能,只需要在“拖拽釋放”的時候,將被拖拽方的數(shù)據(jù)放到當前目標所在的value數(shù)組中即可。
具體實現(xiàn)代碼如下:
// 當一個元素或是選中的文字被拖拽釋放到一個有效的釋放目標位置時 drop(dropedSort, data, sortKey, dropedUid, codeKey, ee) { ee.preventDefault(); const code = ee.dataTransfer.getData("code"); const uId = ee.dataTransfer.getData("uId"); const dragedItem = ee.dataTransfer.getData("item"); const sort = ee.dataTransfer.getData("sort"); if (uId === dropedUid) { if (sort < dropedSort) { data.map(item => { if (item[codeKey] === code) { item[sortKey] = dropedSort; } else if (item[sortKey] > sort && item[sortKey] < dropedSort + 1) { item[sortKey]--; } return item; }); } else { data.map(item => { if (item[codeKey] === code) { item[sortKey] = dropedSort; } else if (item[sortKey] > dropedSort - 1 && item[sortKey] < sort) { item[sortKey]++; } return item; }); } } else if (this.props.isAcceptAdd) { let objDragedItem = JSON.parse(dragedItem); if (data.filter(item => item[codeKey] === objDragedItem[codeKey]).length === 0) { const maxSort = Math.max.apply(Math, data.map(citem => citem[sortKey])); data.map(item => { if (dropedSort === maxSort) { objDragedItem[sortKey] = dropedSort + 1; } else { if (item.sort > dropedSort) { objDragedItem[sortKey] = dropedSort + 1; item[sortKey]++ } } return item }); data.push(objDragedItem) } } this.props.onChange(data) if (ee.target.className.indexOf('droppingContent') !== -1) { ee.target.className = styles.droppedcontent; } }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。