space.vue = new Vue({ el: space.appContent, data() { return { // 审核入口 auditEntranceData: [ {name: '列表、详情', value: '1000'}, {name: '详情', value: '1010'} ], // 消息类型 messageTypeData: [], serviceURI: { departmentList: departmentList, postList: postList, flowSave: flowSave, releaseVersion: releaseVersion }, // 部门数据 departmentOptions: undefined, // 岗位数据 postOptions: undefined, // GooFlow 实例化与改变节点属性时需要的 gooFlow: { // GooFlow 元素标签, el: '.demo', // 所有数据 allData: space.utils.isNull(gooFlowDataJson) ? [] : JSON.parse(gooFlowDataJson), // 当前流程图使用的数据, currentData: {}, // 索引,当前流程图数据,在所有数据中使用第几个 index: 0, // 初始化流程图的参数 property: { width: '', height: '', toolBtnsAndName: [], headLabel: true, haveTool: true, haveGroup: true, useOperStack: true, toolWidth: 125 }, // 流程图标签 title: '', key: '', // 左边工具栏的别名 nodeRemarks: [], // 已画流程图的数据 initData: space.utils.isNull(gooFlowInitData) ? undefined : JSON.parse(gooFlowInitData), // 从流程图数据中要解析的类型 nodeType: ['task', 'foreach'], nodeBpmType: 'bpm', // 字典(任务节点的表单,办理类型) dict: undefined, nodetopDesc: '当审核人是发起人时,系统将自动越过该节点', // task 节点的属性表单数据 taskForm: { // 已选中的字典类型(状态) dictType: '', name: '', // 办理类型(字典) handleType: '', // 是否部门内逐级审,默认不是 isIntradepartmental: false, // 节点审核模式 nodeMode: '1000', // 多个角色 dept: { role: [] }, // 指定部门,角色或岗位审 specifi:{ deptR: '', // 部门 role: [], // 角色,与 handleType == specifiDeptRole 时 deptP: '', // 部门 post: '' // 岗位,与 handleType == specifiDeptPost 时 }, messageType: '', // 消息标题 messageTitle: '', // 消息内容 messageContent: '', // 标题(在待办流程时显示) backlogTitle: '', // 审核入口(下拉框选项) auditEntrance: '1000', // 自动审核 automaticAudit: true, // 退回处理(拒绝处理) refuseHandle: 'node_2' }, // 决策数据 decision: undefined, // 决策节点的属性表单数据 decisionForm: { typeName: '', // 退回处理(拒绝处理) refuseHandle: 'node_2' } }, // 定义办理类型被选中的类型时,所需要显示的 dictLinked: { // 部门内逐级审 intradepartmental: 10000, // 部门内指定角色审 deptSpecifiRole: 10100, // 指定部门下角色审 specifiDeptRole: 10200, // 指定部门下岗位审 specifiDeptPost: 10300 }, // GooFlow 实例化的对象,用于撤销、重做、导出(保存) gooFlowObj: undefined, // 备用表单对象,主要用于拷贝 task、join 等表单属性,在关闭时,恢复表单的初始值,如:this.standbyFormObj = Object.assign({}, JSON.parse(JSON.stringify(this.gooFlow.taskForm))) standbyFormObj: undefined, standbyAttrUseGooFlowObj: undefined, attr: { formType: 'node', // 当前选中节点,节点属性框关闭时,需要清空 currentFocusNode: undefined, currentFocusNodeData: {}, currentFocusId: '', currentFocusType: 'node' // node、line、area,默认为节点类型 }, loading: false, } }, created: function() { this.gooFlow.currentData = space.utils.isNull(this.gooFlow.allData) ? {} : this.gooFlow.allData[this.gooFlow.index]; this.initGooFlowParam(); this.initDepartmentOption(); }, mounted: function() { var _this = this; // 浏览器窗口调整大小 window.onresize = function() { return(function() { _this.gooFlowSize(); _this.gooFlowObj.resizeGooFlow(_this.gooFlow.property.width, _this.gooFlow.property.height) })(); } // 设置 gooFlow 的宽高 this.gooFlowSize(); this.gooFlowObj = $.createGooFlow($(this.gooFlow.el), this.gooFlow.property, this) this.gooFlowObj.setTitle(this.gooFlow.title); this.gooFlowObj.setKey(this.gooFlow.key); this.gooFlowObj.loadData(this.gooFlow.initData); }, methods: { // 初始化部门数据 initDepartmentOption() { if (!this.departmentOptions) { var _this = this space.utils.ajax({ url: _this.serviceURI.departmentList, dataType: 'json', callback: function(data) { _this.departmentOptions = data.data; } }) } }, // 部门改变时联动岗位 departmentChangeToPost(value, flag) { if (!value) { this.postOptions = undefined return } var _this = this; space.utils.ajax({ url: _this.serviceURI.postList, data: { "departmentid": value }, dataType: 'json', callback: function(data) { _this.postOptions = data.data; if (!flag) { // 为 true 则不清空已选中的岗位 // 清空岗位的值 _this.gooFlow.taskForm.specifi.post = '' } } }) }, // 设置 gooFlow 的宽高 gooFlowSize: function() { // 获取当前页面最外层的宽度、高度 var spaceContentW = $("#space-content").width(); // 获取侧边栏属性的宽度、高度 var gooFlowAttrW = $(".gooFlow-attr").width(); // gooFlow 的宽度 var gooFlowW = spaceContentW - gooFlowAttrW; // gooFlow 的高度 var spaceContentH = $(".gooFlow-content").height() + 4; this.gooFlow.property.width = gooFlowW; this.gooFlow.property.height = spaceContentH; }, flowSave() { var _this = this; space.utils.ajax({ type: "post", url: _this.serviceURI.flowSave, data: { "flowId": flowId, "gooFlowData": JSON.stringify(_this.gooFlowObj.exportData()) }, dataType: 'json', callback: function(data) { space.message.auto(data); } }) }, // 初始化 GooFlow 参数 initGooFlowParam() { this.initToolBtnsParam(); this.gooFlow.dict = this.gooFlow.currentData.dict; this.gooFlow.nodeMode = this.gooFlow.currentData.nodeMode; this.gooFlow.decision = this.gooFlow.currentData.decision; this.messageTypeData = this.gooFlow.currentData.message; }, // 初始化工具栏参数 initToolBtnsParam() { if(!this.gooFlow.currentData) return; for(nodeData in this.gooFlow.currentData) { var currentNodeNameData = this.gooFlow.currentData[nodeData]; // 获取流程图的 name、key if(this.gooFlow.nodeBpmType == nodeData) { this.gooFlow.title = currentNodeNameData[0].name; this.gooFlow.key = currentNodeNameData[0].key; } if(this.gooFlow.nodeType.indexOf(nodeData) == -1) continue; var i = 0 for(node in currentNodeNameData) { // 后期要改工具栏的类型,还需要改这里的 key 规则 this.gooFlow.property.toolBtnsAndName.push({ type: nodeData, title: currentNodeNameData[i].title, name: currentNodeNameData[i].name }); i++ } } }, // 这个方法时在 GooFlow 中自定义打开模态框时回调,修改源代码 openNodeAttrCall(currentFocusNode, nodeData) { if (!currentFocusNode || !nodeData) return // 清空 this.clearCurrentFocus() // 备份属性表单使用的状态与节点数据 this.standbyAttrUseGooFlowObj = Object.assign({}, JSON.parse(JSON.stringify(this.attr))); this.attr.formType = nodeData.type; this.attr.currentFocusNode = currentFocusNode; this.attr.currentFocusNodeData = nodeData; this.attr.currentFocusId = nodeData.id; // 后续加其他节点都表单 if (this.attr.formType == 'task' || this.attr.formType == 'foreach') { this.standbyFormObj = Object.assign({}, JSON.parse(JSON.stringify(this.gooFlow.taskForm))); // 任务节点的表单备份 this.initTaskForm(); } else if (this.attr.formType == 'decision') { this.standbyFormObj = Object.assign({}, JSON.parse(JSON.stringify(this.gooFlow.decisionForm))); // 决策节点的表单备份 this.initDecisionFrom(); } }, // 办理类型改变时 handleTypeChange() { // 部门内逐级审 if (this.dictLinked.intradepartmental == this.gooFlow.taskForm.handleType) { this.gooFlow.taskForm.isIntradepartmental = true; this.gooFlow.taskForm.automaticAudit = true; } else { this.gooFlow.taskForm.isIntradepartmental = false; // 部门数据、角色数据不用重新获取,因不是随着其他数据而改变 if (this.dictLinked.specifiDeptRole == this.gooFlow.taskForm.handleType) { this.departmentChangeToPost(this.attr.currentFocusNodeData.deptR, true); } // 指定部门的岗位(有部门和岗位),清空或重新获取一次岗位数据 else if (this.dictLinked.specifiDeptPost == this.gooFlow.taskForm.handleType) { this.departmentChangeToPost(this.gooFlow.taskForm.specifi.deptP, true); } } }, /** * 检查集合中是否包含已选中的值 * @param {*} list 集合 * @param {*} listKey 集合中的key * @param {*} valueList 已选的值集合 * @returns */ checkListContainsValue: function(list, listKey, valueList) { if (!list || !valueList) { return []; } var tmpAry = []; for (let index = 0; index < list.length; index++) { tmpAry.push(list[index][listKey]); } var rstAry = []; for (let index = 0; index < valueList.length; index++) { if (tmpAry.indexOf(valueList[index]) != -1) { rstAry.push(valueList[index]); } } return rstAry; }, // 初始化任务节点的表单 initTaskForm() { this.loading = true; var that = this; setTimeout(function(){ that.loading = false; },400) // 与保存任务节点时的 this.gooFlow.taskForm.handleType = this.attr.currentFocusNodeData.handleType; this.gooFlow.taskForm.name = this.attr.currentFocusNodeData.title; this.gooFlow.taskForm.messageType = this.checkListContainsValue(this.messageTypeData, 'name', this.attr.currentFocusNodeData.messageType); this.gooFlow.taskForm.messageTitle = this.attr.currentFocusNodeData.messageTitle; this.gooFlow.taskForm.messageContent = this.attr.currentFocusNodeData.messageContent; this.gooFlow.taskForm.isIntradepartmental = this.attr.currentFocusNodeData.isIntradepartmental; this.gooFlow.taskForm.backlogTitle = this.attr.currentFocusNodeData.backlogTitle; if (this.attr.currentFocusNodeData.auditEntrance) { this.gooFlow.taskForm.auditEntrance = this.attr.currentFocusNodeData.auditEntrance; } if (this.attr.currentFocusNodeData.automaticAudit != undefined) { this.gooFlow.taskForm.automaticAudit = this.attr.currentFocusNodeData.automaticAudit; } if (this.attr.currentFocusNodeData.nodeMode) { this.gooFlow.taskForm.nodeMode = this.attr.currentFocusNodeData.nodeMode; } if (this.attr.currentFocusNodeData.refuseHandle) { this.gooFlow.taskForm.refuseHandle = this.attr.currentFocusNodeData.refuseHandle; } // 部门内的角色(当前申请人的部门下的角色) if (this.dictLinked.deptSpecifiRole == this.gooFlow.taskForm.handleType) { this.gooFlow.taskForm.dept.role = this.attr.currentFocusNodeData.role; // 要去掉审核模式 } // 指定部门的角色(有部门和角色) else if (this.dictLinked.specifiDeptRole == this.gooFlow.taskForm.handleType) { this.gooFlow.taskForm.specifi.deptR = this.attr.currentFocusNodeData.deptR; this.gooFlow.taskForm.specifi.role = this.attr.currentFocusNodeData.deptRole; } // 指定部门的岗位(有部门和岗位) else if (this.dictLinked.specifiDeptPost == this.gooFlow.taskForm.handleType) { this.gooFlow.taskForm.specifi.deptP = this.attr.currentFocusNodeData.deptP; this.gooFlow.taskForm.specifi.post = this.attr.currentFocusNodeData.deptPost; this.departmentChangeToPost(this.attr.currentFocusNodeData.deptP, true); } }, // 保存任务节点 saveTask() { // 办理类型 this.attr.currentFocusNodeData.handleType = this.gooFlow.taskForm.handleType; // 节点名称 this.attr.currentFocusNode.setNodeName(this.attr.currentFocusId, this.gooFlow.taskForm.name, this.attr.currentFocusType); // 消息类型 this.attr.currentFocusNodeData.messageType = this.gooFlow.taskForm.messageType; // 消息标题 this.attr.currentFocusNodeData.messageTitle = this.gooFlow.taskForm.messageTitle; // 消息内容 this.attr.currentFocusNodeData.messageContent = this.gooFlow.taskForm.messageContent; // 自动审核 this.attr.currentFocusNodeData.automaticAudit = this.gooFlow.taskForm.automaticAudit; // 是否部门内逐级 this.attr.currentFocusNodeData.isIntradepartmental = this.gooFlow.taskForm.isIntradepartmental; // 待办时的节点标题 this.attr.currentFocusNodeData.backlogTitle = this.gooFlow.taskForm.backlogTitle; if (this.gooFlow.taskForm.auditEntrance) { // 审核入口 this.attr.currentFocusNodeData.auditEntrance = this.gooFlow.taskForm.auditEntrance; } if (this.gooFlow.taskForm.nodeMode) { this.attr.currentFocusNodeData.nodeMode = this.gooFlow.taskForm.nodeMode; } if (this.gooFlow.taskForm.refuseHandle) { this.attr.currentFocusNodeData.refuseHandle = this.gooFlow.taskForm.refuseHandle; } delete this.attr.currentFocusNodeData.role; delete this.attr.currentFocusNodeData.dept; delete this.attr.currentFocusNodeData.deptR; delete this.attr.currentFocusNodeData.deptP; delete this.attr.currentFocusNodeData.deptRole; delete this.attr.currentFocusNodeData.deptPost; // 部门内的角色(当前申请人的部门下的角色) if (this.dictLinked.deptSpecifiRole == this.gooFlow.taskForm.handleType) { this.attr.currentFocusNodeData.role = this.gooFlow.taskForm.dept.role; } // 指定部门的角色(有部门和角色) else if (this.dictLinked.specifiDeptRole == this.gooFlow.taskForm.handleType) { this.attr.currentFocusNodeData.deptR = this.gooFlow.taskForm.specifi.deptR; this.attr.currentFocusNodeData.deptRole = this.gooFlow.taskForm.specifi.role; } // 指定部门的岗位(有部门和岗位) else if (this.dictLinked.specifiDeptPost == this.gooFlow.taskForm.handleType) { this.attr.currentFocusNodeData.deptP = this.gooFlow.taskForm.specifi.deptP; this.attr.currentFocusNodeData.deptPost = this.gooFlow.taskForm.specifi.post; } space.message.success("保存成功"); }, // 初始化决策节点的表单 initDecisionFrom() { this.loading = true; var that = this; setTimeout(function(){ that.loading = false; },400) this.gooFlow.decisionForm.typeName = this.attr.currentFocusNodeData.name; if (this.attr.currentFocusNodeData.refuseHandle) { this.gooFlow.decisionForm.refuseHandle = this.attr.currentFocusNodeData.refuseHandle; } }, // 保存决策节点 saveDecisionFrom() { this.attr.currentFocusNodeData.name = this.gooFlow.decisionForm.typeName; if (this.gooFlow.decisionForm.refuseHandle) { this.attr.currentFocusNodeData.refuseHandle = this.gooFlow.decisionForm.refuseHandle; } var transitions; for (var i = 0;i < this.gooFlow.decision.length;i++) { if (this.attr.currentFocusNodeData.name == this.gooFlow.decision[i].name) { transitions = this.gooFlow.decision[i].transition; } } // 保存决策时,还要改变连线 this.gooFlowObj.addDecisionLine(this.attr.currentFocusId, transitions); space.message.success("保存成功"); }, // 清除当前选中的节点,在关闭属性窗口时操作 clearCurrentFocus() { if(this.attr.formType == 'task' || this.attr.formType == 'foreach') { this.gooFlow.taskForm = Object.assign({}, JSON.parse(JSON.stringify(this.standbyFormObj))); } else if (this.attr.formType == 'decision') { this.gooFlow.decisionForm = Object.assign({}, JSON.parse(JSON.stringify(this.standbyFormObj))); } // 根据不同的属性表单类型,还原当前表单的默认属性 if (this.standbyAttrUseGooFlowObj) { // 还原属性表单使用的状态与节点数据 this.attr = Object.assign({}, JSON.parse(JSON.stringify(this.standbyAttrUseGooFlowObj))); } }, // 关闭属性窗口 closeAttrWindow() { this.clearCurrentFocus(); }, // 已画好流程图时的保存 saveGooFlow() { this.flowSave(); }, // 发布版本 releaseVersion() { var _this = this; // 保存流程图,发布流程版本 space.utils.ajax({ type: "post", url: _this.serviceURI.releaseVersion, data: { "flowId": flowId, "gooFlowData": JSON.stringify(_this.gooFlowObj.exportData()) }, dataType: 'json', callback: function(data) { space.message.auto(data); } }) } } })