index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <div class="FlowChartComponent">
  3. <!-- <Alert show-icon closable v-if="currentSteps === 1">双击空白区域即可直接新增一个中间节点,双击节点可编辑</Alert> -->
  4. <div class="chartContent">
  5. <div id="paletteDiv"></div>
  6. <div id="goChart" v-show="currentSteps === 1">
  7. </div>
  8. <div id="showChart" v-show="currentSteps === 2">
  9. </div>
  10. </div>
  11. <!-- 全局侧滑模块 -->
  12. <Drawer
  13. v-model="drawerObject.show"
  14. transfer
  15. :title="drawerObject.title"
  16. :width="472"
  17. :mask-closable="false"
  18. :closable="false"
  19. scrollable
  20. >
  21. <components
  22. v-if="drawerObject.show"
  23. :configData="drawerObject.configData"
  24. :data="drawerObject.configData"
  25. :is="drawerObject.component"
  26. :TABLE_ID="drawerObject.TABLE_ID"
  27. :node="drawerObject.node"
  28. :status="drawerObject.status"
  29. :rejectedNodes="rejectedNodes"
  30. :assignedNodes="assignedNodes"
  31. :readOnly="readOnly"
  32. :moduleType="data.moduleType"
  33. @closeDrawer="closeDrawer"
  34. >
  35. </components>
  36. </Drawer>
  37. </div>
  38. </template>
  39. <script>
  40. import '@/utils/go'
  41. import FlowDesinger from '@/utils/flow-desinger';
  42. import startNodeInfo from '@/components/startNodeInfo'
  43. import endNodeInfo from '@/components/endNodeInfo'
  44. import linkInfo from '@/components/linkInfo'
  45. import ProcessNodeConfig from '@/components/ProcessNodeConfig'
  46. import DynamicProcessNodeConfig from '@/components/DynamicProcessNodeConfig'
  47. import ServiceNodeConfig from '@/components/ServiceNodeConfig'
  48. import FlowDisplay from '@/utils/flow-display';
  49. export default {
  50. components:{
  51. startNodeInfo, endNodeInfo, linkInfo, ProcessNodeConfig, DynamicProcessNodeConfig, ServiceNodeConfig
  52. },
  53. props:{
  54. editable:{ //是否可编辑
  55. type:Boolean,
  56. default:true
  57. },
  58. fresh:{
  59. type:Boolean,
  60. default:false
  61. },
  62. currentSteps:{
  63. type:Number,
  64. default:null
  65. },
  66. noFreshFlag:{
  67. type:Boolean,
  68. default:false
  69. },
  70. readOnly:{
  71. type:Boolean,
  72. default:false
  73. },
  74. data:{
  75. type:Object,
  76. default () {
  77. return {
  78. }
  79. }
  80. }
  81. },
  82. data () {
  83. return {
  84. myDesigner:null, //画布实例
  85. drawerObject:{
  86. show:false
  87. },
  88. nodeMsg:{}, //存放节点数据
  89. pathMsg:{}, //存放路径数据
  90. rejectedNodes:[], //驳回节点
  91. assignedNodes: [], //指派节点
  92. }
  93. },
  94. activated () {
  95. if(!this.noFreshFlag){
  96. this.init()
  97. }
  98. },
  99. deactivated () { //keep-alive 组件停用时调用
  100. if(this.currentSteps === 1 && this.myDesigner){
  101. this.data.guiStyle = JSON.parse(this.myDesigner.getFlowData())
  102. }
  103. },
  104. methods:{
  105. init () {
  106. if(!Array.isArray(this.data.nodeMsg)){
  107. let nodeMsg = []
  108. Object.keys(this.data.nodeMsg).map(item => {
  109. nodeMsg.push(this.data.nodeMsg[item])
  110. return item
  111. })
  112. this.data.nodeMsg = nodeMsg
  113. let pathMsg = []
  114. Object.keys(this.data.pathMsg).map(item => {
  115. pathMsg.push(this.data.pathMsg[item])
  116. return item
  117. })
  118. this.data.pathMsg = pathMsg
  119. }
  120. this.dataProcessing()
  121. if(this.currentSteps === 1){
  122. // 流程图设计器
  123. if(!this.myDesigner){
  124. this.myDesigner= new FlowDesinger('goChart',{
  125. showEditNode:this.showEditNode, //节点双击编辑
  126. SelectionDeleted:this.SelectionDeleted, //删除事件
  127. LinkDrawn:this.LinkDrawn, //线的生成
  128. externalobjectsdropped:this.externalobjectsdropped, //节点生成
  129. LinkRelinked: this.LinkRelinked //连线修改
  130. });
  131. }
  132. this.initToolbar = this.myDesigner.initToolbar('paletteDiv',this.data.moduleType)
  133. this.myDesigner.displayFlow(JSON.parse(JSON.stringify(this.data.guiStyle)));// 在设计面板中显示流程图
  134. this.data.myDisplay = this.myDesigner.diagram
  135. }else{
  136. if(this.myDisplay){
  137. this.myDisplay.loadFlow(JSON.parse(JSON.stringify(this.data.guiStyle)))
  138. }else{
  139. this.myDisplay = new FlowDisplay('showChart',{
  140. showEditNode:this.showEditNode, //节点双击编辑
  141. });
  142. this.myDisplay.loadFlow(JSON.parse(JSON.stringify(this.data.guiStyle)))
  143. }
  144. // this.data.myDisplay = this.myDisplay.diagram
  145. }
  146. },
  147. compare (property) {
  148. return function(a,b) {
  149. var value1 = a[property];
  150. var value2 = b[property];
  151. return value1 - value2
  152. }
  153. },
  154. dataProcessing () { //处理后端返回节点数据和路径数据
  155. if(this.data.nodeMsg){
  156. this.data.nodeMsg.forEach(item => {
  157. this.nodeMsg[item.key] = item
  158. if(item.type === 2){ //结束节点对数据排序,区分执行程序还是抄送人
  159. this.nodeMsg[item.key].actionConfig.sort(this.compare('handleType'))
  160. }
  161. })
  162. this.data.nodeMsg = this.nodeMsg
  163. }
  164. if(this.data.pathMsg){
  165. this.data.pathMsg.forEach(item => {
  166. this.pathMsg[item.key] = item
  167. })
  168. this.data.pathMsg = this.pathMsg
  169. }
  170. this.data.removePath = []
  171. this.data.removeNode = []
  172. },
  173. showEditNode (node) { //双击编辑
  174. // node.findNodesOutOf()
  175. if(node.data.type === 1){
  176. let defaultObj = {
  177. conditionType: 0,
  178. ruleList: [],
  179. priority: null,
  180. defaultPriority: null,
  181. modifyId: null,
  182. id:null,
  183. triggerBt:[],
  184. visibleBt:[]
  185. }
  186. if(!node.data.id){
  187. this.nodeMsg[node.data.key] = Object.assign(defaultObj,this.nodeMsg[node.data.key])
  188. }
  189. this.drawerObject = {
  190. show: true,
  191. component: 'startNodeInfo',
  192. configData: this.nodeMsg[node.data.key],
  193. title:'开始节点配置'
  194. }
  195. }
  196. if(node.data.type === 2){
  197. let defaultObj = {
  198. id:null,
  199. manualConfig:null,
  200. actionConfig:[]
  201. }
  202. if(!node.data.id){
  203. this.nodeMsg[node.data.key] = Object.assign(defaultObj,this.nodeMsg[node.data.key])
  204. }
  205. this.drawerObject = {
  206. show: true,
  207. component: 'endNodeInfo',
  208. configData: this.nodeMsg[node.data.key],
  209. title:'结束节点配置'
  210. }
  211. }
  212. // 审批节点和操作节点用同一个配置界面,根据参数控制展示项
  213. if(node.data.category === "Approval" || node.data.category === "Operation"){
  214. this.rejectedNodes = []
  215. this.assignedNodes = []
  216. this.findNodesInto(node)
  217. this.findNodesOutOf(node)
  218. // 默认节点配置
  219. let defaultObj = {
  220. actServiceS:[],
  221. actionConfig:[],
  222. approvelList:[],
  223. backId:null,
  224. id:null,
  225. manualConfig:0,
  226. modifiableField:[],
  227. moduleId:null,
  228. name:'中间节点',
  229. nodeType:0,
  230. ruleList:[],
  231. inevitable: 1, //节点必经
  232. approveCondition: 0, //审批条件
  233. assignBack: 0, //驳回操作
  234. whetherBack: 0, //可为驳回节点
  235. nodeCancle: 0, //作废操作
  236. assignNext: 1, //指派流转节点
  237. assignNode: 1, //节点是否是必需指派
  238. assignApprover: 1, //是否动态指派操作人
  239. visibleBt:[], //可见按钮
  240. nodeBack: 0, //驳回按钮开关
  241. nodeAgree: 0, //同意按钮
  242. }
  243. if(this.data.moduleType === 0){
  244. defaultObj = {
  245. actServiceS:[],
  246. actionConfig:[],
  247. approvelList:[],
  248. backId:null,
  249. id:null,
  250. manualConfig:0,
  251. modifiableField:'',
  252. modifiableFieldName:'',
  253. moduleId:null,
  254. name:'审批节点',
  255. nodeType:0,
  256. ruleList:[]
  257. }
  258. }
  259. if(!node.data.id){
  260. this.nodeMsg[node.data.key] = Object.assign(defaultObj,this.nodeMsg[node.data.key])
  261. }
  262. this.drawerObject = {
  263. show: true,
  264. component: this.data.moduleType === 0?'ProcessNodeConfig':'DynamicProcessNodeConfig',
  265. configData: this.nodeMsg[node.data.key],
  266. node: node,
  267. title:node.data.category === "Approval"?'审批节点配置':'操作节点'
  268. }
  269. }
  270. // 服务节点
  271. if(node.data.category === 'Service'){
  272. let defaultObj = {
  273. id:null,
  274. actionConfig:[{
  275. "id":null, //新增不传,修改传
  276. "handleValue":null, //具体的关于请求状态,url之类的json
  277. "handleType":null, //51:rest服务实现,52:消息系统
  278. "extraMsg":null //相关参数
  279. }]
  280. }
  281. if(!node.data.id){
  282. this.nodeMsg[node.data.key] = Object.assign(defaultObj,this.nodeMsg[node.data.key])
  283. }
  284. this.drawerObject = {
  285. show: true,
  286. component: 'ServiceNodeConfig',
  287. configData: this.nodeMsg[node.data.key],
  288. title:'服务节点配置'
  289. }
  290. }
  291. if(node.data.from !== undefined){
  292. if(this.nodeMsg[node.data.from].category === 'Service' && this.data.moduleType === 1){
  293. return
  294. }
  295. // 默认连线配置
  296. let defaultObj = {
  297. endNode:null,
  298. moduleId:null,
  299. name:null,
  300. ruleList:[],
  301. sources:null,
  302. startNode:null,
  303. status:null
  304. }
  305. if(!node.data.moduleId){
  306. this.pathMsg[node.data.key] = Object.assign(defaultObj,this.pathMsg[node.data.key])
  307. }
  308. let tableConfig = [{
  309. ID: this.nodeMsg[node.data.from].nodeFormId,
  310. value: this.nodeMsg[node.data.from].nodeForm
  311. }]
  312. if(this.nodeMsg[node.data.from].category === 'Start'){
  313. tableConfig = [{
  314. ID: this.nodeMsg[node.data.from].businessType,
  315. value: this.nodeMsg[node.data.from].businessTypeName
  316. }]
  317. }
  318. this.drawerObject = {
  319. show: true,
  320. component: 'linkInfo',
  321. configData: this.pathMsg[node.data.key],
  322. TABLE_ID: this.data.moduleType === 1?tableConfig:this.data.businessType,
  323. title:'连接线配置'
  324. }
  325. }
  326. },
  327. findNodesInto (node) { //查找父节点
  328. let parents = node.findNodesInto()
  329. if(parents.count > 0){
  330. node.findNodesInto().map(item => {
  331. this.rejectedNodes.push({
  332. value:item.data.key,
  333. label:item.data.text
  334. })
  335. this.findNodesInto(item)
  336. })
  337. }else{
  338. return
  339. }
  340. },
  341. findNodesOutOf (node) { //查找子节点
  342. let childrens = node.findNodesOutOf()
  343. if(childrens.count > 0){
  344. node.findNodesOutOf().map(item => {
  345. if(item.data.key != -2){
  346. this.assignedNodes.push({
  347. value:item.data.key,
  348. label:item.data.text
  349. })
  350. this.findNodesOutOf(item)
  351. }
  352. })
  353. }else{
  354. return
  355. }
  356. },
  357. SelectionDeleted (node) { //删除节点或者线
  358. if(node.fromPort !== undefined){ //线的删除
  359. delete this.pathMsg[node.key]
  360. if(node.id){ //已保存的线
  361. this.data.removePath.push(node.id)
  362. }
  363. }else{ //节点删除
  364. delete this.nodeMsg[node.key]
  365. if(node.id){
  366. this.data.removeNode.push({
  367. id:node.id,
  368. type:node.type
  369. })
  370. }
  371. }
  372. },
  373. LinkDrawn (node) { //连线生成
  374. if(!this.judgeLoop()){
  375. this.$Modal.fcWarning({
  376. title:'警告',
  377. content:'流程图中存在回路,请重新设置!!',
  378. mask:true
  379. })
  380. this.data.guiStyle = JSON.parse(this.myDesigner.getFlowData())
  381. let linkDataArray = this.data.guiStyle.linkDataArray
  382. linkDataArray = linkDataArray.filter(item => {
  383. return item.key !== node.key
  384. })
  385. this.data.guiStyle.linkDataArray = linkDataArray
  386. this.init()
  387. // reject()
  388. return
  389. }else{
  390. this.pathMsg[node.key] = node
  391. this.pathMsg[node.key].ruleList = []
  392. }
  393. },
  394. LinkRelinked (node) { //连线修改
  395. this.pathMsg[node.key].from = node.from
  396. this.pathMsg[node.key].to = node.to
  397. this.pathMsg[node.key].fromPort = node.fromPort
  398. this.pathMsg[node.key].toPort = node.toPort
  399. },
  400. judgeLoop () { //判断是否存在闭环 true为没有闭环 false有闭环
  401. // 获取所有的节点
  402. let data = JSON.parse(this.myDesigner.getFlowData())
  403. const edges = data.linkDataArray?data.linkDataArray:JSON.parse(data).linkDataArray;
  404. const nodes = [];
  405. const list = {}; // 邻接表
  406. const queue = []; // 入度为0的节点集合
  407. const indegree = {};
  408. edges.forEach(e => {
  409. const { from, to } = e;
  410. if (!nodes.includes(from)) {
  411. nodes.push(from);
  412. }
  413. if (!nodes.includes(to)) {
  414. nodes.push(to);
  415. }
  416. addEdge(from, to);
  417. });
  418. const V = nodes.length;
  419. nodes.forEach(node => {
  420. if (!indegree[node]) indegree[node] = 0;
  421. if (!list[node]) list[node] = [];
  422. });
  423. function addEdge(source, target) {
  424. if (!list[source]) list[source] = [];
  425. if (!indegree[target]) indegree[target] = 0;
  426. list[source].push(target);
  427. indegree[target] += 1;
  428. }
  429. function sort() {
  430. Object.keys(indegree).forEach(id => {
  431. if (indegree[id] === 0) {
  432. queue.push(id);
  433. }
  434. });
  435. let count = 0;
  436. while (queue.length) {
  437. ++count;
  438. const currentNode = queue.pop();
  439. const nodeTargets = list[currentNode];
  440. for (let i = 0; i < nodeTargets.length; i++) {
  441. const target = nodeTargets[i];
  442. indegree[target] -= 1;
  443. if (indegree[target] === 0) {
  444. queue.push(target);
  445. }
  446. }
  447. }
  448. // false 没有输出全部顶点,有向图中有回路
  449. return !(count < V);
  450. }
  451. return sort();
  452. },
  453. externalobjectsdropped (node) { //节点生成
  454. if(node.category === 'Service' || node.category === 'Subprocesses'){
  455. this.nodeMsg[node.key] = node
  456. this.nodeMsg[node.key].name = node.text
  457. return
  458. }
  459. this.nodeMsg[node.key] = node
  460. this.nodeMsg[node.key].ruleList = []
  461. this.nodeMsg[node.key].actServiceS =[
  462. {
  463. status:1,
  464. handleValue:null,
  465. handleType:11
  466. },
  467. {
  468. status:1,
  469. handleValue:null,
  470. handleType:20
  471. }
  472. ]
  473. this.nodeMsg[node.key].actionConfig =[]
  474. this.nodeMsg[node.key].approvelList = []
  475. this.nodeMsg[node.key].approverStyle = 0
  476. this.nodeMsg[node.key].name = node.text
  477. },
  478. closeDrawer () { //关闭策划块
  479. this.drawerObject = {
  480. show: false
  481. }
  482. }
  483. }
  484. }
  485. </script>
  486. <style lang=scss" >
  487. .FlowChartComponent{
  488. width: 100%;
  489. height: 100%;
  490. overflow: hidden;
  491. display: flex;
  492. position: relative;
  493. flex-direction: column;
  494. .burgeon-alert{
  495. margin-bottom: 0;
  496. }
  497. .chartContent{
  498. flex: 1;
  499. display: flex;
  500. }
  501. #paletteDiv{
  502. padding: 5px;
  503. width: 160px;
  504. height: 100%;
  505. display: inline-block;
  506. border-right: 1px solid #dcdee2;
  507. }
  508. canvas{
  509. outline: none;
  510. }
  511. #goChart,#showChart{
  512. flex-grow: 1;
  513. flex: 1;
  514. // border: solid 1px black
  515. }
  516. }
  517. </style>