headerRight.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div class="header_right">
  3. <div v-if="isLogin" class="loginAdmin">
  4. <div v-if="admin">
  5. <img src="" alt="">
  6. <router-link to="/admin"><span>管理后台</span></router-link>
  7. </div>
  8. <div>
  9. <img src="" alt="">
  10. <span>{{ userName }}</span>
  11. </div>
  12. </div>
  13. <div v-else>
  14. <el-button @click="linkLogin()">登录</el-button>
  15. </div>
  16. </div>
  17. </template>
  18. <script setup>
  19. import { ref, onMounted, watchEffect } from "vue"
  20. import { userInfoStore } from '../../stores/counter'
  21. const user = userInfoStore()
  22. const isLogin = ref(false)
  23. const admin = ref(false)
  24. const userName = ref('')
  25. // onMounted(() => {
  26. // console.log(user)
  27. // if (JSON.stringify(user.user) != "{}") {
  28. // isLogin.value = true
  29. // userName.value = user.user.userName
  30. // if (user.user.currentRole == "areaAdministrator" || user.user.currentRole == "userAdministrator" || user.user.currentRole == "securityAuditor" || user.user.currentRole == "schoolAdministrator" || user.user.currentRole == "schoolSecurityAuditor" || user.user.currentRole == "teacher") {
  31. // admin.value = true
  32. // }
  33. // }
  34. // })
  35. const linkLogin = () => {
  36. 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`
  37. }
  38. watchEffect(() => {
  39. // console.log(user, 2222222222)
  40. if (JSON.stringify(user.user) != "{}") {
  41. isLogin.value = true
  42. userName.value = user.user.userName
  43. if (user.user.currentRole == "areaAdministrator" || user.user.currentRole == "userAdministrator" || user.user.currentRole == "securityAuditor" || user.user.currentRole == "schoolAdministrator" || user.user.currentRole == "schoolSecurityAuditor" || user.user.currentRole == "teacher" || user.user.currentRole == "visitor") {
  44. admin.value = true
  45. }
  46. }
  47. })
  48. </script>
  49. <style scoped lang="scss">
  50. .header_right {
  51. display: flex;
  52. .loginAdmin {
  53. display: flex;
  54. }
  55. div {
  56. line-height: 60px;
  57. padding-right: 20px;
  58. img {
  59. vertical-align: middle;
  60. }
  61. span {
  62. padding: 10px;
  63. line-height: 60px;
  64. }
  65. .el-button {
  66. background: rgba(54, 129, 252, 1);
  67. color: #fff;
  68. }
  69. }
  70. }
  71. </style>