Browse Source

!205 修复bpmn不支持跨域的问题
Merge pull request !205 from 高雄/N/A

kailing 1 year ago
parent
commit
fa2a5d3e35
1 changed files with 14 additions and 2 deletions
  1. 14 2
      server/src/main/resources/web/bpmn.ftl

+ 14 - 2
server/src/main/resources/web/bpmn.ftl

@@ -5,6 +5,14 @@
     <meta http-equiv="content-type" content="text/html; charset=utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
     <#include "*/commonHeader.ftl">
+      <script src="js/base64.min.js" type="text/javascript"></script>
+      	<#if currentUrl?contains("http://") || currentUrl?contains("https://") || currentUrl?contains("file://")>
+    <#assign finalUrl="${currentUrl}">
+  <#elseif currentUrl?contains("ftp://") >
+   <#assign finalUrl="${currentUrl}">
+<#else>
+    <#assign finalUrl="${baseUrl}${currentUrl}">
+</#if>
     <style>
         html, body, #diagram {
             height: 100%
@@ -33,12 +41,16 @@
     const viewer = new BpmnJS({
         container: '#diagram'
     });
-
+      var url = '${finalUrl}';
+    var baseUrl = '${baseUrl}'.endsWith('/') ? '${baseUrl}' : '${baseUrl}' + '/';
+    if (!url.startsWith(baseUrl)) {
+        url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url));
+    }
     async function showDiagram(diagramXML) {
         await viewer.importXML(diagramXML);
     }
     // load + show diagram
-    $.get('${currentUrl}', showDiagram, 'text');
+    $.get(url, showDiagram, 'text');
 </script>
 </body>
 </html>