<template>
  <el-container class="app-container" direction="vertical" v-if="loaded">
    <vue-progress-bar/>
    <Header/>

    <!-- 多页模式 -->
    <el-container v-if="!$config.isSinglePage">
      <Aside/>
      <Container/>
    </el-container>

    <!-- 单页模式 -->
    <component v-if="$config.isSinglePage" :is="$config.embedHome"/>

    <el-dialog append-to-body title="系统提示" :visible.sync="$store.state.base.loginTimeout" width="400px" :show-close="false">
      <LoginRe v-if="$store.state.base.loginTimeout"/>
    </el-dialog>
    <el-dialog close-on-press-escape append-to-body title="修改密码" :visible.sync="$store.state.base.loginChangePwd" width="360px">
      <ChangePw @cancel="$store.state.base.loginChangePwd=false"/>
    </el-dialog>
  </el-container>
</template>

<script>
  import {Loading} from "element-ui";
  import ChangePw from "../module/sysm/ChangePw";
  import LoginRe from "./LoginRe";
  import Container from "./layout/Container";
  import Aside from "./layout/Aside";
  import Header from "./layout/Header";
  import CacheService from "../service/module/CacheService";

  export default {
    components: {Container, Aside, Header, ChangePw, LoginRe},
    data() {
      return {
        changepwd: false,
        loaded: false
      };
    },
    async mounted() {
      this.loaded = false;
      let loading = Loading.service({
        lock: true,
        text: "系统初始化...",
        spinner: "el-icon-loading",
        background: "rgba(255, 255, 255, 0.7)"
      });
      try {

        let data = await this.$store.dispatch("base/getLoginInfo");
        if (data.respCode !== this.$config.respCode.success) {
          await this.$router.replace("/login");
          return;
        }
        await CacheService.repairWith(data['ttocpic'], data['tversion']);
        await CacheService.repairWith(data['ctocpic'], data['cversion']);
        if (this.$config.init) {
          await this.$config.init(this);
          delete this.$config["init"];
        }
        setInterval(() => {
          //需要定时执行的代码
          this.$store.dispatch("base/getLoginInfo").then(
              data => {
                if (data.respCode !== this.$config.respCode.success) {
                  this.$router.replace("/login");
                }
              }
          );

        }, 60 * 1000)
      } catch (e) {
        console.error(e);
        await this.$router.replace("/login");
      } finally {
        this.loaded = true;
        loading.close();
      }
    },
    methods: {

    }
  };
</script>
