headerRight.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="header_right">
  3. <div>
  4. <el-button @click="goBack()">返回人工智能专栏</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>
  13. <img src="" alt="">
  14. <span style="cursor: pointer;" @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. const linkLogin = () => {
  38. 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`
  39. }
  40. const adminClick = () => {
  41. console.log('admin')
  42. // U.MD.D.I.openInApplication('dataBoardSZCity') //市级数据看板
  43. // U.MD.D.I.openInApplication('dataBoardSZArea') //区级数据看板
  44. console.log(CurrentRole.currentRole)
  45. if (CurrentRole.currentRole === 'userAdministrator') {
  46. top.U.MD.D.I.openInApplication('dataBoardSZCity')
  47. } else if (CurrentRole.currentRole === 'securityAuditor') {
  48. top.U.MD.D.I.openInApplication('dataBoardSZArea')
  49. } else {
  50. top.U.MD.D.I.openApplication('Grade')
  51. }
  52. }
  53. const goBack = () => {
  54. top.location.href = "https://zy.szedu.cn/ai/"
  55. }
  56. const userInfoOpen = () => {
  57. top.U.MD.D.I.openApplication('my')
  58. }
  59. const logout = () => {
  60. axios.post(`https://beta.api.cocorobo.cn/api/logout`).then(res => {
  61. console.log("logout",res)
  62. if (res.data == "logout") {
  63. top.location.href = "https://sz.edu.cn/thirdauth/oauth2/sso_logout?app_id=f03970962b254aa29115fefd42a8eeb7&redirect_uri="
  64. }
  65. })
  66. }
  67. watchEffect(() => {
  68. // console.log(user, 2222222222)
  69. if (JSON.stringify(user.user) != "{}") {
  70. isLogin.value = true
  71. userName.value = user.user.username
  72. 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) {
  73. admin.value = true
  74. }
  75. }
  76. })
  77. </script>
  78. <style scoped lang="scss">
  79. .header_right {
  80. display: flex;
  81. .loginAdmin {
  82. display: flex;
  83. }
  84. div {
  85. line-height: 60px;
  86. padding-right: 20px;
  87. img {
  88. vertical-align: middle;
  89. }
  90. span {
  91. padding: 10px;
  92. line-height: 60px;
  93. }
  94. .el-button {
  95. background: rgba(54, 129, 252, 1);
  96. color: #fff;
  97. }
  98. }
  99. .user_info {
  100. width: 100%;
  101. position: relative;
  102. background: #fff;
  103. border: 1px solid #fff;
  104. li {
  105. padding: 10px;
  106. cursor: pointer;
  107. // height: 40px;
  108. line-height: normal;
  109. }
  110. li:hover {
  111. background: rgb(54, 129, 252);
  112. color: #fff;
  113. }
  114. }
  115. }
  116. </style>