index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <header class="header-bar">
  3. <span ></span>
  4. <span>
  5. <slot name="header-user">
  6. <el-dropdown @command="handleCommand">
  7. <span class="account-name">{{accountInfo.userName}} <i class="el-icon-arrow-down"></i></span>
  8. <template #dropdown>
  9. <el-dropdown-menu>
  10. <slot name="pre-dropdown"></slot>
  11. <el-dropdown-item command="logout">退出</el-dropdown-item>
  12. <slot name="dropdown" />
  13. </el-dropdown-menu>
  14. </template>
  15. </el-dropdown>
  16. </slot>
  17. </span>
  18. </header>
  19. </template>
  20. <script>
  21. import { ElDropdown, ElDropdownMenu, ElDropdownItem } from 'element-plus'
  22. import { computed } from 'vue'
  23. import { Token } from '@/lib/token'
  24. import { useRouter } from 'vue-router'
  25. // import { accountService } from '@/api'
  26. import store from '../../store'
  27. import { useCipConfig } from '@cip/components/hooks/use-cip-config'
  28. export default {
  29. name: 'CipHeaderBar',
  30. components: {
  31. ElDropdown, ElDropdownMenu, ElDropdownItem
  32. },
  33. setup () {
  34. // const store = useStore()
  35. const cipConfig = useCipConfig()
  36. const router = useRouter()
  37. const accountInfo = computed(() => {
  38. return store.state.accountInfo || {}
  39. })
  40. const handleCommand = (command) => {
  41. if (command === 'logout') {
  42. if (cipConfig.logout) {
  43. cipConfig.logout()
  44. } else {
  45. Token.remove()
  46. location.href = `${router.options.history.base}/login`
  47. }
  48. }
  49. }
  50. return { accountInfo, handleCommand }
  51. }
  52. }
  53. </script>
  54. <style lang="less">
  55. .main-framework__header{
  56. .header-bar{
  57. height: 100%;
  58. display: flex;
  59. align-items: center;
  60. justify-content: space-between;
  61. padding: 0 12px;
  62. margin-left: auto;
  63. }
  64. .account-name{
  65. cursor: pointer;
  66. font-weight: bold;
  67. }
  68. }
  69. </style>