Vue.js 异步函数:显示工作流程视图
这段代码是一个 Vue.js 的异步函数,用于显示工作流程的视图。函数首先将所有表单数据重置为空数组,然后注册 BPMN 模块。接下来,函数根据传入的模块 ID 参数判断工作流程是否需要进行编辑。如果需要编辑,则会获取模块信息,将模块的 JSON 数据解析为子形状对象,并将每个子形状对象中的表格数据存储到 Vue.js 的 store 中。如果模块信息获取失败,则会提示用户获取失败并退出函数。如果模块 ID 参数为空,则会创建一个新的模块并将模块 ID 存储为函数的模块 ID 参数。最后,函数设置对话框的标题,并打开一个包含 BpmnModeler 组件的对话框以显示工作流程视图。函数末尾添加了一个兼容样式类,并将主加载状态设置为 false。
async activitiView(modulesId = "") {
this.$store.commit("SET_ALL_FORM", []);
// this.mainLoading = true;
registerBpmnModule();
try {
if (modulesId) {
this.bpmnIsEdit = true;
this.bpmnIsImport = false;
let res = await getInfo(modulesId);
if (res.data.success) {
this.bpmnJsonData = res.data.data;
let json = res.data.data.json;
let childShapes = JSON.parse(json).childShapes;
childShapes.forEach((o) => {
if (o.properties?.tableData?.length > 0) {
o.properties.tableData.forEach((it) => {
this.$store.dispatch("addAllForm", {obj: it, id: ""});
});
}
if (o.childShapes?.length > 0) {
o.childShapes.forEach((x) => {
if (x.properties?.tableData?.length > 0) {
x.properties.tableData.forEach((it) => {
this.$store.dispatch("addAllForm", {obj: it, id: ""});
});
}
});
}
});
} else {
this.$notify({
title: this.$t("deletePrompt.promptTitle"),
message: this.$t("workFlow.WFDesign.hintGetFailed"),
type: "warning",
});
// this.mainLoading = false;
return false;
}
} else {
let res = await newModel();
modulesId = res.data.data;
this.bpmnIsEdit = false;
}
this.modulesId = modulesId;
this.dialog.title = this.bpmnIsEdit
? this.$t("workFlow.WFDesign.titleEditFlow")
: this.$t("workFlow.WFDesign.titleAddFlow");
this.openDialog({
title: this.dialog.title,
component: "BpmnModeler",
width: "80%",
fullscreen: true,
});
} catch (error) {
}
//添加兼容样式类
document.body.className = document.body.className + " original";
// this.mainLoading = false;
}
该代码使用了 async/await 语法来处理异步操作,并利用了 Vue.js 的 store 来管理数据。代码还使用了 $t 方法来获取国际化文本,以及 $notify 方法来显示提示信息。
需要注意的是,代码中使用了 // this.mainLoading = true; 和 // this.mainLoading = false; 注释掉的代码,这表明代码可能使用了加载状态变量 mainLoading 来指示加载进度。
总体来说,这段代码是一个使用 Vue.js 开发工作流程视图的典型示例,它展示了如何利用 Vue.js 的各种特性来实现复杂的应用程序功能。
原文地址: https://www.cveoy.top/t/topic/orGR 著作权归作者所有。请勿转载和采集!