异步的思考

直接上代码 两个接口 等一个接口掉完调用另一个的写法

 const [pipelineInstance, { wrapRequset: requestPipelineInstance }] =
    useLoading<typeof getPipelineInst>(getPipelineInst);// 接口

const changedata = res => {
    const bizIdData = res?.nodeInsts?.find((item) => {
      return item?.nodeType === PipelineNodeType?.PUBLISH_CHECK;
    });
    const simulateId = bizIdData?.bizId
    setsimulateId(simulateId)
    res?.nodeInsts.map(item => {
      if (item?.nodeType === "PUBLISH_CHECK") {
        setuseLoading(true)
        fetchAPI(
          API_dpchangeguardian_whiteListV1Rest_postInsertWhiteList,
        ).request({}, {
          conditions: {
            whiteListObject: {
              like: `%${simulateId}%`
            }
          },
          orderBys: [{
            field: 'id',
            asc: false
          }]
        }).then?.((data) => {
          item?.detailResult?.forms[0].rows.forEach(items => {
            const result = data?.find(item => item?.ruleInstanceId == items?.cells?.[2]?.operations?.[0]?.operationValue?.ruleInstanceId);
            if (result) {
              items.cells[2].operations[0].operationValue.status = result.status;
              items.cells[2].operations[0].operationValue.bmpsApproveUrl = result.bmpsApproveUrl;
            }
          });
          setuseLoading(false)
        })
      }
    })
  }

useEffect(() => {
    if (visible) {
      /** 查询任务最新的流程实例 */
      requestPipelineInstance(submittedObject, isproduct).then(data => {
        changedata(data)// 更新publine状态
      });
      requestChangeImpactInfo(submittedObject);
    }
  }, [visible]);

你可能感兴趣的:(javascript)