headerRight.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="header_right">
  3. <div>
  4. <el-button @click="goBack()">返回深教AI首页</el-button>
  5. </div>
  6. <div v-if="isLogin" class="loginAdmin">
  7. <div v-if="admin">
  8. <img src="" alt="">
  9. <!-- <span>管理后台</span> -->
  10. <router-link to="" @click="adminClick()"><span>管理后台</span></router-link>
  11. </div>
  12. <div style="min-width: 100px;">
  13. <img src="" alt="">
  14. <span style="cursor: pointer;" class="dropdownMenu" @click="userInfoShow = true">{{ userName }}</span>
  15. <ul v-if="userInfoShow" class="user_info">
  16. <li @click="userInfoOpen()">个人资料</li>
  17. <li @click="logout()">退出</li>
  18. </ul>
  19. </div>
  20. </div>
  21. <div v-else>
  22. <!-- <el-button @click="studentLogin()">学生登录</el-button> -->
  23. <el-button @click="linkLogin()">教师登录</el-button>
  24. </div>
  25. </div>
  26. </template>
  27. <script setup>
  28. import axios from "axios"
  29. import { ref, onMounted, watchEffect } from "vue"
  30. import { userCurrentRole, userInfoStore } from '../../stores/counter'
  31. const user = userInfoStore()
  32. const isLogin = ref(false)
  33. const admin = ref(false)
  34. const userName = ref('username')
  35. const CurrentRole = userCurrentRole()
  36. const userInfoShow = ref(false)
  37. onMounted(() => {
  38. document.addEventListener('click', (e) => {
  39. if (e.target.className !== 'dropdownMenu') {
  40. userInfoShow.value = false
  41. }
  42. })
  43. })
  44. const linkLogin = () => {
  45. top.location.href = `https://sz.edu.cn/thirdauth/oauth2/authorize?service=initService&scope=all&response_type=code&app_id=f03970962b254aa29115fefd42a8eeb7&redirect_uri=https://cloud.cocorobo.cn/api`
  46. }
  47. const adminClick = () => {
  48. console.log('admin')
  49. // U.MD.D.I.openInApplication('dataBoardSZCity') //市级数据看板
  50. // U.MD.D.I.openInApplication('dataBoardSZArea') //区级数据看板
  51. console.log(CurrentRole.CurrentRole)
  52. if (CurrentRole.currentRole === 'userAdministrator' || user.user.role == 1) {
  53. top.U.MD.D.I.openInApplication('dataBoardSZCity')
  54. } else if (CurrentRole.currentRole === 'securityAuditor') {
  55. top.U.MD.D.I.openInApplication('dataBoardSZArea')
  56. } else {
  57. top.U.MD.D.I.openApplication('Grade')
  58. }
  59. }
  60. const goBack = () => {
  61. top.location.href = "https://ai.szedu.cn/"
  62. }
  63. const userInfoOpen = () => {
  64. top.U.MD.D.I.openApplication('my')
  65. }
  66. const logout = () => {
  67. axios.post(`https://beta.api.cocorobo.cn/api/logout`).then(res => {
  68. console.log("logout", res)
  69. if (res.data == "logout") {
  70. top.location.href = "https://sz.edu.cn/thirdauth/oauth2/sso_logout?app_id=f03970962b254aa29115fefd42a8eeb7&redirect_uri=https%3A%2F%2Fcloud.cocorobo.cn%2Fapi"
  71. }
  72. })
  73. }
  74. watchEffect(() => {
  75. // console.log(user, 2222222222)
  76. if (JSON.stringify(user.user) != "{}") {
  77. isLogin.value = true
  78. userName.value = user.user.username
  79. 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) {
  80. admin.value = true
  81. }
  82. }
  83. })
  84. </script>
  85. <style scoped lang="scss">
  86. .header_right {
  87. display: flex;
  88. .loginAdmin {
  89. display: flex;
  90. }
  91. div {
  92. line-height: 60px;
  93. padding-right: 20px;
  94. img {
  95. vertical-align: middle;
  96. }
  97. span {
  98. padding: 10px;
  99. line-height: 60px;
  100. }
  101. .el-button {
  102. background: rgba(54, 129, 252, 1);
  103. color: #fff;
  104. }
  105. }
  106. .user_info {
  107. width: 100%;
  108. position: relative;
  109. background: #fff;
  110. border: 1px solid #fff;
  111. li {
  112. padding: 10px;
  113. cursor: pointer;
  114. // height: 40px;
  115. line-height: normal;
  116. }
  117. li:hover {
  118. background: rgb(54, 129, 252);
  119. color: #fff;
  120. }
  121. }
  122. }
  123. </style>