From e1cee96b38805bcccf48e7bcb9d296f2bc54c720 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 24 一月 2025 11:10:32 +0800 Subject: [PATCH] 2025-01-24 --- src/menu/tableshell/index.jsx | 109 +++++++++++++++++++++++++++++++----------------------- 1 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/menu/tableshell/index.jsx b/src/menu/tableshell/index.jsx index 0346d43..defc741 100644 --- a/src/menu/tableshell/index.jsx +++ b/src/menu/tableshell/index.jsx @@ -1,5 +1,6 @@ import React, { useState } from 'react' import { useDrop } from 'react-dnd' +import { is, fromJS } from 'immutable' import update from 'immutability-helper' import { Modal } from 'antd' @@ -11,14 +12,8 @@ const Container = ({menu, handleList }) => { const [cards, setCards] = useState(menu.components) - const moveCard = (id, atIndex) => { - const { card, index } = findCard(id) - const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] }) - handleList({...menu, components: _cards}) - setCards(_cards) - } - if (menu.components.length > cards.length) { + if (!is(fromJS(cards), fromJS(menu.components))) { setCards(menu.components) } @@ -31,30 +26,65 @@ } const updateConfig = (element) => { - const _cards = cards.map(item => item.uuid === element.uuid ? element : item) + let _cards = cards.map(item => item.uuid === element.uuid ? element : item) + + if (element.type === 'tabs' && element.subtabs.length === 0) { + _cards = cards.filter(item => item.uuid !== element.uuid) + } + handleList({...menu, components: _cards}) - setCards(_cards) + } + + const switchConfig = (dragKey, hoverKey, callback) => { + let _tab = null + + let hoverTabsIndex = 0 + let hoverIndex = 0 + let _cards = cards.map((item, pindex) => { + if (item.type === 'tabs') { + item.subtabs = item.subtabs.filter((tab, index) => { + if (tab.uuid === dragKey) { + _tab = tab + return false + } + if (tab.uuid === hoverKey) { + hoverTabsIndex = pindex + hoverIndex = index + } + return true + }) + } + return item + }) + + if (hoverTabsIndex && _tab) { + _cards[hoverTabsIndex].subtabs.splice(hoverIndex + 1, 0, _tab) + } else { + return + } + + _cards = _cards.filter(item => { + if (item.type !== 'tabs') return true + if (item.subtabs.length === 0) return false + + return true + }) + + handleList({...menu, components: _cards}) + + setTimeout(() => { + callback() + }, 100) } const deleteCard = (id) => { const { card } = findCard(id) - let hasComponent = false - if (card.type === 'tabs') { - card.subtabs.forEach(tab => { - if (tab.components.length > 0) { - hasComponent = true - } - }) - } - confirm({ - title: `纭畾鍒犻櫎銆�${card.name}銆嬪悧锛焋, - content: hasComponent ? '褰撳墠缁勪欢涓惈鏈夊瓙缁勪欢锛�' : '', + title: `纭畾鍒犻櫎瀛愯〃缁勫悧锛焋, onOk() { const _cards = cards.filter(item => item.uuid !== card.uuid) handleList({...menu, components: _cards}) - setCards(_cards) }, onCancel() {} }) @@ -63,35 +93,16 @@ const [, drop] = useDrop({ accept: 'menu', drop(item) { - if (item.hasOwnProperty('originalIndex') || item.added) { + if (item.added || item.index) { delete item.added // 鍒犻櫎缁勪欢娣诲姞鏍囪 + delete item.dropTargetId return } - - let name = '' - let names = { - tabs: '鏍囩缁�' - } - let i = 1 - while (!name && names[item.component]) { - let _name = names[item.component] + i - if (menu.components.filter(com => com.name === _name).length === 0) { - name = _name - } - i++ - } - let newcard = { uuid: Utils.getuuid(), - type: item.component, - subtype: item.subtype, - config: item.config, - width: item.width || 24, - dataName: Utils.getdataName(), - name: name, - floor: 1, // 缁勪欢鐨勫眰绾� - isNew: true // 鏂版坊鍔犳爣蹇楋紝鐢ㄤ簬鍒濆鍖� + type: 'tabs', + isNew: true } let targetId = '' @@ -106,23 +117,27 @@ const { index: overIndex } = findCard(`${targetId}`) const _cards = update(cards, { $splice: [[overIndex + 1, 0, newcard]] }) + // setCards(_cards) handleList({...menu, components: _cards}) - setCards(_cards) } }) + let style = JSON.stringify(menu.style || {}) + style = style.replace(/@mywebsite@\//ig, window.GLOB.baseurl) + style = JSON.parse(style) + return ( - <div ref={drop} className="table-shell-inner" style={menu.style}> + <div ref={drop} className="table-shell-inner" style={style}> <div className="ant-row"> {cards.map(card => ( <Card id={card.uuid} key={card.uuid} card={card} - moveCard={moveCard} delCard={deleteCard} findCard={findCard} updateConfig={updateConfig} + switchConfig={switchConfig} /> ))} </div> -- Gitblit v1.8.0