日韩成人免费在线_国产成人一二_精品国产免费人成电影在线观..._日本一区二区三区久久久久久久久不

當前位置:首頁 > 科技  > 軟件

Next-Admin最佳實踐!支持可視化拖拽模塊

來源: 責編: 時間:2024-04-26 17:29:04 164觀看
導讀模塊演示圖片技術實現拖拽模塊我采用了 movable, 并研究了它的大量 API,最終實現了我想要的效果,當然我還設計了一套數據結構,如果大家對可視化搭建感興趣,也可以擴展成自己的拖拽搭建結構。圖片元素多選我采用了 selecto

模塊演示

圖片圖片nHK28資訊網——每日最新資訊28at.com

技術實現

拖拽模塊我采用了 movable, 并研究了它的大量 API,最終實現了我想要的效果,當然我還設計了一套數據結構,如果大家對可視化搭建感興趣,也可以擴展成自己的拖拽搭建結構。nHK28資訊網——每日最新資訊28at.com

圖片圖片nHK28資訊網——每日最新資訊28at.com

元素多選我采用了 selecto 模塊,成組管理器我采用了 @moveable/helper, 當然在使用這些庫的時候也踩了不少坑,好在已經完美解決。nHK28資訊網——每日最新資訊28at.com

下面分享一個簡單的數據結構,以支持我們的元素自由搭建:nHK28資訊網——每日最新資訊28at.com

const schema = {    "Button": {        id: 'wep_001',        name: 'Button',        type: 'base', // 基礎類型組件        base: {            width: 120,            height: 36,            transform: 'translate(100px,100px)'        }    },    "Image": {        id: 'wep_002',        name: 'Image',        type: 'base', // 基礎類型組件        base: {            width: 120,            height: 120,            url: '',            transform: 'translate(300px,160px)'        }    }}export default schema

工具條實現

圖片圖片nHK28資訊網——每日最新資訊28at.com

對于工具條的實現,我做了統一的封裝,以便后期可能更低成本的維護和管理:nHK28資訊網——每日最新資訊28at.com

  • config 工具條配置
  • actions 工具條選項對應的功能方法

接下來看看工具條的配置:nHK28資訊網——每日最新資訊28at.com

const toolbar = {    base: [        {            key: 'group',            icon: <GroupOutlined />,            text: '成組',        },        {            key: 'ungroup',            icon: <UngroupOutlined />,            text: '取消成組'        },        {            key: 'left',            icon: <AlignLeftOutlined />,            text: '左對齊'        },        // ... 其他工具條配置        {            key: 'v-space',            icon: <PicCenterOutlined />,            text: '垂直分布空間'        },        {            key: 'h-space',            icon: <PicCenterOutlined style={{transform: 'rotate(-90deg)'}} />,            text: '水平分布空間'        },            ]}

工具條方法封裝:nHK28資訊網——每日最新資訊28at.com

const handleOperate = (key: string) => {        // ... some function        // 頂對齊實現        if(key === 'top') {            const rect = moveableRef.current!.getRect();            // console.log(rect)            const moveables = moveableRef.current!.getMoveables();            if (moveables.length <= 1) {                return;            }            moveables.forEach(child => {                child.request<DraggableRequestParam>("draggable", {                    y: rect.top,                }, true);            });            moveableRef.current?.updateRect();            return        }        // 底對齊        if(key === 'bottom') {            const rect = moveableRef.current!.getRect();            const moveables = moveableRef.current!.getMoveables();            if (moveables.length <= 1) {                return;            }            moveables.forEach(child => {                child.request<DraggableRequestParam>("draggable", {                    y: rect.top + rect.height - (child.props?.target ? (child.props.target as any).offsetHeight : 0),                }, true);            });            moveableRef.current?.updateRect();            return        }        // ... 其他工具條方法        // 水平分布        if(key === 'h-space') {            const groupRect = moveableRef.current!.getRect();            const moveables = moveableRef.current!.getMoveables();            let left = groupRect.left;            if (moveables.length <= 1) {                return;            }            const gap = (groupRect.width - groupRect.children!.reduce((prev, cur) => {                return prev + cur.width;            }, 0)) / (moveables.length - 1);            moveables.sort((a, b) => {                return a.state.left - b.state.left;            });            moveables.forEach(child => {                const rect = child.getRect();                child.request<DraggableRequestParam>("draggable", {                    x: left,                }, true);                left += rect.width + gap;            });            moveableRef.current?.updateRect();            return        }    }

通過以上的封裝方式我們就能輕松擴展自己的工具條啦~nHK28資訊網——每日最新資訊28at.com

接下來我們看看工具條實現的效果:nHK28資訊網——每日最新資訊28at.com

圖片圖片nHK28資訊網——每日最新資訊28at.com

當然代碼我已經提交到 github 上了, 大家感興趣可以參考研究一下。nHK28資訊網——每日最新資訊28at.com

開源地址:https://github.com/MrXujiang/next-adminnHK28資訊網——每日最新資訊28at.com

多選 & 成組實現

圖片圖片nHK28資訊網——每日最新資訊28at.com

下面直接上代碼:nHK28資訊網——每日最新資訊28at.com

<Selecto    ref={selectoRef}    // dragCnotallow={container.current}    selectableTargets={[".wep-area .cube"]}    hitRate={0}    selectByClick={true}    selectFromInside={false}    toggleCnotallow={["shift"]}    ratio={0}    notallow={e => {        const moveable = moveableRef.current!;        const target = e.inputEvent.target;        const flatted = deepFlat(targets);        if (            target.tagName === "BUTTON"            || moveable.isMoveableElement(target)            || flatted.some(t => t === target || t.contains(target))        ) {            e.stop();        }        e.data.startTargets = targets;    }}    notallow={e => {        const {            startAdded,            startRemoved,            isDragStartEnd,        } = e;        if (isDragStartEnd) {            return;        }        const nextChilds = groupManager.selectSameDepthChilds(            e.data.startTargets,            startAdded,            startRemoved,        );        setSelectedTargets(nextChilds.targets());    }}    notallow={e => {        const {            isDragStartEnd,            isClick,            added,            removed,            inputEvent,        } = e;        const moveable = moveableRef.current!;        if (isDragStartEnd) {            inputEvent.preventDefault();            moveable.waitToChangeTarget().then(() => {                moveable.dragStart(inputEvent);            });        }        let nextChilds: TargetList;        if (isDragStartEnd || isClick) {            if (isCommand) {                nextChilds = groupManager.selectSingleChilds(targets, added, removed);            } else {                nextChilds = groupManager.selectCompletedChilds(targets, added, removed, isShift);            }        } else {            nextChilds = groupManager.selectSameDepthChilds(e.data.startTargets, added, removed);        }        e.currentTarget.setSelectedTargets(nextChilds.flatten());        setSelectedTargets(nextChilds.targets());    }}></Selecto>

完整代碼都同步到 Next-Admin 了, 如果大家感興趣也可以研究一下。nHK28資訊網——每日最新資訊28at.com

nHK28資訊網——每日最新資訊28at.com

本文鏈接:http://www.www897cc.com/showinfo-26-85858-0.htmlNext-Admin最佳實踐!支持可視化拖拽模塊

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 每位開發者都需要知道的七個Django命令

下一篇: Go 語言入門指南:基礎語法和常用特性解析

標簽:
  • 熱門焦點
  • 影音體驗是真的強 簡單聊聊iQOO Pad

    大公司的好處就是產品線豐富,非常細分化的東西也能給你做出來,例如早先我們看到了新的vivo Pad2,之后我們又在iQOO Neo8 Pro的發布會上看到了iQOO的首款平板產品iQOO Pad。雖
  • 跑分安卓第一!Redmi K60至尊版8月發布!盧偉冰:目標年度性能之王

    8月5日消息,Redmi K60至尊版將于8月發布,在此前舉行的戰略發布會上,官方該機將搭載搭載天璣9200+處理器,安兔兔V10跑分超177萬分,是目前安卓陣營最高的分數
  • Raft算法:保障分布式系統共識的穩健之道

    1. 什么是Raft算法?Raft 是英文”Reliable、Replicated、Redundant、And Fault-Tolerant”(“可靠、可復制、可冗余、可容錯”)的首字母縮寫。Raft算法是一種用于在分布式系統
  • 2023 年的 Node.js 生態系統

    隨著技術的不斷演進和創新,Node.js 在 2023 年達到了一個新的高度。Node.js 擁有一個龐大的生態系統,可以幫助開發人員更快地實現復雜的應用。本文就來看看 Node.js 最新的生
  • .NET 程序的 GDI 句柄泄露的再反思

    一、背景1. 講故事上個月我寫過一篇 如何洞察 C# 程序的 GDI 句柄泄露 文章,當時用的是 GDIView + WinDbg 把問題搞定,前者用來定位泄露資源,后者用來定位泄露代碼,后面有朋友反
  • 使用AIGC工具提升安全工作效率

    在日常工作中,安全人員可能會涉及各種各樣的安全任務,包括但不限于:開發某些安全工具的插件,滿足自己特定的安全需求;自定義github搜索工具,快速查找所需的安全資料、漏洞poc、exp
  • “又被陳思誠騙了”

    作者|張思齊 出品|眾面(ID:ZhongMian_ZM)如今的國產懸疑電影,成了陳思誠的天下。最近大爆電影《消失的她》票房突破30億斷層奪魁暑期檔,陳思誠再度風頭無兩。你可以說陳思誠的
  • 自研Exynos回歸!三星Galaxy S24系列將提供Exynos和驍龍雙版本

    年初,全新的三星Galaxy S23系列發布,包含Galaxy S23、Galaxy S23+和Galaxy S23 Ultra三個版本,全系搭載超頻版驍龍8 Gen 2,雖同樣采用臺積電4nm工藝制
  • 首發天璣9200+ iQOO Neo8系列發布首銷售價2299元起

    2023年5月23日晚,iQOO Neo8系列正式發布。其中,Neo系列首款Pro之作——iQOO Neo8 Pro強悍登場,限時售價3099元起;價位段最強性能手機iQOO Neo8同期上市
Top 主站蜘蛛池模板: 衡阳县| 瓦房店市| 贵州省| 梁河县| 郧西县| 永登县| 乌苏市| 怀集县| 瓦房店市| 寻乌县| 明光市| 嫩江县| 隆子县| 龙川县| 东海县| 沅江市| 莱芜市| 昭平县| 长白| 新兴县| 南雄市| 阿拉善盟| 南岸区| 大港区| 广汉市| 乌恰县| 湘潭县| 龙陵县| 社会| 若尔盖县| 沂南县| 诏安县| 牟定县| 镇远县| 瑞丽市| 崇礼县| 来安县| 阿尔山市| 疏勒县| 剑阁县| 山西省|