| | |
| | | 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' |
| | |
| | | node: null, |
| | | loading: false, |
| | | status: 0, |
| | | orgs: [] |
| | | flowname: '', |
| | | flowcode: '', |
| | | orgs: [], |
| | | empty: true |
| | | } |
| | | |
| | | selectNode = null |
| | |
| | | title: com.OrgName, |
| | | shortName: com.ShortName, |
| | | checkable: false, |
| | | disabled: true, |
| | | selectable: false, |
| | | children: [] |
| | | } |
| | | let _works = [] |
| | |
| | | key: dep.co_pro_code, |
| | | title: dep.co_pro_name, |
| | | checkable: false, |
| | | disabled: true, |
| | | selectable: false, |
| | | children: [] |
| | | } |
| | | |
| | |
| | | key: job.jobcode, |
| | | title: job.jobname, |
| | | checkable: false, |
| | | disabled: true, |
| | | selectable: false, |
| | | children: [] |
| | | } |
| | | |
| | |
| | | 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] |
| | | } |
| | |
| | | key: group.work_group, |
| | | title: group.work_group, |
| | | checkable: false, |
| | | disabled: true, |
| | | selectable: false, |
| | | children: [] |
| | | } |
| | | |
| | |
| | | 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] |
| | | } |
| | |
| | | const { BID } = this.state |
| | | |
| | | if (!BID) { |
| | | this.cells = [] |
| | | if (!is(fromJS(this.data), fromJS([]))) { |
| | | this.cells = [] |
| | | this.handleData() |
| | | } |
| | | this.setState({empty: true}) |
| | |
| | | |
| | | this.setState({ |
| | | status: item.status || 0, |
| | | loading: false |
| | | flowname: item.works_flow_name || '', |
| | | flowcode: item.works_flow_code || '', |
| | | loading: false, |
| | | empty: cells.length === 0 |
| | | }) |
| | | |
| | | if (result.message) { |
| | |
| | | }) |
| | | graph.on('edge:click', ({ edge }) => { |
| | | this.selectNode = edge |
| | | |
| | | |
| | | this.setState({node: edge.store.data}) |
| | | |
| | | graph.clearTransformWidgets() |
| | |
| | | |
| | | this.setState({node: null}) |
| | | }) |
| | | graph.on('edge:connected', ({ isNew, edge }) => { |
| | | if (!isNew) return |
| | | |
| | | let target = edge.getTargetCell() |
| | | let source = edge.getSourceCell() |
| | | |
| | | 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') |
| | | |
| | | if (target.prop('mknode') === 'end') { |
| | | 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}) |
| | | } |
| | | }) |
| | | |
| | | const r1 = graph.createNode({ |
| | | shape: 'mk-rect', |
| | | mknode: 'start', |
| | | mkdata: {status: 0, statusName: '开始'}, |
| | | mkdata: {status: 0, statusName: '未提交'}, |
| | | attrs: { |
| | | body: { |
| | | rx: 20, |
| | |
| | | const r8 = graph.createNode({ |
| | | shape: 'mk-rect', |
| | | mknode: 'end', |
| | | mkdata: {status: '', statusName: '结束'}, |
| | | mkdata: {status: 888, statusName: '已完成'}, |
| | | attrs: { |
| | | body: { |
| | | rx: 20, |
| | |
| | | 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 } = this.state |
| | | const { BID, plot, status, flowname, flowcode } = this.state |
| | | |
| | | if (!BID) { |
| | | Modal.error({ |
| | |
| | | let _status = status |
| | | |
| | | if (plot.subtype === 'xflow' && status === 10) { |
| | | let start_num = nodes.cells.filter(cell => cell.mknode === 'start').length |
| | | let end_num = nodes.cells.filter(cell => cell.mknode === 'end').length |
| | | let start_num = 0 |
| | | let end_num = 0 |
| | | let unvalid = false |
| | | let map = new Map() |
| | | let appMap = new Map() |
| | | |
| | | if (start_num !== 1 || end_num !== 1) { |
| | | nodes.cells.forEach(item => { |
| | | 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') { |
| | | 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 === 0 || unvalid) { |
| | | _status = 0 |
| | | } |
| | | } |
| | |
| | | ID: BID, |
| | | BID: '' |
| | | } |
| | | |
| | | let ssoParam = { |
| | | func: 's_works_flow_param_sso_upt_v6', |
| | | status: status, |
| | | ID: BID, |
| | | works_flow_code: flowcode, |
| | | works_flow_name: flowname, |
| | | long_param: window.btoa(window.encodeURIComponent(JSON.stringify(nodes))) |
| | | } |
| | | |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | notification.success({ |
| | | top: 92, |
| | | message: '保存成功!', |
| | | duration: 2 |
| | | }) |
| | | this.setState({ |
| | | loading: false, |
| | | status: _status |
| | | }) |
| | | if (plot.subtype === 'xflow') { |
| | | Api.getSystemConfig(ssoParam).then(result => { |
| | | if (result.status) { |
| | | notification.success({ |
| | | top: 92, |
| | | message: '保存成功!', |
| | | duration: 2 |
| | | }) |
| | | this.setState({ |
| | | loading: false, |
| | | status: _status |
| | | }) |
| | | this.cells = nodes.cells |
| | | } else { |
| | | notification.error({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 10 |
| | | }) |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | } |
| | | }) |
| | | } else { |
| | | notification.success({ |
| | | top: 92, |
| | | message: '保存成功!', |
| | | duration: 2 |
| | | }) |
| | | this.setState({ |
| | | loading: false, |
| | | status: _status |
| | | }) |
| | | this.cells = nodes.cells |
| | | } |
| | | } else { |
| | | notification.error({ |
| | | top: 92, |
| | |
| | | MKEmitter.emit('modifyTabs', newtab, true) |
| | | } else if (plot.click === 'menu') { |
| | | let menuId = plot.menu.slice(-1)[0] |
| | | let newtab = window.GLOB.mkThdMenus.filter(m => m.MenuID === menuId)[0] |
| | | let menu = null |
| | | |
| | | if (!newtab && plot.MenuID) { |
| | | newtab = { |
| | | if (window.GLOB.mkThdMenus.has(menuId)) { |
| | | menu = {...window.GLOB.mkThdMenus.get(menuId)} |
| | | } else if (plot.MenuID) { |
| | | menu = { |
| | | MenuID: plot.MenuID, |
| | | MenuName: plot.MenuName, |
| | | MenuNo: plot.MenuNo, |
| | | type: plot.tabType |
| | | } |
| | | } else if (!newtab) { |
| | | return |
| | | } |
| | | |
| | | MKEmitter.emit('modifyTabs', {...newtab, param: {$BID: sign}}, true) |
| | | if (!menu) return |
| | | |
| | | menu.param = {$BID: sign} |
| | | |
| | | MKEmitter.emit('modifyTabs', menu, true) |
| | | } else { |
| | | MKEmitter.emit('resetSelectLine', config.uuid, sign, {}) |
| | | } |
| | |
| | | |
| | | if (plot.subtype === 'xflow' && _status === 10) { |
| | | let nodes = this.mkGraph.toJSON() |
| | | let start_num = nodes.cells.filter(cell => cell.mknode === 'start').length |
| | | let end_num = nodes.cells.filter(cell => cell.mknode === 'end').length |
| | | |
| | | 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.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' && !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) |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | |
| | | if (start_num === 0) { |
| | | notification.warning({ |
| | |
| | | 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) { |
| | | let edge = this.mkGraph.getCellById(unvalidId) |
| | | |
| | | let node = edge.getTargetCell() |
| | | |
| | | 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 |
| | | } |
| | | |
| | | 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: '节点《' + s_label + '》与《' + title + '》间连线未设置审批人!', |
| | | duration: 2 |
| | | }) |
| | | } else { |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { loading, config, node, orgs, status } = 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 |
| | |
| | | <QuestionCircleOutlined /> |
| | | </Tooltip> |
| | | </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'}> |