promise 多层嵌套顺序执行

109 阅读1分钟
    // 单点登陆跳转
    async singlePoint(e) {
      // 获取用户信息
      // 通过用户信息id 获取 租户信息
      // 通过租户信息获取新token
      new Promise(async (resolve) => {
        resolve(await getInfo());
      })
        .then((resUser) => {
          new Promise(async (resolve) => {
            resolve(await getTenant(resUser.user.userId));
          })
            .then(async (resTenant) => {
              new Promise(async (resolve) => {
                resolve(
                  await getNewAppToken({
                    transactionUserId: resTenant.data.transactionUserId,
                    orderId: e.orderId,
                  })
                );
              }).then((res) => {
                let data = res.data;
                if (data && e.url.length) {
                  const link = e.url[0].url;
                  console.log("link", e.url[0].url);
                  console.log("token", data);
                  window.open(`${link}?token=${data}`, '_blank');
                  // window.location.href = `${link}?token=${data}`;
                } else {
                  this.$message({
                    message: "此应用尚未配置试用地址",
                    type: "warning",
                  });
                }
              });
            })
            .catch(() => {
              this.$message({
                message: "获取租户信息失败请稍后重试",
                type: "warning",
              });
            });
        })
        .catch(() => {
          this.$message({
            message: "获取用户信息失败请稍后重试",
            type: "warning",
          });
        });
    },