king
2023-08-04 465be8b618c1fb139d56ed779ff6f4dbc8d89b89
src/menu/tablenodes/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal, Button, notification, Spin, Input } from 'antd'
import { Modal, Button, notification, Spin, Input, message } from 'antd'
import { ForkOutlined } from '@ant-design/icons'
import Api from '@/api'
@@ -122,7 +122,7 @@
        MenuID: config.uuid
      }
      Api.getSystemConfig(param).then(result => {
      Api.getCloudConfig(param).then(result => {
        if (!result.status) {
          notification.warning({
            top: 92,
@@ -158,6 +158,7 @@
              id: 'par' + i,
              direction: 'left',
              color: '#5AD8A6',
              node: 'table',
              children: []
            }
@@ -173,6 +174,7 @@
        if (result.tb_list) {
          result.tb_list.sort((a, b) => a.tbname > b.tbname ? 1 : -1)
          let length = result.tb_list.length
          result.tb_list.forEach((item, i) => {
            let cell = {
              label: item.tbname,
@@ -180,6 +182,8 @@
              id: 'table' + i,
              direction: 'right',
              color: '#1890ff',
              collapsed: false,
              collable: true,
              children: []
            }
@@ -198,10 +202,17 @@
                    id: item.tbname + 'menu' + i,
                    direction: 'right',
                    color: '#1890ff',
                    type: 'dice-mind-map-leaf',
                    param: _param
                  })
                }
              })
            }
            if (cell.children.length > 5 && length > 1) {
              cell.collapsed = true
            } else if (cell.children.length === 0) {
              cell.collable = false
            }
            data.children.push(cell)
@@ -222,7 +233,12 @@
    if (menu.direction !== 'right') return
    if (menu.depth === 1) {
      sessionStorage.setItem('mk-table-node', menu.label)
      window.open('#/hs')
      setTimeout(() => {
        sessionStorage.removeItem('mk-table-node')
      }, 50)
    } else if (menu.param) {
      if (menu.param.type === 'admin') {
        if (menu.param.MenuType === 'custom') {
@@ -284,12 +300,12 @@
          const stroke = cfg.style.stroke || '#096dd9';
    
          return `
          <group>
            <rect draggable="true" style={{width: ${width}, height: 30, stroke: ${stroke}, radius: 4}} keyshape>
              <text style={{ fontSize: 14, marginLeft: 6, marginTop: 6 }}>${cfg.label}</text>
            </rect>
          </group>
        `;
            <group>
              <rect draggable="true" style={{width: ${width}, height: 30, stroke: ${stroke}, radius: 4}} keyshape>
                <text style={{ fontSize: 14, marginLeft: 6, marginTop: 6 }}>${cfg.label}</text>
              </rect>
            </group>
          `;
        },
        getAnchorPoints() {
          return [
@@ -308,13 +324,13 @@
          const color = cfg.color;
    
          return `
          <group>
            <rect draggable="true" style={{width: ${width}, height: 26, cursor: ${cfg.direction !== 'left' ? 'pointer' : 'default'}, fill: 'transparent' }}>
              <text style={{ fontSize: 12, fill: ${cfg.fontcolor ? cfg.fontcolor : 'black'}, cursor: ${cfg.direction !== 'left' ? 'pointer' : 'default'}, marginLeft: 12, marginTop: 6 }}>${cfg.label}</text>
            </rect>
            <rect style={{ fill: ${color}, width: ${width}, cursor: ${cfg.direction !== 'left' ? 'pointer' : 'default'}, height: 2, x: 0, y: 32 }} />
          </group>
        `;
            <group>
              <rect draggable="true" style={{width: ${width}, height: 26, cursor: ${cfg.direction !== 'left' ? 'pointer' : 'default'}, fill: 'transparent' }}>
                <text style={{ fontSize: 12, fill: ${cfg.fontcolor ? cfg.fontcolor : 'black'}, cursor: ${cfg.direction !== 'left' ? 'pointer' : 'default'}, marginLeft: 12, marginTop: 6 }}>${cfg.label} ${cfg.collable ? '+' : ''}</text>
              </rect>
              <rect style={{ fill: ${color}, width: ${width}, cursor: ${cfg.direction !== 'left' ? 'pointer' : 'default'}, height: 2, x: 0, y: 32 }} />
            </group>
          `;
        },
        getAnchorPoints() {
          return [
@@ -334,6 +350,35 @@
      editNode(evt) {
        const item = evt.item;
        const model = item.get('model');
        // 选中节点
        this.graph.getNodes().forEach(node => {
          let _model = node.get('model')
          if (_model.fontcolor === '#1890ff') {
            _model.fontcolor = ''
            this.graph.updateItem(node, _model, false)
          }
        })
        if (model.direction === 'left') {
          if (model.node === 'table') {
            model.fontcolor = '#1890ff'
            this.graph.updateItem(item, model, false)
            let oInput = document.createElement('input')
            oInput.value = model.label
            document.body.appendChild(oInput)
            oInput.select()
            document.execCommand('Copy')
            document.body.removeChild(oInput)
            message.success('表名复制成功。')
          }
          return
        }
        model.fontcolor = '#1890ff'
        this.graph.updateItem(item, model, false)
        
        that.changeMenu(model)
      }
@@ -394,7 +439,7 @@
          data.color = color;
        }
    
        if (d.children) {
        if (d.children && !d.collapsed) {
          data.children = d.children.map((child) => changeData(child, level + 1, data.color));
        }
        return data;
@@ -435,9 +480,21 @@
          lineWidth: 2,
        },
      },
      minZoom: 0.5,
      minZoom: 0.3,
      modes: {
        default: ['drag-canvas', 'zoom-canvas', 'dice-mindmap'],
        default: [
          {
            type: 'collapse-expand',
            trigger: 'click',
            shouldBegin: (e, self) => {
              if (e.item && e.item.getModel().collable) return true;
              return false;
            },
          },
          'drag-canvas',
          'zoom-canvas',
          'dice-mindmap'
        ],
      },
    });
    
@@ -471,6 +528,7 @@
          </div>
          <div className="footer">
            <Button key="cancel" onClick={() => { this.setState({ visible: false })}}>关闭</Button>
            <span className="tip">注:点击表名可展开/收起菜单</span>
          </div>
        </Modal>
      </div>