<template>
<div class="taskCenter">
<template v-if="batchIframeUrl">
<hi-taskcenter
ref="hiTask"
@openfunc="openfunc"
@openmonitor="openmonitorFn"
:batchProcessFn="batchProcessFn"
:batchProcessFunc="batchProcessFuncFn"
:syncBatch="syncBatch"
style="
background-color: #fff;
padding-top: 10px;
box-sizing: border-box;
"
>
</hi-taskcenter>
</template>
<template v-else>
<hi-taskcenter
ref="hiTask"
@openfunc="openfunc"
@openmonitor="openmonitorFn"
:batchProcessFunc="batchProcessFuncFn"
:syncBatch="syncBatch"
style="
background-color: #fff;
padding-top: 10px;
box-sizing: border-box;
"
>
</hi-taskcenter>
</template>
</div>
</template>
<script>
import "hi-taskcenter/hi-taskcenter.css";
import HiTaskcenter from "hi-taskcenter";
import { getToken } from "@main/utils/auth";
export default {
components: {
HiTaskcenter,
},
data() {
return {
syncBatch: HIVUI_SETTING.syncBatch,
batchWindow: null,
batchTitle: "",
batchIframeUrl: "",
batchParams: {
method: "",
batchData: [],
},
};
},
computed: {
batchTitleDialog() {
return "任务批处理" + this.batchTitle;
},
},
mounted() {
let me = this;
let electron = top.window.electron;
if (top.window.customSysCofig.batchIframeUrl && electron) {
me.batchIframeUrl = top.window.customSysCofig.batchIframeUrl;
}
document.addEventListener("iframeActiving", function (e) {
if (top.window.__refreshTaskcenter) {
top.window.__refreshTaskcenter = false;
me.$refs.hiTask.taskschemeItemClick({
value: "untreated",
label: me.$t("hivuiMain_taskcenter_untreated"),
sel: true,
});
}
});
window.addEventListener("message", this.handleIframeMsg);
},
beforeDestroy() {
window.removeEventListener("message", this.handleIframeMsg);
if (this.batchWindow && !this.batchWindow.closed) {
this.batchWindow.close();
}
},
methods: {
openfunc(__data1, __data2, __data3) {
if (__data2.furl) {
if (
top.window.customSysCofig.taskcenterCustomeropen &&
typeof top.window.customSysCofig.taskcenterCustomeropen == "function"
) {
top.window.customSysCofig.taskcenterCustomeropen.call(this, __data2);
} else {
top.window.open(__data2.furl);
}
} else {
top.window.SysPage.newPage(
__data2.fpdisplayname,
location.origin +
(window._global ? "" : window.HIVUI_SETTING.serverName) +
"/" +
__data2.fmodelpath,
{
fmodelpath: __data2.fmodelpath,
version: __data2.fversion,
ftaskguid: __data2.ftaskguid,
flowstate: __data2.flowstate,
forderguid: __data2.forderguid,
fnumber: __data2.fordernumber,
fbzid: __data2.fbzid,
pn: window.HIVUI_SETTING.projectName,
}
);
}
},
openmonitorFn(_this, __data2) {
if (__data2 && __data2.furl) {
if (
top.window.customSysCofig.taskcenterCustomeropenmonitor &&
typeof top.window.customSysCofig.taskcenterCustomeropenmonitor ==
"function"
) {
top.window.customSysCofig.taskcenterCustomeropenmonitor.call(
this,
_this,
__data2
);
}
}
},
batchProcessFuncFn(config) {
if (config.row && config.row.furl) {
if (
top.window.customSysCofig.taskcenterbatchProcess &&
typeof top.window.customSysCofig.taskcenterbatchProcess == "function"
) {
return top.window.customSysCofig.taskcenterbatchProcess.call(
this,
this.$refs.hiTask,
config
);
}
} else {
return this.$refs.hiTask.processFlow(config);
}
},
// 接收子页面消息
handleIframeMsg(e) {
console.log("接收子页面回调", e);
const data = e.data;
// 子页面加载完成握手信号,收到后再下发业务数据
if (data.type === "childReady") {
this.sendDataToBatchWindow();
return;
}
if (data.type === "batchFinish") {
this.$refs.hiTask.taskschemeItemClick({
value: "untreated",
label: this.$t("hivuiMain_taskcenter_untreated"),
sel: true,
});
}
},
// 批处理入口
batchProcessFn(method, batchData) {
console.log(method, batchData);
this.batchTitle = method == "flowOut" ? "(流转)" : "(回退)";
this.batchParams = {
method,
batchData,
};
if (this.batchWindow && !this.batchWindow.closed) {
this.batchWindow.focus();
// 窗口已打开,直接重新发数据
this.sendDataToBatchWindow();
} else {
// 新开窗口,等待子页面主动发ready再传数据
this.batchWindow = window.open(
this.batchIframeUrl,
"taskBatchProcess",
"width=900,height=600,scrollbars=yes"
);
}
},
// 向批处理窗口发送业务数据
sendDataToBatchWindow() {
if (!this.batchWindow || this.batchWindow.closed) return;
this.batchWindow.postMessage(
{
type: "refreshTable",
serverUrl: window.HIVUI_SETTING.serverUrl,
pn: window.HIVUI_SETTING.projectName,
method: this.batchParams.method,
list: this.batchParams.batchData,
token: getToken(),
},
"*"
);
},
},
};
</script>
<style scoped>
.taskCenter {
height: 100%;
}
</style>