xml.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { catchError, catchWarning } from "./printCatch";
  2. export function emptyXML(key, name) {
  3. return `<?xml version="1.0" encoding="UTF-8"?>
  4. <bpmn:definitions
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
  7. xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
  8. xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
  9. xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
  10. id="Definitions_0001">
  11. <bpmn:process id="${key}" name="${name}" isExecutable="true" />
  12. <bpmndi:BPMNDiagram id="BPMNDiagram_1">
  13. <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="${key}" />
  14. </bpmndi:BPMNDiagram>
  15. </bpmn:definitions>`;
  16. }
  17. export async function createNewDiagram(modeler, newXml, settings) {
  18. try {
  19. const timestamp = Date.now();
  20. const { processId, processName } = settings || {};
  21. const newId = processId ? processId : `Process_${timestamp}`;
  22. const newName = processName || `业务流程_${timestamp}`;
  23. const xmlString = newXml || emptyXML(newId, newName);
  24. const { warnings } = await modeler.importXML(xmlString);
  25. if (warnings && warnings.length) {
  26. warnings.forEach(catchWarning);
  27. }
  28. } catch (e) {
  29. catchError(e);
  30. }
  31. }