mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-04-10 09:43:16 +08:00
fix(workflow): 修复切换任务时接口请求未取消的问题
在审批面板中切换任务时,之前的异步请求可能仍在进行,导致数据错乱。现在通过维护请求取消函数列表,在发起新请求前取消所有未完成的请求。
This commit is contained in:
@@ -87,18 +87,27 @@ const currentFlowInfo = ref<FlowInfoResponse>();
|
|||||||
*/
|
*/
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
|
||||||
|
// 存放所有请求取消函数
|
||||||
|
const abortList: (() => void)[] = [];
|
||||||
async function handleLoadInfo(task: TaskInfo | undefined) {
|
async function handleLoadInfo(task: TaskInfo | undefined) {
|
||||||
if (!task) {
|
if (!task) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
// 取消之前的请求 & 清空数组
|
||||||
|
abortList.forEach((abort) => abort());
|
||||||
|
abortList.length = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不为审批不需要调用`getTaskByTaskId`接口
|
* 不为审批不需要调用`getTaskByTaskId`接口
|
||||||
*/
|
*/
|
||||||
if (props.type !== 'approve') {
|
if (props.type !== 'approve') {
|
||||||
const flowResp = await flowInfo(task.businessId);
|
const flowRespApi = flowInfo(task.businessId);
|
||||||
|
// 请求取消
|
||||||
|
abortList.push(flowRespApi.abort);
|
||||||
|
// 获取数据
|
||||||
|
const flowResp = await flowRespApi;
|
||||||
currentFlowInfo.value = flowResp;
|
currentFlowInfo.value = flowResp;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -107,10 +116,12 @@ async function handleLoadInfo(task: TaskInfo | undefined) {
|
|||||||
* getTaskByTaskId主要为了获取按钮权限 目前没有其他功能
|
* getTaskByTaskId主要为了获取按钮权限 目前没有其他功能
|
||||||
* 行数据(即props.task)获取的是没有按钮权限的
|
* 行数据(即props.task)获取的是没有按钮权限的
|
||||||
*/
|
*/
|
||||||
const [flowResp, taskResp] = await Promise.all([
|
const flowInfoApi = flowInfo(task.businessId);
|
||||||
flowInfo(task.businessId),
|
const taskRespApi = getTaskByTaskId(task.id);
|
||||||
getTaskByTaskId(task.id),
|
// 请求取消
|
||||||
]);
|
abortList.push(flowInfoApi.abort, taskRespApi.abort);
|
||||||
|
|
||||||
|
const [flowResp, taskResp] = await Promise.all([flowInfoApi, taskRespApi]);
|
||||||
|
|
||||||
currentFlowInfo.value = flowResp;
|
currentFlowInfo.value = flowResp;
|
||||||
onlyForBtnPermissionTask.value = taskResp;
|
onlyForBtnPermissionTask.value = taskResp;
|
||||||
|
|||||||
Reference in New Issue
Block a user