<template>
  <el-header>
    <Menu></Menu>
  </el-header>
  <el-container>
    <router-view/>
  </el-container>
</template>

<script lang="ts">
import { defineComponent, onMounted } from 'vue';
import Menu from '@/components/Menu.vue';

import { getVariableFromQueryString } from '@/utils/qs';
import { WorkspaceDispatcher, UserDispatcher, TokenDispatcher } from './store/dispatchers';
import { useStore } from './store';

export default defineComponent({
  components: { Menu },
  setup() {
    const store = useStore();

    // 调试输出vuex信息
    if (document.location.host !== 'devcloud.seec.seecoder.cn') {
      console.log(store.state);
    }

    const token = getVariableFromQueryString('id_token');
    if (token) {
      TokenDispatcher.updateToken(token);
    }

    UserDispatcher.updateUserInfo();
    WorkspaceDispatcher.refreshProjectList();

    onMounted(() => {
      window.onbeforeunload = () => {
        localStorage.setItem('workspace', JSON.stringify(store.state.workspace));
      };
    });
  },
});
</script>

<style lang="scss">
* {
  margin: 0;
  padding: 0;
}
html, body {
  width: 100%;
}

div[role=tooltip] {
  max-width: 30vw;
}

#app {
  font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB",
  "Microsoft YaHei","微软雅黑",Arial,sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>
