index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="appNav">
  3. <div class="rowBC">
  4. <div class="appNav-left">
  5. <el-avatar class="appNav-avatar" :size="25" :src="imgUrl" @error="errorHandler">
  6. <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png" />
  7. </el-avatar>
  8. <span class="appNav-name">深圳机场货运一个码系统-管理端</span>
  9. </div>
  10. <div class="appNav-right">
  11. <el-avatar class="appNav-avatar" :size="25" :src="imgUrl" @error="errorHandler">
  12. <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png" />
  13. </el-avatar>
  14. <el-dropdown trigger="click" size="medium">
  15. <div class="avatar-wrapper">
  16. <span class="name">{{name}}</span>
  17. <ArrowDownBold style="width: 1.2em; height: 1.3em;" />
  18. </div>
  19. <template #dropdown>
  20. <el-dropdown-menu>
  21. <router-link to="/">
  22. <el-dropdown-item>Home</el-dropdown-item>
  23. </router-link>
  24. <el-dropdown-item divided @click="loginOut">login out</el-dropdown-item>
  25. </el-dropdown-menu>
  26. </template>
  27. </el-dropdown>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script setup lang="ts">
  33. import { ref } from "vue";
  34. import { ElMessage } from "element-plus";
  35. import { ArrowDownBold } from "@element-plus/icons-vue";
  36. import { useUserStore } from "@/store/user";
  37. const imgUrl = ref(
  38. "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
  39. );
  40. const store = useUserStore();
  41. const name = store.$state.username;
  42. const errorHandler = () => true;
  43. /*
  44. * 退出登录
  45. * */
  46. const router = useRouter();
  47. const route = useRoute();
  48. const loginOut = async () => {
  49. const userStore = useUserStore();
  50. const result: any = await userStore.logout();
  51. if (result.code == 0) {
  52. ElMessage({
  53. message: "退出成功",
  54. type: "success",
  55. duration: 2 * 1000,
  56. onClose: () => {
  57. useUserStore().resetState();
  58. router.push(`/login`);
  59. location.reload();
  60. },
  61. });
  62. } else {
  63. ElMessage.error(result.message);
  64. }
  65. };
  66. </script>
  67. <style lang="scss" scoped>
  68. .appNav {
  69. height: 48px;
  70. line-height: 48px;
  71. background: #ac014d;
  72. padding: 0 42px 0 16px;
  73. &-avatar {
  74. margin-top: 11.5px;
  75. }
  76. &-name {
  77. font-size: 14px;
  78. font-weight: 400;
  79. color: #ffffff;
  80. margin-left: 13px;
  81. top: -5px;
  82. position: relative;
  83. }
  84. .avatar-wrapper {
  85. font-size: 14px;
  86. font-family: Helvetica;
  87. font-weight: bold;
  88. color: #ffffff;
  89. cursor: pointer;
  90. margin-top: 15px;
  91. .name {
  92. margin: 0px 10px;
  93. position: relative;
  94. top: -3px;
  95. }
  96. }
  97. }
  98. </style>