<template>
    <div class="header_right">
        <div>
            <el-button @click="goBack()">返回人工智能专栏</el-button>
        </div>
        <div v-if="isLogin" class="loginAdmin">
            <div v-if="admin">
                <img src="" alt="">
                <!-- <span>管理后台</span> -->
                <router-link to="" @click="adminClick()"><span>管理后台</span></router-link>
            </div>
            <div>
                <img src="" alt="">
                <span>{{ userName }}</span>
            </div>
        </div>
        <div v-else>
            <!-- <el-button @click="studentLogin()">学生登录</el-button> -->
            <el-button @click="linkLogin()">教师登录</el-button>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted, watchEffect } from "vue"
import { userCurrentRole,userInfoStore } from '../../stores/counter'

const user = userInfoStore()
const isLogin = ref(false)
const admin = ref(false)
const userName = ref('')
const CurrentRole = userCurrentRole()

const linkLogin = () => {
    top.location.href = `http://szedutest.changyan.cn/thirdauth/oauth2/authorize?service=initService&scope=all&response_type=code&app_id=94c720f0634b4bad890dc9223de01166&redirect_uri=https://cloud.cocorobo.cn/testapi`
}

const adminClick = () => {
    console.log('admin')
    // U.MD.D.I.openInApplication('dataBoardSZCity') //市级数据看板
    // U.MD.D.I.openInApplication('dataBoardSZArea') //区级数据看板
    console.log(CurrentRole.currentRole)
    if(CurrentRole.currentRole === 'userAdministrator'){
        top.U.MD.D.I.openInApplication('dataBoardSZCity')
    }else if(CurrentRole.currentRole === 'securityAuditor'){
        top.U.MD.D.I.openInApplication('dataBoardSZArea')
    }else{
        top.U.MD.D.I.openApplication('Grade') 
    }
}

const goBack=()=>{
    top.location.href = "https://zy.szedu.cn/ai/"
}

watchEffect(() => {
    // console.log(user, 2222222222)
    if (JSON.stringify(user.user) != "{}") {
        isLogin.value = true
        userName.value = user.user.username
        if (CurrentRole.currentRole == "edupersonnel" || CurrentRole.currentRole == "areaAdministrator" || CurrentRole.currentRole == "userAdministrator" || CurrentRole.currentRole == "securityAuditor" || CurrentRole.currentRole == "schoolAdministrator" || CurrentRole.currentRole == "schoolSecurityAuditor" || CurrentRole.currentRole == "teacher" || user.user.type != 2) {
            admin.value = true
        }
    }
})
</script>
<style scoped lang="scss">
.header_right {
    display: flex;

    .loginAdmin {
        display: flex;
    }

    div {
        line-height: 60px;
        padding-right: 20px;

        img {

            vertical-align: middle;
        }

        span {
            padding: 10px;
            line-height: 60px;

        }

        .el-button {

            background: rgba(54, 129, 252, 1);
            color: #fff;
        }
    }
}
</style>