|
@@ -5,14 +5,14 @@
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
export const nodeStyleHandle = (_this, style) => {
|
|
|
- if (_this.properties.status === "pass") {
|
|
|
- style.stroke = "green";
|
|
|
- } else if (_this.properties.status === "reject") {
|
|
|
- style.stroke = "#ffba00";
|
|
|
- } else if (_this.properties.status === "approval") {
|
|
|
- style.stroke = "red";
|
|
|
+ if (_this.properties.status === 'pass') {
|
|
|
+ style.stroke = 'green'
|
|
|
+ } else if (_this.properties.status === 'reject') {
|
|
|
+ style.stroke = '#ffba00'
|
|
|
+ } else if (_this.properties.status === 'approval') {
|
|
|
+ style.stroke = 'red'
|
|
|
} else {
|
|
|
- style.stroke = "#909399";
|
|
|
+ style.stroke = '#909399'
|
|
|
}
|
|
|
return style
|
|
|
}
|
|
@@ -24,9 +24,9 @@ export const nodeStyleHandle = (_this, style) => {
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
export const nodeSizeHandle = (_this) => {
|
|
|
- _this.width = 120;
|
|
|
- _this.height = 80;
|
|
|
- _this.radius = 5;
|
|
|
+ _this.width = 120
|
|
|
+ _this.height = 80
|
|
|
+ _this.radius = 5
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -45,7 +45,6 @@ export const skipText = (skipType) => {
|
|
|
return text
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 解析xml成Dom对象
|
|
|
* @param {} xml
|
|
@@ -56,7 +55,8 @@ export const parseXml2Dom = (xml) => {
|
|
|
if (window.DOMParser) {
|
|
|
const parser = new DOMParser()
|
|
|
xmlDoc = parser.parseFromString(xml, 'text/xml')
|
|
|
- } else { // Internet Explorer
|
|
|
+ } else {
|
|
|
+ // Internet Explorer
|
|
|
// eslint-disable-next-line no-undef
|
|
|
xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
|
|
|
xmlDoc.async = false
|
|
@@ -70,8 +70,19 @@ const NODE_NAMES = ['start', 'between', 'serial', 'parallel', 'end']
|
|
|
// 流程节点属性
|
|
|
const DEFINITION_KEYS = ['flowCode', 'flowName', 'version', 'fromCustom', 'fromPath']
|
|
|
// 节点属性
|
|
|
-const NODE_ATTR_KEYS = ['nodeType', 'nodeCode', 'nodeName', 'coordinate', 'nodeRatio', 'permissionFlag', "skipAnyNode"
|
|
|
- , "listenerType", "listenerPath", "formCustom", "formPath"]
|
|
|
+const NODE_ATTR_KEYS = [
|
|
|
+ 'nodeType',
|
|
|
+ 'nodeCode',
|
|
|
+ 'nodeName',
|
|
|
+ 'coordinate',
|
|
|
+ 'nodeRatio',
|
|
|
+ 'permissionFlag',
|
|
|
+ 'skipAnyNode',
|
|
|
+ 'listenerType',
|
|
|
+ 'listenerPath',
|
|
|
+ 'formCustom',
|
|
|
+ 'formPath'
|
|
|
+]
|
|
|
// 变迁节点属性
|
|
|
const SKIP_ATTR_KEYS = ['skipName', 'skipType', 'coordinate', 'skipCondition']
|
|
|
|
|
@@ -92,7 +103,7 @@ export const xml2LogicFlowJson = (xml) => {
|
|
|
}
|
|
|
let value = null
|
|
|
// 解析definition属性
|
|
|
- DEFINITION_KEYS.forEach(key => {
|
|
|
+ DEFINITION_KEYS.forEach((key) => {
|
|
|
value = definitionDom[0].getAttribute(key)
|
|
|
if (value) {
|
|
|
graphData[key] = value
|
|
@@ -102,16 +113,16 @@ export const xml2LogicFlowJson = (xml) => {
|
|
|
let node = null
|
|
|
let lfNode = {}
|
|
|
// 解析节点
|
|
|
- nodeEles = definitionDom[0].getElementsByTagName("node")
|
|
|
+ nodeEles = definitionDom[0].getElementsByTagName('node')
|
|
|
if (nodeEles.length) {
|
|
|
for (var i = 0, len = nodeEles.length; i < len; i++) {
|
|
|
node = nodeEles[i]
|
|
|
lfNode = {
|
|
|
- text:{},
|
|
|
+ text: {},
|
|
|
properties: {}
|
|
|
}
|
|
|
// 处理节点
|
|
|
- NODE_ATTR_KEYS.forEach(attrKey => {
|
|
|
+ NODE_ATTR_KEYS.forEach((attrKey) => {
|
|
|
value = node.getAttribute(attrKey)
|
|
|
if (value) {
|
|
|
if (attrKey === 'nodeType') {
|
|
@@ -145,7 +156,7 @@ export const xml2LogicFlowJson = (xml) => {
|
|
|
skipEle = skipEles[j]
|
|
|
edge = {
|
|
|
text: {},
|
|
|
- properties: {},
|
|
|
+ properties: {}
|
|
|
}
|
|
|
edge.id = skipEle.getAttribute('id')
|
|
|
edge.type = 'skip'
|
|
@@ -153,7 +164,6 @@ export const xml2LogicFlowJson = (xml) => {
|
|
|
edge.targetNodeId = skipEle.textContent
|
|
|
edge.text = {
|
|
|
value: skipEle.getAttribute('skipName')
|
|
|
-
|
|
|
}
|
|
|
edge.properties.skipCondition = skipEle.getAttribute('skipCondition')
|
|
|
edge.properties.skipName = skipEle.getAttribute('skipName')
|
|
@@ -176,7 +186,7 @@ export const xml2LogicFlowJson = (xml) => {
|
|
|
edge.startPoint = edge.pointsList[0]
|
|
|
edge.endPoint = edge.pointsList[edge.pointsList.length - 1]
|
|
|
if (coordinateXy.length > 1) {
|
|
|
- let textXy = coordinateXy[1].split(",");
|
|
|
+ let textXy = coordinateXy[1].split(',')
|
|
|
edge.text.x = parseInt(textXy[0])
|
|
|
edge.text.y = parseInt(textXy[1])
|
|
|
}
|
|
@@ -203,7 +213,7 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
flowName: data.flowName, // 流程定义名称
|
|
|
version: data.version, // 流程定义版本号
|
|
|
fromCustom: data.fromCustom, // 表单自定义
|
|
|
- fromPath: data.fromPath, // 表单自定义路径
|
|
|
+ fromPath: data.fromPath // 表单自定义路径
|
|
|
}
|
|
|
/**
|
|
|
* 获取开始节点
|
|
@@ -220,13 +230,15 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
* @returns
|
|
|
*/
|
|
|
const getNextNodes = (id) => {
|
|
|
- return data.edges.filter(edge => {
|
|
|
- return edge.sourceNodeId === id
|
|
|
- }).map(edge => {
|
|
|
- return data.nodes.find((node) => {
|
|
|
- return node.id === edge.targetNodeId
|
|
|
+ return data.edges
|
|
|
+ .filter((edge) => {
|
|
|
+ return edge.sourceNodeId === id
|
|
|
+ })
|
|
|
+ .map((edge) => {
|
|
|
+ return data.nodes.find((node) => {
|
|
|
+ return node.id === edge.targetNodeId
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
}
|
|
|
/**
|
|
|
* 获取节点所有跳转
|
|
@@ -234,27 +246,30 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
* @returns
|
|
|
*/
|
|
|
const getSkip = (id) => {
|
|
|
- return data.edges.filter((edge) => {
|
|
|
- return edge.sourceNodeId === id
|
|
|
- }).map(edge => {
|
|
|
- let coordinate = ''
|
|
|
- for (let i = 0; i < edge.pointsList.length; i++) {
|
|
|
- coordinate = coordinate + parseInt(edge.pointsList[i].x) + ',' + parseInt(edge.pointsList[i].y)
|
|
|
- if (i !== edge.pointsList.length - 1) {
|
|
|
- coordinate = coordinate + ';'
|
|
|
+ return data.edges
|
|
|
+ .filter((edge) => {
|
|
|
+ return edge.sourceNodeId === id
|
|
|
+ })
|
|
|
+ .map((edge) => {
|
|
|
+ let coordinate = ''
|
|
|
+ for (let i = 0; i < edge.pointsList.length; i++) {
|
|
|
+ coordinate =
|
|
|
+ coordinate + parseInt(edge.pointsList[i].x) + ',' + parseInt(edge.pointsList[i].y)
|
|
|
+ if (i !== edge.pointsList.length - 1) {
|
|
|
+ coordinate = coordinate + ';'
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (edge.text) {
|
|
|
- coordinate = coordinate + '|' + parseInt(edge.text.x) + ',' + parseInt(edge.text.y)
|
|
|
- }
|
|
|
- return {
|
|
|
- skipType: edge.properties.skipType,
|
|
|
- skipCondition: edge.properties.skipCondition,
|
|
|
- skipName: edge?.text?.value || edge.properties.skipName,
|
|
|
- textContent: edge.targetNodeId, // 目地节点id
|
|
|
- coordinate: coordinate,
|
|
|
- }
|
|
|
- })
|
|
|
+ if (edge.text) {
|
|
|
+ coordinate = coordinate + '|' + parseInt(edge.text.x) + ',' + parseInt(edge.text.y)
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ skipType: edge.properties.skipType,
|
|
|
+ skipCondition: edge.properties.skipCondition,
|
|
|
+ skipName: edge?.text?.value || edge.properties.skipName,
|
|
|
+ textContent: edge.targetNodeId, // 目地节点id
|
|
|
+ coordinate: coordinate
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
/**
|
|
|
* 构建节点属性
|
|
@@ -262,14 +277,15 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
* @returns
|
|
|
*/
|
|
|
const buildNode = (node) => {
|
|
|
- let textXy = '';
|
|
|
+ let textXy = ''
|
|
|
if (node.text) {
|
|
|
- textXy = '|' + node.text.x + ',' + node.text.y;
|
|
|
+ textXy = '|' + node.text.x + ',' + node.text.y
|
|
|
}
|
|
|
return {
|
|
|
nodeType: node.type,
|
|
|
nodeCode: node.id,
|
|
|
- nodeName: (node.text instanceof String || node.text === undefined) ? node.text : node.text.value,
|
|
|
+ nodeName:
|
|
|
+ node.text instanceof String || node.text === undefined ? node.text : node.text.value,
|
|
|
permissionFlag: node.properties.permissionFlag,
|
|
|
nodeRatio: node.properties.nodeRatio,
|
|
|
skipAnyNode: node.properties.skipAnyNode,
|
|
@@ -287,7 +303,8 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
* @returns
|
|
|
*/
|
|
|
const textEncode = (text) => {
|
|
|
- text = text.replace(/&/g, '&')
|
|
|
+ text = text
|
|
|
+ .replace(/&/g, '&')
|
|
|
.replace(/"/g, '"')
|
|
|
.replace(/</g, '<')
|
|
|
.replace(/>/g, '>')
|
|
@@ -302,7 +319,7 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
if (!definitionObj[nodeName + '_' + node.id]) {
|
|
|
definitionObj[nodeName + '_' + node.id] = buildNode(node)
|
|
|
const nextNodes = getNextNodes(node.id)
|
|
|
- nextNodes.forEach(nextNode => {
|
|
|
+ nextNodes.forEach((nextNode) => {
|
|
|
recursionBuildNode(nextNode)
|
|
|
})
|
|
|
}
|
|
@@ -315,7 +332,7 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
recursionBuildNode(startNode)
|
|
|
xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
|
|
|
xml += '<definition'
|
|
|
- Object.keys(definitionObj).forEach(key => {
|
|
|
+ Object.keys(definitionObj).forEach((key) => {
|
|
|
const value = definitionObj[key]
|
|
|
if (DEFINITION_KEYS.includes(key) && value) {
|
|
|
xml += ' ' + key + '=' + '"' + textEncode(value) + '"'
|
|
@@ -323,13 +340,13 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
})
|
|
|
xml += '>\n'
|
|
|
// 生成节点xml
|
|
|
- Object.keys(definitionObj).forEach(key => {
|
|
|
+ Object.keys(definitionObj).forEach((key) => {
|
|
|
const value = definitionObj[key]
|
|
|
let nodeName = key.split('_')[0]
|
|
|
if (NODE_NAMES.includes(nodeName)) {
|
|
|
xml += '\t<node'
|
|
|
// 构造属性
|
|
|
- Object.keys(value).forEach(nodeAttrKey => {
|
|
|
+ Object.keys(value).forEach((nodeAttrKey) => {
|
|
|
if (NODE_ATTR_KEYS.includes(nodeAttrKey) && value[nodeAttrKey]) {
|
|
|
xml += ' ' + nodeAttrKey + '=' + '"' + textEncode(value[nodeAttrKey]) + '"'
|
|
|
}
|
|
@@ -337,10 +354,10 @@ export const logicFlowJsonToFlowXml = (data) => {
|
|
|
xml += '>\n\t'
|
|
|
// 构建skip
|
|
|
if (value.skip) {
|
|
|
- value.skip.forEach(skip => {
|
|
|
+ value.skip.forEach((skip) => {
|
|
|
xml += '\t<skip'
|
|
|
// skip属性
|
|
|
- Object.keys(skip).forEach(skipAttrKey => {
|
|
|
+ Object.keys(skip).forEach((skipAttrKey) => {
|
|
|
if (SKIP_ATTR_KEYS.includes(skipAttrKey) && skip[skipAttrKey]) {
|
|
|
xml += ' ' + skipAttrKey + '=' + '"' + textEncode(skip[skipAttrKey]) + '"'
|
|
|
}
|