<template>
  <div class="app-wrapper">
    <map-create ref="mapCreate" :line-code="lineCode" @refresh="refresh1" />
    <div class="examList" :style="{width: widthLeft+'px'}">
      <demon-list ref="demonList" @createMap="createMap" />
    </div>
    <drap-left :width-left="widthLeft" @drapWidth="drapWidth" />
    <transition>
      <router-view />
    </transition>
    <context-menu />
  </div>
</template>

<script>
import demonList from './demonList';
import drapLeft from '@/views/components/drapLeft/index';
import { launchFullscreen } from '@/utils/screen';
import localStore from 'storejs';
import { getSessionStorage, setSessionStorage } from '@/utils/auth';
import MapCreate from './mapmanage/create';
import ContextMenu from './contextMenu';

export default {
    name: 'DesignPlatform',
    components: {
        demonList,
        drapLeft,
        MapCreate,
        ContextMenu
    },
    data() {
        return {
            widthLeft: Number(localStore.get('LeftWidth')) || 450,
            lineCode: ''
        };
    },
    computed: {
        width() {
            return this.$store.state.app.width;
        }
    },
    watch: {
        widthLeft(val) {
            this.setMapResize(val);
        },
        '$store.state.app.windowSizeCount': function() {
            this.resize();
        }
    },
    created() {
        this.resize();
    },
    mounted() {
        const againEnter = getSessionStorage('againEnter') || null;
        if (!againEnter) {
            launchFullscreen();
            setSessionStorage('againEnter', true);
        }
        this.widthLeft = Number(localStore.get('LeftWidth'));
    },
    methods: {
        refresh() {
            this.$refs && this.$refs.demonList && this.$refs.demonList.loadInitData();
        },
        refresh1() {
            this.$refs.demonList.loadInitData();
        },
        createMap() {
            this.$refs.mapCreate.show();
        },
        drapWidth(width) {
            this.widthLeft = Number(width);
        },
        resize() {
            this.widthLeft = Number(localStore.get('LeftWidth')) || this.widthLeft;
            const width = this.$store.state.app.width - this.widthLeft;
            const height = this.$store.state.app.height - 90;
            this.$store.dispatch('config/resize', { width: width, height: height });
        },
        setMapResize(LeftWidth) {
            const width = this.$store.state.app.width - LeftWidth;
            const height = this.$store.state.app.height - 90;
            this.$store.dispatch('config/resize', { width: width, height: height });
        }
    }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    @import "src/styles/mixin.scss";

    .app-wrapper {
        @include clearfix;
        position: relative;
        height: 100%;
        width: 100%;
        overflow: hidden;
    }

    .examList {
        float: left;
        height: 100%;
    }
</style>
