<!--
 * @Author: zhangyu
 * @Date: 2019-11-05 15:36:21
 * @Info: 
 * @LastEditTime: 2019-11-14 15:46:27
 -->
<template>
    <div id="screenBox">
        <div class="mian-icon" v-show="$route.name == 'splitScreen'">
            <div class="main-content">
                <img src="@/assets/image/uncultivated.svg" />
                <h2>功能设计中。。。</h2>
            </div>
        </div>
        <router-view v-show="$route.name != 'splitScreen'" class="screen-router"></router-view>
    </div>
</template>

<script>
import { mapGetters } from "vuex";
import lStorage from "@/utils/localStorage";

export default {
    data() {
        return {};
    },
    mounted() {
        // 页面初始化
        this.init();
        // 监听localStorage的数据的变化
        window.addEventListener("storage", (event) => {
            if (event.key == "_sagacloud_admin_store_screen_data") {
                let data;
                try {
                    data = JSON.parse(event.newValue);
                } catch (error) {
                    console.error(error);
                    data = event.newValue;
                }
                this.handleChangeRouter(data);
            }
        });
    },
    destroyed() {
        window.removeEventListener("storage", (event) => {});
        lStorage.remove("screen_data");
    },
    computed: {
        ...mapGetters("layout", ["userInfo", "projectId", "projects", "userId"]),
    },
    methods: {
        init() {
            const screenData = lStorage.get("screen_data");
            screenData && this.handleChangeRouter(screenData);
        },
        handleChangeRouter(data) {
            console.log(data);
            if (data.path && data.path == "/ledger/spacelist") {
                //业务空间台账
                this.$router.push({
                    path: "/splitScreen/spaceledger",
                    query: data.data,
                });
            } else if (data.path && data.path == "/point/report") {
                //系统集成成果管理
                this.$router.push({
                    path: "/splitScreen/integrateresults",
                    query: data.data,
                });
            } else if (data.path && data.path == "/ledger/facility") {
                //设备位置图
                this.$router.push({
                    path: "/splitScreen/equipledger",
                    query: data.data,
                });
            } else {
                this.$router.push({
                    path: "/splitScreen",
                });
            }
        },
    },
};
</script>

<style lang="scss" scoped>
#screenBox {
    width: 100%;
    height: 100%;
    .mian-icon {
        width: 100%;
        height: 100%;
        text-align: center;
        position: relative;
        .main-content {
            position: absolute;
            top: 25%;
            left: 50%;
            transform: translate(-50%, 0);
            h2 {
                text-align: center;
                margin-top: 30px;
            }
        }
    }
    .screen-router {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        padding: 10px;
        width: 100%;
        height: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }
}
</style>