<template>
  <div>
    <div>页面跳转中......</div>
  </div>
</template>

<script>
import local from "@/utils/local";
import { mapMutations } from "vuex";
import { createMenus } from "@/router";
import { login } from "@/services/user";

export default {
  data() {
    return {};
  },
  created() {
    if (this.$route.query.loginName) {
      const userName = this.$route.query.loginName;
      const password = "xhxADMIN8@a";
      login(userName, password).then((res) => {
        const loginRes = res.data;
        console.log(loginRes);
        if (loginRes.code == 1) {
          const { token } = loginRes.data;
          local.setLocal("token", token);

          let userInfo = {
            id: loginRes.data.id,
            userType: loginRes.data.userType,
            currUserName: loginRes.data.currUserName,
          };
          this.getToken(token, userInfo, loginRes.data);
          this.$message.success(loginRes.msg, 3);
        } else {
          this.error = loginRes.msg;
        }
      });
    }
  },
  methods: {
    ...mapMutations("site", [
      "SET_userInfo",
      "SET_token",
      "SET_SITE_ID",
      "SET_siteName",
      "SET_sysName",
      "SET_sysLogo",
      "SET_path",
    ]),
    // 获取token
    getToken(token, userInfo, data) {
      // let { userInfo, siteid, siteName, sysName, sysLogo, path } =
      //   this.$route.query;
      if (token) {
        this.SET_userInfo(userInfo);
        this.SET_token(token);
        console.log(data);

        // data.siteid ? this.SET_SITE_ID(data.siteid) : "";
        // data.siteName ? this.SET_siteName(data.siteName) : "";
        // this.SET_sysName(data.sysName);
        // this.SET_sysLogo(data.sysLogo);
        // this.SET_path(data.path);
        // local.setLocal("siteId", data.siteid);
        // local.setLocal("siteName", data.siteName);
        // 动态菜单
        createMenus();
        this.$router.push("/website");
      } else {
        this.$message.warning("跳转失败,请重新登录");
        setTimeout(() => {
          location.href = process.env.VUE_APP_API_portal_URL;
        }, 2000);
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
