From f393af9623c26ae177a3f69b8676afc4e23bff8d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 08 二月 2022 14:48:51 +0800
Subject: [PATCH] 2022-02-08

---
 src/menu/pastecontroller/index.jsx |  202 ++++++++++++--------------------------------------
 1 files changed, 50 insertions(+), 152 deletions(-)

diff --git a/src/menu/pastecontroller/index.jsx b/src/menu/pastecontroller/index.jsx
index 12a510d..8ed2307 100644
--- a/src/menu/pastecontroller/index.jsx
+++ b/src/menu/pastecontroller/index.jsx
@@ -1,17 +1,17 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Icon, Modal, Button, notification } from 'antd'
+import { Modal, Button, notification } from 'antd'
+import { SnippetsOutlined } from '@ant-design/icons'
 
-import Utils from '@/utils/utils.js'
+import MenuUtils from '@/utils/utils-custom.js'
+import MKEmitter from '@/utils/events.js'
 import asyncComponent from '@/utils/asyncComponent'
-import './index.scss'
+// import './index.scss'
 
 const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
 
 class PasteController extends Component {
   static propTpyes = {
-    type: PropTypes.any,        // 缁勪欢绫诲瀷
-    Tab: PropTypes.any,         // 鏍囩锛屾坊鍔犺彍鍗曠粍浠舵椂涓虹┖
     insert: PropTypes.func
   }
 
@@ -19,198 +19,96 @@
     visible: false
   }
 
-  handleMenuClick = () => {
-    this.setState({visible: true})
-  }
-
-  resetconfig = (item, Tab, isgroup) => {
-    item.uuid = Utils.getuuid()
-    item.floor = Tab ? (Tab.floor + 1) : 1
-
-    if (Tab && !isgroup) {
-      item.tabId = Tab.uuid
-      item.parentId = Tab.parentId
-    } else if (Tab) {
-      item.floor = Tab.floor || 1
-      item.parentId = Tab.parentId
-    }
-
-    if (item.dataName) {
-      item.dataName = Utils.getdataName()
-    }
-
+  resetconfig = (item, copyBtns, uuids = {}) => {
+    let appType = sessionStorage.getItem('appType')
+    
     if (item.type === 'tabs') {
+      uuids[item.uuid] = MenuUtils.getuuid()
+      item.uuid = uuids[item.uuid]
+      item.setting.name = item.setting.name + MenuUtils.getdataName().toUpperCase().substr(-4)
+      item.name = item.setting.name
+
       item.subtabs.forEach(tab => {
-        tab.uuid = Utils.getuuid()
+        uuids[tab.uuid] = MenuUtils.getuuid()
+        tab.uuid = uuids[tab.uuid]
         tab.parentId = item.uuid
 
-        if (item.floor >= 3) {
-          tab.components = tab.components.filter(cell => cell.type !== 'tabs')
+        if (appType !== 'mob') {
+          tab.components = tab.components.filter(cell => cell.type !== 'menubar')
         }
 
         tab.components = tab.components.map(cell => {
-          cell = this.resetconfig(cell, tab)
+          cell.tabId = tab.uuid
+          cell.parentId = tab.parentId
+
+          cell = this.resetconfig(cell, copyBtns, uuids)
           return cell
         })
       })
     } else if (item.type === 'group') {
-      item.components = item.components.forEach(cell => {
-        cell = this.resetconfig(cell, item, true)
+      uuids[item.uuid] = MenuUtils.getuuid()
+      item.uuid = uuids[item.uuid]
+      item.setting.name = item.setting.name + MenuUtils.getdataName().toUpperCase().substr(-4)
+      item.name = item.setting.name
+
+      item.components = item.components.map(cell => {
+        cell.tabId = item.tabId || ''
+        cell.parentId = item.parentId || ''
+
+        cell = MenuUtils.resetComponentConfig(cell, copyBtns, uuids)
         return cell
       })
-    } else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
-      item.subcards.forEach(card => {
-        card.uuid = Utils.getuuid()
-        if (card.elements) {
-          if (sessionStorage.getItem('editMenuType') === 'popview') {
-            card.elements = card.elements.filter(b => b.OpenType !== 'popview')
-          }
-          card.elements = card.elements.map(cell => {
-            cell.uuid = Utils.getuuid()
-            return cell
-          })
-        }
-        if (card.backElements) {
-          if (sessionStorage.getItem('editMenuType') === 'popview') {
-            card.elements = card.elements.filter(b => b.OpenType !== 'popview')
-          }
-          card.backElements = card.backElements.map(cell => {
-            cell.uuid = Utils.getuuid()
-            return cell
-          })
-        }
-      })
-    } else if (item.type === 'table' && item.subtype === 'normaltable' && item.cols) {
-      let loopCol = (col) => {
-        col.subcols = col.subcols.map(c => {
-          c.uuid = Utils.getuuid()
-
-          if (c.type === 'colspan' && c.subcols) {
-            c = loopCol(c)
-          } else if (c.type === 'custom' && c.elements) {
-            c.elements = c.elements.map(cell => {
-              cell.uuid = Utils.getuuid()
-              return cell
-            })
-          } else if (c.type === 'action' && c.elements) {
-            if (sessionStorage.getItem('editMenuType') === 'popview') {
-              c.elements = c.elements.filter(b => b.OpenType !== 'popview')
-            }
-            c.elements = c.elements.map(cell => {
-              cell.uuid = Utils.getuuid()
-              return cell
-            })
-          }
-          return c
-        })
-
-        return col
-      }
-
-      item.cols = item.cols.map(col => {
-        col.uuid = Utils.getuuid()
-
-        if (col.type === 'colspan' && col.subcols) {
-          col = loopCol(col)
-        } else if (col.type === 'custom' && col.elements) {
-          col.elements = col.elements.map(cell => {
-            cell.uuid = Utils.getuuid()
-            return cell
-          })
-        } else if (col.type === 'action' && col.elements) {
-          if (sessionStorage.getItem('editMenuType') === 'popview') {
-            col.elements = col.elements.filter(c => c.OpenType !== 'popview')
-          }
-          col.elements = col.elements.map(cell => {
-            cell.uuid = Utils.getuuid()
-            return cell
-          })
-        }
-        return col
-      })
-    }
-
-    if (item.btnlog) {
-      item.btnlog = []
-    }
-
-    if (item.action) {
-      if (sessionStorage.getItem('editMenuType') === 'popview') {
-        item.action = item.action.filter(c => c.OpenType !== 'popview')
-      }
-      item.action = item.action.map(cell => {
-        cell.uuid = Utils.getuuid()
-        return cell
-      })
-    }
-    if (item.search) {
-      item.search = item.search.map(cell => {
-        cell.uuid = Utils.getuuid()
-        return cell
-      })
-    }
-    if (item.columns) {
-      item.columns = item.columns.map(cell => {
-        cell.uuid = Utils.getuuid()
-        return cell
-      })
+    } else {
+      item = MenuUtils.resetComponentConfig(item, copyBtns, uuids)
     }
 
     return item
   }
 
   pasteSubmit = () => {
-    const { Tab } = this.props
-
-    let isgroup = Tab && Tab.type === 'group' ? true : false
+    let options = ['tabs', 'menubar', 'topbar', 'timeline', 'datacard', 'propcard', 'mainsearch', 'stepform', 'tabform', 'balcony', 'group', 'normaltable', 'tablecard', 'line', 'bar', 'pie', 'dashboard', 'scatter']
 
     this.pasteFormRef.handleConfirm().then(res => {
-      if (!isgroup && !['tabs', 'datacard', 'propcard', 'mainsearch', 'group', 'normaltable', 'tablecard', 'line', 'bar', 'pie'].includes(res.copyType)) {
+      if ((res.copyType === 'menubar' || res.copyType === 'topbar') && sessionStorage.getItem('appType') !== 'mob') {
         notification.warning({
           top: 92,
-          message: '閰嶇疆淇℃伅鏍煎紡閿欒锛�',
+          message: '褰撳墠绯荤粺涓嶆敮鎸佽彍鍗曠粍浠讹紒',
           duration: 5
         })
         return
-      } else if (isgroup && !['datacard', 'propcard', 'normaltable', 'tablecard', 'line', 'bar', 'pie'].includes(res.copyType)) {
+      } else if (!options.includes(res.copyType)) {
         notification.warning({
           top: 92,
           message: '閰嶇疆淇℃伅鏍煎紡閿欒锛�',
-          duration: 5
-        })
-        return
-      } else if (Tab && Tab.floor === 3 && res.type === 'tabs') {
-        notification.warning({
-          top: 92,
-          message: '鏍囩椤垫渶澶氫负涓夐噸缁撴瀯锛�',
           duration: 5
         })
         return
       }
 
-      res = this.resetconfig(res, Tab, isgroup)
+      let copyBtns = new Map()
+
+      res = this.resetconfig(res, copyBtns)
 
       delete res.copyType
+      
+      this.props.insert(res)
 
-      this.props.insert(res, Tab)
+      copyBtns = [...copyBtns.values()]
+
+      if (copyBtns.length > 0) {
+        MKEmitter.emit('copyButtons', copyBtns)
+      }
+
       this.setState({visible: false})
-
-      notification.success({
-        top: 92,
-        message: '绮樿创鎴愬姛锛�',
-        duration: 2
-      })
     })
   }
 
   render() {
-    const { type } = this.props
     const { visible } = this.state
 
     return (
-      <div style={{display: 'inline-block'}}>
-        {type !== 'menu' ? <Icon type="snippets" style={{color: 'purple'}} onClick={() => {this.setState({visible: true})}} /> : null}
-        {type === 'menu' ? <Button type="link" style={{padding: '5px'}} icon="snippets" onClick={() => {this.setState({visible: true})}}>绮樿创</Button> : null}
+      <div className="mk-view-paste" style={{display: 'inline-block'}}>
+        <Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={() => {this.setState({visible: true})}}><SnippetsOutlined />绮樿创</Button>
         <Modal
           title="绮樿创"
           visible={visible}

--
Gitblit v1.8.0