<script setup lang="ts">
    import { onMounted, ref, nextTick, getCurrentInstance, reactive, onBeforeUnmount } from 'vue';
    import utils from "../util/common";
    import { useRoute } from "vue-router";
    import router from '../router/index'
   // import { removeToken } from "../util/tokenUtil";
    import { useUserInfo } from '@/stores/userInfo';
    const home = ref("");
    const avatar = ref("");
    const userName = ref("未知用户");
    const route = useRoute();////必须写在外面
    const gotoHome = () => {
        ///根据用户判断,如果是教师则返回后台
       
        let path = route.path;
        console.log(path);
        if (path.indexOf("/CourseEditor") >= 0 || path.indexOf("/CourseMng") >= 0) {
            router.push({
                path: "/CourseMng",
            });
            return;
        }
        router.push({
            path: "/TaskMng",
        });
    }
    const logOut = () => {
        const userInfo = useUserInfo();
        userInfo.removeToken();
        router.push({
            path: "/",
        });
    }
    onMounted(() => {
        const userInfo = useUserInfo();
        userName.value = userInfo.nickName;
      
        if (userInfo.userType != 1) {
            router.push({
                path: "/",
            });
        }
    });
</script>
<template>
    <el-container class="el-wrapper">
        <el-header class="header-title-wrap">

            <div class="header-title">排水管网运维养护虚拟仿真教学平台</div>
            <div class="header-opts">

                <el-popover trigger="click">
                    <template #reference>
                        <div class="user-wrap">
                            <el-avatar>
                                <el-icon :size="24"><Avatar /></el-icon>
                            </el-avatar>
                            <span class="user-name">{{userName}}</span>
                        </div>
                    </template>
                    <el-col>
                        <div @click="logOut" style="cursor:pointer;">
                            <a class="drawdown-item">
                                <el-icon style="vertical-align: middle;margin:-3px 0.5rem 0 0; height:1.2rem; line-height:1rem;">
                                    <SwitchButton />
                                </el-icon>
                                <span>退出登录</span>
                            </a>
                        </div>
                    </el-col>
                </el-popover>
                <a class="back-btn" @click="gotoHome" v-if="route.path.toLowerCase().indexOf('taskmng')<1" style="" title="返回"></a>
            </div>
        </el-header>
        <el-container class="el-main">
            <router-view />
        </el-container>
        </el-container>
</template>
<style scoped>
    .el-wrapper {
        display: grid;
        height: 100%;
        width: 100%;
        overflow: hidden;
        grid-template-rows: 60px 1fr;
    }

    .el-container {
        width: 100%;
        padding: 0;
        overflow: hidden;
    }

    .header-title-wrap {
        width: 100%;
        color: #fff;
        background-color: var(--el-color-primary);
        display: flex;
        justify-content: space-between;
    }

    .el-aside {
        transition: width 0.5s ease;
    }

    .container-main {
        transition: width 0.5s ease;
    }

    .el-menu {
        transition: width 0.5s ease;
    }

    .el-main {
        height: calc(100vh - 60px);
        /* background:#ccc;*/
        display: flex;
        background-color: rgb(246,246,246);
    }

    .header-title {
        background-color: var(--el-color-primary);
        font-weight: bold;
        font-size: 1.5rem;
        line-height: 60px;
        justify-self: flex-start;
        width: 30rem;
    }

    .header-opts {
        margin-right: 1rem;
        display: flex;
        align-items: center;
    }

        .header-opts > .el-avatar {
            margin-right: 1rem;
            cursor: pointer;
        }

    .user-wrap {
        display: flex;
        justify-self: flex-start;
        vertical-align: middle;
        height: 100%;
        align-items: center;
        cursor: pointer;
    }

    .user-name {
        margin-left: 0.5rem;
    }

    .log-out {
        justify-self: flex-end;
        line-height: 60px;
        cursor: pointer;
    }

    .header-bread {
        height: 3rem;
        display: flex;
        align-items: center;
        color: var(--el-text-color-regular);
    }

    .el-breadcrumb {
        line-height: 3rem;
    }

    .avatar {
    }

    .el-avatar {
        background: none;
    }
    .back-btn {
        margin-right: 0rem;
        margin-left:2rem;
        display: flex;
        align-self: center;
        background-image:url(@/assets/techer/task-back.png);
        height:2rem;
        width:2rem;
        background-size:2rem;
        background-repeat:no-repeat;
        background-position:center;
    }
    .drawdown-item {
        display: block;
        height: 2rem;
        line-height: 2rem;
        font-size: 1rem;
        text-decoration: none;
        color: var(--el-color-primary);
    }


    .container-main {
    }

    .el-aside {
        height: 100%;
        border-right: 1px solid var(--el-border-color);
    }

    .el-menu {
        height: calc(100vh - 60px);
        border-right: none !important;
    }

    .header-bread {
        height: 3rem;
    }

    .el-breadcrumb {
        line-height: 3rem;
    }

    .bread {
    }

    .el-main-inner {
        overflow: hidden;
        box-sizing: border-box;
    }

</style>