flowEdit.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. space.vue = new Vue({
  2. el: space.appContent,
  3. data() {
  4. return {
  5. // 审核入口
  6. auditEntranceData: [
  7. {name: '列表、详情', value: '1000'},
  8. {name: '详情', value: '1010'}
  9. ],
  10. // 消息类型
  11. messageTypeData: [],
  12. serviceURI: {
  13. departmentList: departmentList,
  14. postList: postList,
  15. flowSave: flowSave,
  16. releaseVersion: releaseVersion
  17. },
  18. // 部门数据
  19. departmentOptions: undefined,
  20. // 岗位数据
  21. postOptions: undefined,
  22. // GooFlow 实例化与改变节点属性时需要的
  23. gooFlow: {
  24. // GooFlow 元素标签,
  25. el: '.demo',
  26. // 所有数据
  27. allData: space.utils.isNull(gooFlowDataJson) ? [] : JSON.parse(gooFlowDataJson),
  28. // 当前流程图使用的数据,
  29. currentData: {},
  30. // 索引,当前流程图数据,在所有数据中使用第几个
  31. index: 0,
  32. // 初始化流程图的参数
  33. property: {
  34. width: '',
  35. height: '',
  36. toolBtnsAndName: [],
  37. headLabel: true,
  38. haveTool: true,
  39. haveGroup: true,
  40. useOperStack: true,
  41. toolWidth: 125
  42. },
  43. // 流程图标签
  44. title: '',
  45. key: '',
  46. // 左边工具栏的别名
  47. nodeRemarks: [],
  48. // 已画流程图的数据
  49. initData: space.utils.isNull(gooFlowInitData) ? undefined : JSON.parse(gooFlowInitData),
  50. // 从流程图数据中要解析的类型
  51. nodeType: ['task', 'foreach'],
  52. nodeBpmType: 'bpm',
  53. // 字典(任务节点的表单,办理类型)
  54. dict: undefined,
  55. nodetopDesc: '当审核人是发起人时,系统将自动越过该节点',
  56. // task 节点的属性表单数据
  57. taskForm: {
  58. // 已选中的字典类型(状态)
  59. dictType: '',
  60. name: '',
  61. // 办理类型(字典)
  62. handleType: '',
  63. // 是否部门内逐级审,默认不是
  64. isIntradepartmental: false,
  65. // 节点审核模式
  66. nodeMode: '1000',
  67. // 多个角色
  68. dept: {
  69. role: []
  70. },
  71. // 指定部门,角色或岗位审
  72. specifi:{
  73. deptR: '', // 部门
  74. role: [], // 角色,与 handleType == specifiDeptRole 时
  75. deptP: '', // 部门
  76. post: '' // 岗位,与 handleType == specifiDeptPost 时
  77. },
  78. messageType: '',
  79. // 消息标题
  80. messageTitle: '',
  81. // 消息内容
  82. messageContent: '',
  83. // 标题(在待办流程时显示)
  84. backlogTitle: '',
  85. // 审核入口(下拉框选项)
  86. auditEntrance: '1000',
  87. // 自动审核
  88. automaticAudit: true,
  89. // 退回处理(拒绝处理)
  90. refuseHandle: 'node_2'
  91. },
  92. // 决策数据
  93. decision: undefined,
  94. // 决策节点的属性表单数据
  95. decisionForm: {
  96. typeName: '',
  97. // 退回处理(拒绝处理)
  98. refuseHandle: 'node_2'
  99. }
  100. },
  101. // 定义办理类型被选中的类型时,所需要显示的
  102. dictLinked: {
  103. // 部门内逐级审
  104. intradepartmental: 10000,
  105. // 部门内指定角色审
  106. deptSpecifiRole: 10100,
  107. // 指定部门下角色审
  108. specifiDeptRole: 10200,
  109. // 指定部门下岗位审
  110. specifiDeptPost: 10300
  111. },
  112. // GooFlow 实例化的对象,用于撤销、重做、导出(保存)
  113. gooFlowObj: undefined,
  114. // 备用表单对象,主要用于拷贝 task、join 等表单属性,在关闭时,恢复表单的初始值,如:this.standbyFormObj = Object.assign({}, JSON.parse(JSON.stringify(this.gooFlow.taskForm)))
  115. standbyFormObj: undefined,
  116. standbyAttrUseGooFlowObj: undefined,
  117. attr: {
  118. formType: 'node',
  119. // 当前选中节点,节点属性框关闭时,需要清空
  120. currentFocusNode: undefined,
  121. currentFocusNodeData: {},
  122. currentFocusId: '',
  123. currentFocusType: 'node' // node、line、area,默认为节点类型
  124. },
  125. loading: false,
  126. }
  127. },
  128. created: function() {
  129. this.gooFlow.currentData = space.utils.isNull(this.gooFlow.allData) ? {} : this.gooFlow.allData[this.gooFlow.index];
  130. this.initGooFlowParam();
  131. this.initDepartmentOption();
  132. },
  133. mounted: function() {
  134. var _this = this;
  135. // 浏览器窗口调整大小
  136. window.onresize = function() {
  137. return(function() {
  138. _this.gooFlowSize();
  139. _this.gooFlowObj.resizeGooFlow(_this.gooFlow.property.width, _this.gooFlow.property.height)
  140. })();
  141. }
  142. // 设置 gooFlow 的宽高
  143. this.gooFlowSize();
  144. this.gooFlowObj = $.createGooFlow($(this.gooFlow.el), this.gooFlow.property, this)
  145. this.gooFlowObj.setTitle(this.gooFlow.title);
  146. this.gooFlowObj.setKey(this.gooFlow.key);
  147. this.gooFlowObj.loadData(this.gooFlow.initData);
  148. },
  149. methods: {
  150. // 初始化部门数据
  151. initDepartmentOption() {
  152. if (!this.departmentOptions) {
  153. var _this = this
  154. space.utils.ajax({
  155. url: _this.serviceURI.departmentList,
  156. dataType: 'json',
  157. callback: function(data) {
  158. _this.departmentOptions = data.data;
  159. }
  160. })
  161. }
  162. },
  163. // 部门改变时联动岗位
  164. departmentChangeToPost(value, flag) {
  165. if (!value) {
  166. this.postOptions = undefined
  167. return
  168. }
  169. var _this = this;
  170. space.utils.ajax({
  171. url: _this.serviceURI.postList,
  172. data: {
  173. "departmentid": value
  174. },
  175. dataType: 'json',
  176. callback: function(data) {
  177. _this.postOptions = data.data;
  178. if (!flag) { // 为 true 则不清空已选中的岗位
  179. // 清空岗位的值
  180. _this.gooFlow.taskForm.specifi.post = ''
  181. }
  182. }
  183. })
  184. },
  185. // 设置 gooFlow 的宽高
  186. gooFlowSize: function() {
  187. // 获取当前页面最外层的宽度、高度
  188. var spaceContentW = $("#space-content").width();
  189. // 获取侧边栏属性的宽度、高度
  190. var gooFlowAttrW = $(".gooFlow-attr").width();
  191. // gooFlow 的宽度
  192. var gooFlowW = spaceContentW - gooFlowAttrW;
  193. // gooFlow 的高度
  194. var spaceContentH = $(".gooFlow-content").height() + 4;
  195. this.gooFlow.property.width = gooFlowW;
  196. this.gooFlow.property.height = spaceContentH;
  197. },
  198. flowSave() {
  199. var _this = this;
  200. space.utils.ajax({
  201. type: "post",
  202. url: _this.serviceURI.flowSave,
  203. data: {
  204. "flowId": flowId,
  205. "gooFlowData": JSON.stringify(_this.gooFlowObj.exportData())
  206. },
  207. dataType: 'json',
  208. callback: function(data) {
  209. space.message.auto(data);
  210. }
  211. })
  212. },
  213. // 初始化 GooFlow 参数
  214. initGooFlowParam() {
  215. this.initToolBtnsParam();
  216. this.gooFlow.dict = this.gooFlow.currentData.dict;
  217. this.gooFlow.nodeMode = this.gooFlow.currentData.nodeMode;
  218. this.gooFlow.decision = this.gooFlow.currentData.decision;
  219. this.messageTypeData = this.gooFlow.currentData.message;
  220. },
  221. // 初始化工具栏参数
  222. initToolBtnsParam() {
  223. if(!this.gooFlow.currentData) return;
  224. for(nodeData in this.gooFlow.currentData) {
  225. var currentNodeNameData = this.gooFlow.currentData[nodeData];
  226. // 获取流程图的 name、key
  227. if(this.gooFlow.nodeBpmType == nodeData) {
  228. this.gooFlow.title = currentNodeNameData[0].name;
  229. this.gooFlow.key = currentNodeNameData[0].key;
  230. }
  231. if(this.gooFlow.nodeType.indexOf(nodeData) == -1) continue;
  232. var i = 0
  233. for(node in currentNodeNameData) {
  234. // 后期要改工具栏的类型,还需要改这里的 key 规则
  235. this.gooFlow.property.toolBtnsAndName.push({
  236. type: nodeData,
  237. title: currentNodeNameData[i].title,
  238. name: currentNodeNameData[i].name
  239. });
  240. i++
  241. }
  242. }
  243. },
  244. // 这个方法时在 GooFlow 中自定义打开模态框时回调,修改源代码
  245. openNodeAttrCall(currentFocusNode, nodeData) {
  246. if (!currentFocusNode || !nodeData) return
  247. // 清空
  248. this.clearCurrentFocus()
  249. // 备份属性表单使用的状态与节点数据
  250. this.standbyAttrUseGooFlowObj = Object.assign({}, JSON.parse(JSON.stringify(this.attr)));
  251. this.attr.formType = nodeData.type;
  252. this.attr.currentFocusNode = currentFocusNode;
  253. this.attr.currentFocusNodeData = nodeData;
  254. this.attr.currentFocusId = nodeData.id;
  255. // 后续加其他节点都表单
  256. if (this.attr.formType == 'task' || this.attr.formType == 'foreach') {
  257. this.standbyFormObj = Object.assign({}, JSON.parse(JSON.stringify(this.gooFlow.taskForm)));
  258. // 任务节点的表单备份
  259. this.initTaskForm();
  260. }
  261. else if (this.attr.formType == 'decision') {
  262. this.standbyFormObj = Object.assign({}, JSON.parse(JSON.stringify(this.gooFlow.decisionForm)));
  263. // 决策节点的表单备份
  264. this.initDecisionFrom();
  265. }
  266. },
  267. // 办理类型改变时
  268. handleTypeChange() {
  269. // 部门内逐级审
  270. if (this.dictLinked.intradepartmental == this.gooFlow.taskForm.handleType) {
  271. this.gooFlow.taskForm.isIntradepartmental = true;
  272. this.gooFlow.taskForm.automaticAudit = true;
  273. }
  274. else {
  275. this.gooFlow.taskForm.isIntradepartmental = false;
  276. // 部门数据、角色数据不用重新获取,因不是随着其他数据而改变
  277. if (this.dictLinked.specifiDeptRole == this.gooFlow.taskForm.handleType) {
  278. this.departmentChangeToPost(this.attr.currentFocusNodeData.deptR, true);
  279. }
  280. // 指定部门的岗位(有部门和岗位),清空或重新获取一次岗位数据
  281. else if (this.dictLinked.specifiDeptPost == this.gooFlow.taskForm.handleType) {
  282. this.departmentChangeToPost(this.gooFlow.taskForm.specifi.deptP, true);
  283. }
  284. }
  285. },
  286. /**
  287. * 检查集合中是否包含已选中的值
  288. * @param {*} list 集合
  289. * @param {*} listKey 集合中的key
  290. * @param {*} valueList 已选的值集合
  291. * @returns
  292. */
  293. checkListContainsValue: function(list, listKey, valueList) {
  294. if (!list || !valueList) {
  295. return [];
  296. }
  297. var tmpAry = [];
  298. for (let index = 0; index < list.length; index++) {
  299. tmpAry.push(list[index][listKey]);
  300. }
  301. var rstAry = [];
  302. for (let index = 0; index < valueList.length; index++) {
  303. if (tmpAry.indexOf(valueList[index]) != -1) {
  304. rstAry.push(valueList[index]);
  305. }
  306. }
  307. return rstAry;
  308. },
  309. // 初始化任务节点的表单
  310. initTaskForm() {
  311. this.loading = true;
  312. var that = this;
  313. setTimeout(function(){
  314. that.loading = false;
  315. },400)
  316. // 与保存任务节点时的
  317. this.gooFlow.taskForm.handleType = this.attr.currentFocusNodeData.handleType;
  318. this.gooFlow.taskForm.name = this.attr.currentFocusNodeData.title;
  319. this.gooFlow.taskForm.messageType = this.checkListContainsValue(this.messageTypeData, 'name', this.attr.currentFocusNodeData.messageType);
  320. this.gooFlow.taskForm.messageTitle = this.attr.currentFocusNodeData.messageTitle;
  321. this.gooFlow.taskForm.messageContent = this.attr.currentFocusNodeData.messageContent;
  322. this.gooFlow.taskForm.isIntradepartmental = this.attr.currentFocusNodeData.isIntradepartmental;
  323. this.gooFlow.taskForm.backlogTitle = this.attr.currentFocusNodeData.backlogTitle;
  324. if (this.attr.currentFocusNodeData.auditEntrance) {
  325. this.gooFlow.taskForm.auditEntrance = this.attr.currentFocusNodeData.auditEntrance;
  326. }
  327. if (this.attr.currentFocusNodeData.automaticAudit != undefined) {
  328. this.gooFlow.taskForm.automaticAudit = this.attr.currentFocusNodeData.automaticAudit;
  329. }
  330. if (this.attr.currentFocusNodeData.nodeMode) {
  331. this.gooFlow.taskForm.nodeMode = this.attr.currentFocusNodeData.nodeMode;
  332. }
  333. if (this.attr.currentFocusNodeData.refuseHandle) {
  334. this.gooFlow.taskForm.refuseHandle = this.attr.currentFocusNodeData.refuseHandle;
  335. }
  336. // 部门内的角色(当前申请人的部门下的角色)
  337. if (this.dictLinked.deptSpecifiRole == this.gooFlow.taskForm.handleType) {
  338. this.gooFlow.taskForm.dept.role = this.attr.currentFocusNodeData.role;
  339. // 要去掉审核模式
  340. }
  341. // 指定部门的角色(有部门和角色)
  342. else if (this.dictLinked.specifiDeptRole == this.gooFlow.taskForm.handleType) {
  343. this.gooFlow.taskForm.specifi.deptR = this.attr.currentFocusNodeData.deptR;
  344. this.gooFlow.taskForm.specifi.role = this.attr.currentFocusNodeData.deptRole;
  345. }
  346. // 指定部门的岗位(有部门和岗位)
  347. else if (this.dictLinked.specifiDeptPost == this.gooFlow.taskForm.handleType) {
  348. this.gooFlow.taskForm.specifi.deptP = this.attr.currentFocusNodeData.deptP;
  349. this.gooFlow.taskForm.specifi.post = this.attr.currentFocusNodeData.deptPost;
  350. this.departmentChangeToPost(this.attr.currentFocusNodeData.deptP, true);
  351. }
  352. },
  353. // 保存任务节点
  354. saveTask() {
  355. // 办理类型
  356. this.attr.currentFocusNodeData.handleType = this.gooFlow.taskForm.handleType;
  357. // 节点名称
  358. this.attr.currentFocusNode.setNodeName(this.attr.currentFocusId, this.gooFlow.taskForm.name, this.attr.currentFocusType);
  359. // 消息类型
  360. this.attr.currentFocusNodeData.messageType = this.gooFlow.taskForm.messageType;
  361. // 消息标题
  362. this.attr.currentFocusNodeData.messageTitle = this.gooFlow.taskForm.messageTitle;
  363. // 消息内容
  364. this.attr.currentFocusNodeData.messageContent = this.gooFlow.taskForm.messageContent;
  365. // 自动审核
  366. this.attr.currentFocusNodeData.automaticAudit = this.gooFlow.taskForm.automaticAudit;
  367. // 是否部门内逐级
  368. this.attr.currentFocusNodeData.isIntradepartmental = this.gooFlow.taskForm.isIntradepartmental;
  369. // 待办时的节点标题
  370. this.attr.currentFocusNodeData.backlogTitle = this.gooFlow.taskForm.backlogTitle;
  371. if (this.gooFlow.taskForm.auditEntrance) {
  372. // 审核入口
  373. this.attr.currentFocusNodeData.auditEntrance = this.gooFlow.taskForm.auditEntrance;
  374. }
  375. if (this.gooFlow.taskForm.nodeMode) {
  376. this.attr.currentFocusNodeData.nodeMode = this.gooFlow.taskForm.nodeMode;
  377. }
  378. if (this.gooFlow.taskForm.refuseHandle) {
  379. this.attr.currentFocusNodeData.refuseHandle = this.gooFlow.taskForm.refuseHandle;
  380. }
  381. delete this.attr.currentFocusNodeData.role;
  382. delete this.attr.currentFocusNodeData.dept;
  383. delete this.attr.currentFocusNodeData.deptR;
  384. delete this.attr.currentFocusNodeData.deptP;
  385. delete this.attr.currentFocusNodeData.deptRole;
  386. delete this.attr.currentFocusNodeData.deptPost;
  387. // 部门内的角色(当前申请人的部门下的角色)
  388. if (this.dictLinked.deptSpecifiRole == this.gooFlow.taskForm.handleType) {
  389. this.attr.currentFocusNodeData.role = this.gooFlow.taskForm.dept.role;
  390. }
  391. // 指定部门的角色(有部门和角色)
  392. else if (this.dictLinked.specifiDeptRole == this.gooFlow.taskForm.handleType) {
  393. this.attr.currentFocusNodeData.deptR = this.gooFlow.taskForm.specifi.deptR;
  394. this.attr.currentFocusNodeData.deptRole = this.gooFlow.taskForm.specifi.role;
  395. }
  396. // 指定部门的岗位(有部门和岗位)
  397. else if (this.dictLinked.specifiDeptPost == this.gooFlow.taskForm.handleType) {
  398. this.attr.currentFocusNodeData.deptP = this.gooFlow.taskForm.specifi.deptP;
  399. this.attr.currentFocusNodeData.deptPost = this.gooFlow.taskForm.specifi.post;
  400. }
  401. space.message.success("保存成功");
  402. },
  403. // 初始化决策节点的表单
  404. initDecisionFrom() {
  405. this.loading = true;
  406. var that = this;
  407. setTimeout(function(){
  408. that.loading = false;
  409. },400)
  410. this.gooFlow.decisionForm.typeName = this.attr.currentFocusNodeData.name;
  411. if (this.attr.currentFocusNodeData.refuseHandle) {
  412. this.gooFlow.decisionForm.refuseHandle = this.attr.currentFocusNodeData.refuseHandle;
  413. }
  414. },
  415. // 保存决策节点
  416. saveDecisionFrom() {
  417. this.attr.currentFocusNodeData.name = this.gooFlow.decisionForm.typeName;
  418. if (this.gooFlow.decisionForm.refuseHandle) {
  419. this.attr.currentFocusNodeData.refuseHandle = this.gooFlow.decisionForm.refuseHandle;
  420. }
  421. var transitions;
  422. for (var i = 0;i < this.gooFlow.decision.length;i++) {
  423. if (this.attr.currentFocusNodeData.name == this.gooFlow.decision[i].name) {
  424. transitions = this.gooFlow.decision[i].transition;
  425. }
  426. }
  427. // 保存决策时,还要改变连线
  428. this.gooFlowObj.addDecisionLine(this.attr.currentFocusId, transitions);
  429. space.message.success("保存成功");
  430. },
  431. // 清除当前选中的节点,在关闭属性窗口时操作
  432. clearCurrentFocus() {
  433. if(this.attr.formType == 'task' || this.attr.formType == 'foreach') {
  434. this.gooFlow.taskForm = Object.assign({}, JSON.parse(JSON.stringify(this.standbyFormObj)));
  435. }
  436. else if (this.attr.formType == 'decision') {
  437. this.gooFlow.decisionForm = Object.assign({}, JSON.parse(JSON.stringify(this.standbyFormObj)));
  438. }
  439. // 根据不同的属性表单类型,还原当前表单的默认属性
  440. if (this.standbyAttrUseGooFlowObj) {
  441. // 还原属性表单使用的状态与节点数据
  442. this.attr = Object.assign({}, JSON.parse(JSON.stringify(this.standbyAttrUseGooFlowObj)));
  443. }
  444. },
  445. // 关闭属性窗口
  446. closeAttrWindow() {
  447. this.clearCurrentFocus();
  448. },
  449. // 已画好流程图时的保存
  450. saveGooFlow() {
  451. this.flowSave();
  452. },
  453. // 发布版本
  454. releaseVersion() {
  455. var _this = this;
  456. // 保存流程图,发布流程版本
  457. space.utils.ajax({
  458. type: "post",
  459. url: _this.serviceURI.releaseVersion,
  460. data: {
  461. "flowId": flowId,
  462. "gooFlowData": JSON.stringify(_this.gooFlowObj.exportData())
  463. },
  464. dataType: 'json',
  465. callback: function(data) {
  466. if (data.code == 'success') {
  467. space.message.success(data.msg);
  468. }
  469. }
  470. })
  471. }
  472. }
  473. })