vue3集成bpmn.js詳細代碼示例
更新時間:2024年01月11日 09:19:44 作者:高秉文
bpmn.js是一個BPMN2.0渲染工具包和web建模器,使得畫流程圖的功能在前端來完成,這篇文章主要給大家介紹了關于vue3集成bpmn.js的相關資料,文中通過代碼示例介紹的非常詳細,需要的朋友可以參考下
1 安裝依賴
npm install bpmn-js npm install bpmn-js-properties-panel npm install camunda-bpmn-moddle
注意依賴會有沖突,最好按照下列版本來安裝:
"bpmn-js": "^7.3.1", "bpmn-js-properties-panel": "^0.37.2", "bpmn-moddle": "^6.0.0", "camunda-bpmn-moddle": "^4.5.0", "diagram-js-minimap": "2.0.4",
2 編寫頁面
(1)引入相關依賴
import { onMounted, markRaw } from 'vue'; // bpmn-js相關 import 'bpmn-js/dist/assets/diagram-js.css'; // 左邊工具欄以及編輯節(jié)點的樣式 import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css'; import BpmnModeler from 'bpmn-js/lib/Modeler'; // bpmn-js-properties-panel相關 import 'bpmn-js-properties-panel/dist/assets/bpmn-js-properties-panel.css' import propertiesPanelModule from 'bpmn-js-properties-panel' import propertiesProviderModule from 'bpmn-js-properties-panel/lib/provider/camunda' import camundaModdleDescriptor from 'camunda-bpmn-moddle/resources/camunda'
(2)編寫DIV
<div class="containerBox" style="position: relative;"> <div id="container" style="width: calc(100vw - 750px); height: calc(100vh - 150px)"> </div> <div id="js-properties-panel" class="panel"></div> </div>
(3)DIV樣式調整
<style> .containerBox { height: calc(100vh - 160px); margin-top: 30px; } .containerBox #container { height: calc(100vh - 160px); border: 1px solid rgb(121, 121, 121); } .bpp-properties-panel [type=text] { box-sizing: border-box; } .panel { width: 400px; position: absolute; top: 1px; right: 1px; height: 100%; overflow: auto; } /* 右下角logo */ .bjs-powered-by { display: none; } </style>
(4)頁面初始化時,創(chuàng)建bpmn畫板
onMounted(() => { const containerEl = document.getElementById('container'); const bpmnModeler = markRaw(new BpmnModeler({ container: containerEl, // 添加控制板 propertiesPanel: { parent: '#js-properties-panel' }, // 右側屬性面板 additionalModules: [ propertiesPanelModule, propertiesProviderModule ], moddleExtensions: { camunda: camundaModdleDescriptor } })); bpmnModeler.createDiagram(() => { bpmnModeler.get('canvas').zoom('fit-viewport'); }); })
(5)漢化bpmn
assets/bpmn/zh.js
export default { // Labels "Activate the global connect tool": "激活全局連接工具", "Append {type}": "追加 {type}", "Append EndEvent": "追加 結束事件 ", "Append Task": "追加 任務", "Append Gateway": "追加 網關", "Append Intermediate/Boundary Event": "追加 中間/邊界 事件", "Add Lane above": "在上面添加道", "Divide into two Lanes": "分割成兩個道", "Divide into three Lanes": "分割成三個道", "Add Lane below": "在下面添加道", "Append compensation activity": "追加補償活動", "Change type": "修改類型", "Connect using Association": "使用關聯(lián)連接", "Connect using Sequence/MessageFlow or Association": "使用順序/消息流或者關聯(lián)連接", "Connect using DataInputAssociation": "使用數據輸入關聯(lián)連接", "Remove": "移除", "Activate the hand tool": "激活抓手工具", "Activate the lasso tool": "激活套索工具", "Activate the create/remove space tool": "激活創(chuàng)建/刪除空間工具", "Create expanded SubProcess": "創(chuàng)建擴展子過程", "Create IntermediateThrowEvent/BoundaryEvent": "創(chuàng)建中間拋出事件/邊界事件", "Create Pool/Participant": "創(chuàng)建池/參與者", "Parallel Multi Instance": "并行多重事件", "Sequential Multi Instance": "時序多重事件", "DataObjectReference": "數據對象參考", "DataStoreReference": "數據存儲參考", "Loop": "循環(huán)", "Ad-hoc": "即席", "Create {type}": "創(chuàng)建 {type}", "Create Task": "創(chuàng)建任務", "Create StartEvent": "創(chuàng)建開始事件", "Create EndEvent": "創(chuàng)建結束事件", "Create Group": "創(chuàng)建組", "Task": "任務", "Send Task": "發(fā)送任務", "Receive Task": "接收任務", "User Task": "用戶任務", "Manual Task": "手工任務", "Business Rule Task": "業(yè)務規(guī)則任務", "Service Task": "服務任務", "Script Task": "腳本任務", "Call Activity": "調用活動", "Sub Process (collapsed)": "子流程(折疊的)", "Sub Process (expanded)": "子流程(展開的)", "Start Event": "開始事件", "StartEvent": "開始事件", "Intermediate Throw Event": "中間事件", "End Event": "結束事件", "EndEvent": "結束事件", "Create Gateway": "創(chuàng)建網關", "GateWay": "網關", "Create Intermediate/Boundary Event": "創(chuàng)建中間/邊界事件", "Message Start Event": "消息開始事件", "Timer Start Event": "定時開始事件", "Conditional Start Event": "條件開始事件", "Signal Start Event": "信號開始事件", "Error Start Event": "錯誤開始事件", "Escalation Start Event": "升級開始事件", "Compensation Start Event": "補償開始事件", "Message Start Event (non-interrupting)": "消息開始事件(非中斷)", "Timer Start Event (non-interrupting)": "定時開始事件(非中斷)", "Conditional Start Event (non-interrupting)": "條件開始事件(非中斷)", "Signal Start Event (non-interrupting)": "信號開始事件(非中斷)", "Escalation Start Event (non-interrupting)": "升級開始事件(非中斷)", "Message Intermediate Catch Event": "消息中間捕獲事件", "Message Intermediate Throw Event": "消息中間拋出事件", "Timer Intermediate Catch Event": "定時中間捕獲事件", "Escalation Intermediate Throw Event": "升級中間拋出事件", "Conditional Intermediate Catch Event": "條件中間捕獲事件", "Link Intermediate Catch Event": "鏈接中間捕獲事件", "Link Intermediate Throw Event": "鏈接中間拋出事件", "Compensation Intermediate Throw Event": "補償中間拋出事件", "Signal Intermediate Catch Event": "信號中間捕獲事件", "Signal Intermediate Throw Event": "信號中間拋出事件", "Message End Event": "消息結束事件", "Escalation End Event": "定時結束事件", "Error End Event": "錯誤結束事件", "Cancel End Event": "取消結束事件", "Compensation End Event": "補償結束事件", "Signal End Event": "信號結束事件", "Terminate End Event": "終止結束事件", "Message Boundary Event": "消息邊界事件", "Message Boundary Event (non-interrupting)": "消息邊界事件(非中斷)", "Timer Boundary Event": "定時邊界事件", "Timer Boundary Event (non-interrupting)": "定時邊界事件(非中斷)", "Escalation Boundary Event": "升級邊界事件", "Escalation Boundary Event (non-interrupting)": "升級邊界事件(非中斷)", "Conditional Boundary Event": "條件邊界事件", "Conditional Boundary Event (non-interrupting)": "條件邊界事件(非中斷)", "Error Boundary Event": "錯誤邊界事件", "Cancel Boundary Event": "取消邊界事件", "Signal Boundary Event": "信號邊界事件", "Signal Boundary Event (non-interrupting)": "信號邊界事件(非中斷)", "Compensation Boundary Event": "補償邊界事件", "Exclusive Gateway": "互斥網關", "Parallel Gateway": "并行網關", "Inclusive Gateway": "相容網關", "Complex Gateway": "復雜網關", "Event based Gateway": "事件網關", "Transaction": "轉運", "Sub Process": "子流程", "Event Sub Process": "事件子流程", "Collapsed Pool": "折疊池", "Expanded Pool": "展開池", // Errors "no parent for {element} in {parent}": "在{parent}里,{element}沒有父類", "no shape type specified": "沒有指定的形狀類型", "flow elements must be children of pools/participants": "流元素必須是池/參與者的子類", "out of bounds release": "out of bounds release", "more than {count} child lanes": "子道大于{count} ", "element required": "元素不能為空", "diagram not part of bpmn:Definitions": "流程圖不符合bpmn規(guī)范", "no diagram to display": "沒有可展示的流程圖", "no process or collaboration to display": "沒有可展示的流程/協(xié)作", "element {element} referenced by {referenced}#{property} not yet drawn": "由{referenced}#{property}引用的{element}元素仍未繪制", "already rendered {element}": "{element} 已被渲染", "failed to import {element}": "導入{element}失敗", //屬性面板的參數 "Id": "編號", "Name": "名稱", "General": "常規(guī)", "Details": "詳情", "Message Name": "消息名稱", "Message": "消息", "Initiator": "創(chuàng)建者", "Asynchronous Continuations": "持續(xù)異步", "Asynchronous Before": "異步前", "Asynchronous After": "異步后", "Job Configuration": "工作配置", "Exclusive": "排除", "Job Priority": "工作優(yōu)先級", "Retry Time Cycle": "重試時間周期", "Documentation": "文檔", "Element Documentation": "元素文檔", "History Configuration": "歷史配置", "History Time To Live": "歷史的生存時間", "Forms": "表單", "Form Key": "表單key", "Form Fields": "表單字段", "Business Key": "業(yè)務key", "Form Field": "表單字段", "ID": "編號", "Type": "類型", "Label": "名稱", "Default Value": "默認值", "Validation": "校驗", "Add Constraint": "添加約束", "Config": "配置", "Properties": "屬性", "Add Property": "添加屬性", "Value": "值", "Add": "添加", "Values": "值", "Add Value": "添加值", "Listeners": "監(jiān)聽器", "Execution Listener": "執(zhí)行監(jiān)聽", "Event Type": "事件類型", "Listener Type": "監(jiān)聽器類型", "Java Class": "Java類", "Expression": "表達式", "Must provide a value": "必須提供一個值", "Delegate Expression": "代理表達式", "Script": "腳本", "Script Format": "腳本格式", "Script Type": "腳本類型", "Inline Script": "內聯(lián)腳本", "External Script": "外部腳本", "Resource": "資源", "Field Injection": "字段注入", "Extensions": "擴展", "Input/Output": "輸入/輸出", "Input Parameters": "輸入參數", "Output Parameters": "輸出參數", "Parameters": "參數", "Output Parameter": "輸出參數", "Timer Definition Type": "定時器定義類型", "Timer Definition": "定時器定義", "Date": "日期", "Duration": "持續(xù)", "Cycle": "循環(huán)", "Signal": "信號", "Signal Name": "信號名稱", "Escalation": "升級", "Error": "錯誤", "Link Name": "鏈接名稱", "Condition": "條件名稱", "Variable Name": "變量名稱", "Variable Event": "變量事件", "Specify more than one variable change event as a comma separated list.": "多個變量事件以逗號隔開", "Wait for Completion": "等待完成", "Activity Ref": "活動參考", "Version Tag": "版本標簽", "Executable": "可執(zhí)行文件", "External Task Configuration": "擴展任務配置", "Task Priority": "任務優(yōu)先級", "External": "外部", "Connector": "連接器", "Must configure Connector": "必須配置連接器", "Connector Id": "連接器編號", "Implementation": "實現(xiàn)方式", "Field Injections": "字段注入", "Fields": "字段", "Result Variable": "結果變量", "Topic": "主題", "Configure Connector": "配置連接器", "Input Parameter": "輸入參數", "Assignee": "代理人", "Candidate Users": "候選用戶", "Candidate Groups": "候選組", "Due Date": "到期時間", "Follow Up Date": "跟蹤日期", "Priority": "優(yōu)先級", "The follow up date as an EL expression (e.g. ${someDate} or an ISO date (e.g. 2015-06-26T09:54:00)": "跟蹤日期必須符合EL表達式,如: ${someDate} ,或者一個ISO標準日期,如:2015-06-26T09:54:00", "The due date as an EL expression (e.g. ${someDate} or an ISO date (e.g. 2015-06-26T09:54:00)": "跟蹤日期必須符合EL表達式,如: ${someDate} ,或者一個ISO標準日期,如:2015-06-26T09:54:00", "Variables": "變量", "Candidate Starter Configuration": "候選開始配置", "Task Listener": "任務監(jiān)聽器", "Candidate Starter Groups": "候選開始組", "Candidate Starter Users": "候選開始用戶", "Tasklist Configuration": "任務列表配置", "Startable": "啟動", "Specify more than one group as a comma separated list.": "指定多個組,用逗號分隔", "Specify more than one user as a comma separated list.": "指定多個用戶,用逗號分隔", "This maps to the process definition key.": "這會映射為流程定義的鍵", "CallActivity Type": "調用活動類型", "Condition Type": "條件類型", "Create UserTask": "創(chuàng)建用戶任務", "Create CallActivity": "創(chuàng)建調用活動", "Called Element": "調用元素", "Create DataObjectReference": "創(chuàng)建數據對象引用", "Create DataStoreReference": "創(chuàng)建數據存儲引用", "Multi Instance": "多實例", "Loop Cardinality": "實例數量", "Collection": "任務參與人列表", "Element Variable": "元素變量", "Completion Condition": "完成條件", "Open minimap": "打開小地圖", "Close minimap": "關閉小地圖", };
assets/bpmn/translate.js
import translations from "./zh"; export default function customTranslate(template, replacements) { replacements = replacements || {}; // Translate template = translations[template] || template; // Replace return template.replace(/{([^}]+)}/g, function(_, key) { let str = replacements[key]; if ( translations[replacements[key]] !== null && translations[replacements[key]] !== "undefined" ) { // eslint-disable-next-line no-mixed-spaces-and-tabs str = translations[replacements[key]]; // eslint-disable-next-line no-mixed-spaces-and-tabs } return str || "{" + key + "}"; }); }
index.vue中,引入translate.js'
new BpmnModel時,加入漢化組件
// 引入漢化js import translate from '@/assets/bpmn/translate.js' var customTranslateModule = { translate: ['value', translate] } const bpmnModeler = markRaw(new BpmnModeler({ additionalModules: [ customTranslateModule ], }));
頁面效果圖如下:
總結
到此這篇關于vue3集成bpmn.js的文章就介紹到這了,更多相關vue3集成bpmn.js內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
解決VUE 在IE下出現(xiàn)ReferenceError: Promise未定義的問題
這篇文章主要介紹了解決VUE 在IE下出現(xiàn)ReferenceError: Promise未定義的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11Vue3+TypeScript報錯:無法找到模塊xx的聲明文件問題
這篇文章主要介紹了Vue3+TypeScript報錯:無法找到模塊xx的聲明文件問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11vue項目預覽excel表格功能(file-viewer插件)
這篇文章主要介紹了vue項目預覽excel表格功能(file-viewer插件),本文分步驟結合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-10-10vue3通過ref獲取子組件defineExpose的數據和方法
defineExpose是Vue3中新增的選項,用于向父組件暴露子組件內部的屬性和方法,通過defineExpose,子組件可以主動控制哪些屬性和方法可以被父組件訪問,本文主要介紹了vue3通過ref獲取子組件defineExpose的數據和方法,需要的朋友可以參考下2023-10-10Vue3+Vite實現(xiàn)一個Markdown編輯器組件
在現(xiàn)代前端開發(fā)中,Markdown 編輯器廣泛應用于博客,文檔,Wiki,代碼注釋等場景,本文將使用 Vue 3 構建一個簡單的 Markdown 編輯器組件,感興趣的小伙伴可以了解下2025-04-04