header-dropdown.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div class="header-box">
  3. <div class="logo" :style="{ width: logoWidth }">
  4. <router-link to="/">
  5. <img src="@/assets/logo1.svg" alt="logo" style="height:32px;width:32px;" />
  6. </router-link>
  7. <h1>{{ shortName }}</h1>
  8. </div>
  9. <div class="banner">
  10. <i class="naf-icons" :class="{ 'naf-icon-unfold': menuCollapse, 'naf-icon-fold': !menuCollapse }" @click="toggleMenu"></i>
  11. <!--下拉用户菜单-->
  12. <el-dropdown class="right" @command="handleUserCommand" v-if="false">
  13. <span class="el-dropdown-link">
  14. <i class="naf-icons naf-icon-avatar"></i>
  15. <span class="name">{{ (userinfo && userinfo.fullname) || '管理員' }}</span>
  16. </span>
  17. <el-dropdown-menu class="action-menu" slot="dropdown">
  18. <el-dropdown-item>
  19. <i class="naf-icons naf-icon-user"></i>
  20. <span>个人中心</span>
  21. </el-dropdown-item>
  22. <el-dropdown-item>
  23. <i class="naf-icons naf-icon-setting"></i>
  24. <span>设置</span>
  25. </el-dropdown-item>
  26. <el-dropdown-item command="logout" divided>
  27. <i class="naf-icons naf-icon-quit"></i>
  28. <span>退出</span>
  29. </el-dropdown-item>
  30. </el-dropdown-menu>
  31. </el-dropdown>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import { mapActions, mapState } from 'vuex';
  37. export default {
  38. props: {
  39. shortName: String,
  40. logoWidth: {
  41. type: String,
  42. default: '256px',
  43. },
  44. menuCollapse: Boolean,
  45. },
  46. methods: {
  47. ...mapActions({
  48. logout: 'login/logout',
  49. }),
  50. toggleMenu() {
  51. this.$emit('toggle-menu');
  52. },
  53. async handleUserCommand(command) {
  54. if (command === 'logout') {
  55. await this.handleLogout();
  56. } else {
  57. this.$message({
  58. type: 'info',
  59. message: '即将上线,敬请期待...',
  60. });
  61. }
  62. },
  63. async handleLogout() {
  64. console.log(this.userinfo);
  65. console.log(this);
  66. const res = await this.logout();
  67. // console.log(res);
  68. if (!res.errcode) {
  69. this.$router.push(this.$route.query.redirect || '/login');
  70. }
  71. },
  72. },
  73. computed: {
  74. userinfo() {
  75. return this.$store.getters.userinfo;
  76. },
  77. },
  78. };
  79. </script>
  80. <style lang="less" scoped>
  81. .header-box {
  82. border-bottom: solid 1px #e6e6e6;
  83. display: flex;
  84. flex-direction: row;
  85. padding: 0;
  86. height: 100%;
  87. .logo {
  88. border-right: solid 1px #e6e6e6;
  89. padding: 0 16px;
  90. overflow: hidden;
  91. img,
  92. h1 {
  93. vertical-align: middle;
  94. }
  95. h1 {
  96. display: inline-block;
  97. margin: 0 0 0 12px;
  98. }
  99. }
  100. .banner {
  101. flex: 1;
  102. padding: 0 20px;
  103. .right {
  104. float: right;
  105. }
  106. .naf-icon-avatar {
  107. margin-right: 4px;
  108. color: rgba(255, 255, 255, 0.8);
  109. font-size: 20px;
  110. border-radius: 14px;
  111. background: grey;
  112. padding: 4px;
  113. }
  114. .right.lite {
  115. font-size: 14px;
  116. }
  117. }
  118. }
  119. .el-button--text {
  120. color: white;
  121. }
  122. </style>