<template>
  <div>
    <h2 style="text-align:center;">加载中...</h2>
  </div>
</template>

<script>
import { setRem } from "@/libs/functionRem";
import { isLogin } from "@/api/login";

export default {
  name: "verifyToken",
  created() {
    window.callJsFunction = this.callJsFunction
    setRem();
    isLogin().then(response => {
      if (response.data.state === 1) {
        var data = response.data.data;
        if (data.isLogin) {
          //登录
          var admin = data.admin;
          var user = data.user;
          var org = data.org;
          var subscibe = data.subscibe;
          var config_list = data.config_list;
          var dict_config_list = data.dict_config_list;
          var token = data.token;

          var template_info = data.template_info;
          var filed_list = data.filed_list;
          sessionStorage.setItem("org_id",org.id);
          sessionStorage.setItem("admin_user_id",org.creator);
          // sessionStorage.setItem("token",token);
          localStorage.setItem("token",token)
          this.$store.dispatch("InitUserInfo", {
            admin: admin,
            user: user,
            org: org,
            subscibe: subscibe,
            template_info: template_info,
            filed_list: filed_list
          });
          this.$store.dispatch("SetConfigList", config_list);
          this.$store.dispatch("SetDictConfigList", dict_config_list);
         this.$router.replace("/homeIndex");
        } else {
          //未登录
          this.$router.replace("/login");
        }
      }else{
        this.$toast({
          message: "数据加载错误，请重新登录"
        });
        this.$router.replace("/login");
      }
    });
  },methods:{
    callJsFunction(cookieStr) {
      // console.log(cookieStr)
    }
  },
};
</script>

<style scoped></style>
