From fc8c8d714687a22f711d642d192bd4149f3b7e88 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 22 四月 2024 11:15:14 +0800
Subject: [PATCH] 2024-04-22

---
 src/tabviews/custom/components/chart/antv-X6/index.jsx |  226 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 197 insertions(+), 29 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-X6/index.jsx b/src/tabviews/custom/components/chart/antv-X6/index.jsx
index 97525bc..03c7b22 100644
--- a/src/tabviews/custom/components/chart/antv-X6/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-X6/index.jsx
@@ -1,8 +1,8 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Spin, Tooltip, message, Modal, notification, Switch } from 'antd'
-import { UndoOutlined, RedoOutlined, VerticalAlignTopOutlined, VerticalAlignBottomOutlined, SaveOutlined, ZoomInOutlined, ZoomOutOutlined, OneToOneOutlined, QuestionCircleOutlined, ClearOutlined } from '@ant-design/icons'
+import { Spin, Tooltip, message, Modal, notification, Switch, Button } from 'antd'
+import { UndoOutlined, RedoOutlined, VerticalAlignTopOutlined, VerticalAlignBottomOutlined, ZoomInOutlined, ZoomOutOutlined, OneToOneOutlined, QuestionCircleOutlined, ClearOutlined } from '@ant-design/icons'
 import { Graph, Shape } from '@antv/x6'
 import { Stencil } from '@antv/x6-plugin-stencil'
 import { Transform } from '@antv/x6-plugin-transform'
@@ -388,7 +388,8 @@
     status: 0,
     flowname: '',
     flowcode: '',
-    orgs: []
+    orgs: [],
+    empty: true
   }
 
   selectNode = null
@@ -526,6 +527,7 @@
                     worker_id: work.worker_id || '',
                     workercode: work.workercode || '',
                     workername: work.workername || '',
+                    job_type: job.job_type || '',
                     parentIds: [com.OrgCode, dep.co_pro_code, job.jobcode],
                     parentNames: [com.OrgName, dep.co_pro_name, job.jobname]
                   }
@@ -553,6 +555,7 @@
                     worker_id: work.worker_id || '',
                     workercode: work.workercode || '',
                     workername: work.workername || '',
+                    job_type: job.job_type || '',
                     parentIds: [com.OrgCode, dep.co_pro_code, job.jobcode, group.work_group],
                     parentNames: [com.OrgName, dep.co_pro_name, job.jobname, group.work_group]
                   }
@@ -590,8 +593,8 @@
     const { BID } = this.state
 
     if (!BID) {
+      this.cells = []
       if (!is(fromJS(this.data), fromJS([]))) {
-        this.cells = []
         this.handleData()
       }
       this.setState({empty: true})
@@ -624,7 +627,8 @@
         status: item.status || 0,
         flowname: item.works_flow_name || '',
         flowcode: item.works_flow_code || '',
-        loading: false
+        loading: false,
+        empty: cells.length === 0
       })
 
       if (result.message) {
@@ -989,7 +993,7 @@
     })
     graph.on('edge:click', ({ edge }) => {
       this.selectNode = edge
-      
+
       this.setState({node: edge.store.data})
 
       graph.clearTransformWidgets()
@@ -1003,8 +1007,19 @@
       if (!isNew) return
 
       let target = edge.getTargetCell()
+      let source = edge.getSourceCell()
 
-      if (!target) return
+      if (!target || !source) return
+
+      if (source.prop('mknode') === 'end') {
+        notification.warning({
+          top: 92,
+          message: '缁撴潫鑺傜偣涓嶅彲娣诲姞鍒嗘敮锛�',
+          duration: 2
+        })
+        graph.removeCells([edge])
+        return
+      }
 
       let mkdata = target.prop('mkdata')
 
@@ -1012,6 +1027,8 @@
         edge.prop('mknode', 'endEdge')
       } else if (target.prop('mknode') === 'start') {
         edge.prop('mknode', 'startEdge')
+      } else if (source.prop('mknode') === 'start') {
+        edge.prop('mknode', 'firstEdge')
       }
       if (mkdata) {
         edge.prop('mkdata', {status: mkdata.status, statusName: mkdata.statusName})
@@ -1544,6 +1561,26 @@
     this.mkGraph.zoomTo(1)
   }
 
+  close = () => {
+    const { config } = this.state
+
+    let nodes = this.mkGraph.toJSON()
+
+    if (!is(fromJS(nodes.cells), fromJS(this.cells))) {
+      confirm({
+        title: '娴佺▼鍥惧凡淇敼锛岀‘瀹氬叧闂悧?',
+        okText: '纭畾',
+        cancelText: '鍙栨秷',
+        onOk() {
+          MKEmitter.emit('closeTabView', config.$pageId)
+        },
+        onCancel() {}
+      })
+    } else {
+      MKEmitter.emit('closeTabView', config.$pageId)
+    }
+  }
+
   save = () => {
     const { BID, plot, status, flowname, flowcode } = this.state
 
@@ -1561,20 +1598,42 @@
       let start_num = 0
       let end_num = 0
       let unvalid = false
+      let map = new Map()
+      let appMap = new Map()
       
       nodes.cells.forEach(item => {
-        if (item.mknode === 'start') {
+        if (item.shape === 'mk-text' || item.shape === 'lane') return
+
+        if (!item.mkdata) {
+          unvalid = true
+        } else if (item.mknode === 'start') {
           start_num++
         } else if (item.mknode === 'end') {
           end_num++
-        } else if (item.shape === 'edge' && item.mknode !== 'endEdge' && item.mknode !== 'startEdge') {
-          if (!item.mkdata.members || item.mkdata.members.length === 0) {
+        } else if (item.shape === 'edge') {
+          if (item.mknode !== 'endEdge' && item.mknode !== 'startEdge' && (!item.mkdata.members || item.mkdata.members.length === 0)) {
             unvalid = true
+          } else if (item.mknode === 'startEdge' || item.mkdata.flowType === 'reject') {
+            if (map.has(item.source.cell)) {
+              unvalid = true
+            } else {
+              map.set(item.source.cell, true)
+            }
+          } else if (item.mkdata.flowType === 'approval' || item.mknode === 'endEdge') {
+            let val = ''
+            if (item.mkdata.execCondition === 'open') {
+              val = item.mkdata.match + item.mkdata.matchVal
+            }
+            if (appMap.has(item.source.cell + val)) {
+              unvalid = true
+            } else {
+              appMap.set(item.source.cell + val, true)
+            }
           }
         }
-
       })
-      if (start_num !== 1 || end_num !== 1 || unvalid) {
+
+      if (start_num !== 1 || end_num === 0 || unvalid) {
         _status = 0
       }
     }
@@ -1616,6 +1675,7 @@
                   loading: false,
                   status: _status
                 })
+                this.cells = nodes.cells
               } else {
                 notification.error({
                   top: 92,
@@ -1637,6 +1697,7 @@
               loading: false,
               status: _status
             })
+            this.cells = nodes.cells
           }
         } else {
           notification.error({
@@ -1993,15 +2054,49 @@
       let start_num = 0
       let end_num = 0
       let unvalidId = ''
-      
+      let emptyNode = null
+      let emptyEdge = null
+      let map = new Map()
+      let appMap = new Map()
+      let rejectId = ''
+      let approvalId = ''
+
       nodes.cells.forEach(item => {
-        if (item.mknode === 'start') {
+        if (item.shape === 'mk-text' || item.shape === 'lane') return
+
+        if (!item.mkdata) {
+          if (item.shape !== 'edge') {
+            if (!emptyNode) {
+              emptyNode = item
+            }
+          } else {
+            if (!emptyEdge) {
+              emptyEdge = item
+            }
+          }
+        } else if (item.mknode === 'start') {
           start_num++
         } else if (item.mknode === 'end') {
           end_num++
-        } else if (item.shape === 'edge' && item.mknode !== 'endEdge' && item.mknode !== 'startEdge') {
-          if (!item.mkdata.members || item.mkdata.members.length === 0) {
+        } else if (item.shape === 'edge' && !unvalidId && !rejectId && !approvalId) {
+          if (item.mknode !== 'endEdge' && item.mknode !== 'startEdge' && (!item.mkdata.members || item.mkdata.members.length === 0)) {
             unvalidId = item.id
+          } else if (item.mknode === 'startEdge' || item.mkdata.flowType === 'reject') {
+            if (map.has(item.source.cell)) {
+              rejectId = item.source.cell
+            } else {
+              map.set(item.source.cell, true)
+            }
+          } else if (item.mkdata.flowType === 'approval' || item.mknode === 'endEdge') {
+            let val = ''
+            if (item.mkdata.execCondition === 'open') {
+              val = item.mkdata.match + item.mkdata.matchVal
+            }
+            if (appMap.has(item.source.cell + val)) {
+              approvalId = item.source.cell
+            } else {
+              appMap.set(item.source.cell + val, item)
+            }
           }
         }
       })
@@ -2024,10 +2119,77 @@
           message: '璇锋坊鍔犵粨鏉熻妭鐐癸紒',
           duration: 2
         })
-      } else if (end_num > 1) {
+      // } else if (end_num > 1) {
+      //   notification.warning({
+      //     top: 92,
+      //     message: '缁撴潫鑺傜偣涓嶅彲娣诲姞澶氫釜锛�',
+      //     duration: 2
+      //   })
+      } else if (emptyNode) {
+        let errmsg = '閮ㄥ垎鑺傜偣鏈缃熀鏈俊鎭��'
+        if (emptyNode.attrs && emptyNode.attrs.text && emptyNode.attrs.text.text) {
+          errmsg = '鑺傜偣銆�' + emptyNode.attrs.text.text + '銆嬫湭璁剧疆鍩烘湰淇℃伅銆�'
+        }
         notification.warning({
           top: 92,
-          message: '缁撴潫鑺傜偣涓嶅彲娣诲姞澶氫釜锛�',
+          message: errmsg,
+          duration: 2
+        })
+      } else if (emptyEdge) {
+        let errmsg = '閮ㄥ垎杩炵嚎鏈缃熀鏈俊鎭��'
+
+        let edge = this.mkGraph.getCellById(emptyEdge.id)
+        let target = edge.getTargetCell()
+
+        let t_label = ''
+        if (target.attrs && target.attrs.text && target.attrs.text.text) {
+          t_label = target.attrs.text.text
+        }
+
+        let source = edge.getSourceCell()
+
+        let s_label = ''
+        if (source.attrs && source.attrs.text && source.attrs.text.text) {
+          s_label = source.attrs.text.text
+        }
+
+        if (t_label && s_label) {
+          errmsg = '鑺傜偣銆�' + s_label + '銆嬩笌鑺傜偣銆�' + t_label + '銆嬮棿杩炵嚎鏈缃熀鏈俊鎭��'
+        }
+
+        notification.warning({
+          top: 92,
+          message: errmsg,
+          duration: 2
+        })
+      } else if (rejectId) {
+        let node = this.mkGraph.getCellById(rejectId)
+
+        let title = ''
+        if (node.attrs && node.attrs.text && node.attrs.text.text) {
+          title = '鑺傜偣銆�' + node.attrs.text.text + '銆�'
+        } else if (node.mkdata) {
+          title = '鐘舵�侊細' + node.mkdata.status + ' - ' + node.mkdata.statusName
+        }
+
+        notification.warning({
+          top: 92,
+          message: title + ' 涓嶅彲璁剧疆涓ゆ潯椹冲洖杩炵嚎锛�',
+          duration: 2
+        })
+      } else if (approvalId) {
+        let node = this.mkGraph.getCellById(approvalId)
+
+        let title = ''
+        if (node.attrs && node.attrs.text && node.attrs.text.text) {
+          title = '鑺傜偣銆�' + node.attrs.text.text + '銆�'
+        } else if (node.mkdata) {
+          title = '鐘舵�侊細' + node.mkdata.status + ' - ' + node.mkdata.statusName
+        }
+
+        notification.warning({
+          top: 92,
+          message: title + ' 鍚庣殑瀹℃壒鍒嗘敮鎵ц鏉′欢閲嶅锛�',
           duration: 2
         })
       } else if (unvalidId) {
@@ -2036,15 +2198,24 @@
         let node = edge.getTargetCell()
 
         let title = ''
-        if (node.attrs && node.attrs.text) {
-          title = node.attrs.text.text + ''
+        if (node.attrs && node.attrs.text && node.attrs.text.text) {
+          title = node.attrs.text.text
         } else if (node.mkdata) {
           title = '鐘舵�侊細' + node.mkdata.status + ' - ' + node.mkdata.statusName
         }
 
+        let source = edge.getSourceCell()
+
+        let s_label = ''
+        if (source.attrs && source.attrs.text && source.attrs.text.text) {
+          s_label = source.attrs.text.text
+        } else if (source.mkdata) {
+          s_label = '鐘舵�侊細' + source.mkdata.status + ' - ' + source.mkdata.statusName
+        }
+
         notification.warning({
           top: 92,
-          message: '杩炴帴锛�' + title + '锛夌殑绾挎湭璁剧疆瀹℃壒浜猴紒',
+          message: '鑺傜偣銆�' + s_label + '銆嬩笌銆�' + title + '銆嬮棿杩炵嚎鏈缃鎵逛汉锛�',
           duration: 2
         })
       } else {
@@ -2070,12 +2241,12 @@
   }
 
   render() {
-    const { loading, config, node, orgs, status, flowname } = this.state
+    const { loading, config, node, orgs, status, flowname, empty } = this.state
 
     let style = {...config.style}
 
     if (config.plot.function === 'show') {
-      if (config.plot.empty === 'hidden' && this.cells.length === 0) {
+      if (config.plot.empty === 'hidden' && empty) {
         style.position = 'absolute'
         style.width = '100%'
         style.zIndex = -1
@@ -2138,12 +2309,9 @@
           </div>
           <div className="flow-name">{flowname}</div>
           <div className="right-tool">
-            <Tooltip title="鍚敤/鍋滅敤">
-              <Switch size="small" style={{marginRight: '10px'}} checked={status === 10} onChange={this.changeStatus} />
-            </Tooltip>
-            <Tooltip title="淇濆瓨">
-              <SaveOutlined style={{marginRight: '10px'}} onClick={this.save}/>
-            </Tooltip>
+            <Switch size="large" checked={status === 10} checkedChildren="鍚�" unCheckedChildren="鍋�" onChange={this.changeStatus} />
+            <Button className="save" onClick={this.save}>淇濆瓨</Button>
+            <Button className="close" onClick={this.close}>鍏抽棴</Button>
           </div>
         </div>
         <div className="canvas" style={{width: '100%', minHeight: config.plot.height, height: config.plot.height}} id={config.uuid + 'canvas'}>

--
Gitblit v1.8.0