fetch用法以及实现免登陆跳转到子系统

2022-08-17  本文已影响0人  jesse28

fetch用法参考链接:https://blog.csdn.net/dyw3390199/article/details/111397197
1.第一步主系统的一级菜单会存放在localstorage,这边序列化一下。

JSON.parse(localStorage.getItem("microList"))

2.跳转到主系统

  // 跳转到主系统
    handleJump(item) {
      console.log("点击主系统", item);
      fetch(`${window.webConfig.ipJump}/threeParty/getAccountToken`, {
        method: "post",
        headers: {
          "Content-Type": "application/json;charset=UTF-8",
        },
        body: JSON.stringify({
          account: this.$store.state.user.login.loginName,
          phone: null,
          idCard: null,
          externalSystemId: null,
          columnMap: null,
        }),
      })
        .then((res) => res.json())
        .then((res) => {
          if (res.code == 200) {
            let newToken = JSON.parse(res.data).data;
            // 获取到token之后然后拼接跳转
            switch (item.name) {
              case "zhihuidiaodu":
                window.location.href = `${window.webConfig.ipLoginOut}/case/newScreen/index.html#/`;
                break;
              default:
                window.location.href = `${window.webConfig.ipLoginOut}/case/#login?token=${newToken}&code=${item.name}`;
            }
          }
        });
    },

讲解代码:
通过这个接口获取到data也就是所谓的token,然后拿到这个token和子系统的code去实现挑战。

上一篇 下一篇

猜你喜欢

热点阅读