index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <header class="header-bar">
  3. <slot name="header-plugin"></slot>
  4. <slot name="header-user">
  5. <div class="header-user">
  6. <cip-dropdown @command="handleCommand" :disabled="!($slots.dropdown || $slots['pre-dropdown'])">
  7. <cip-avatar size="small"/>
  8. <span class="account-name">{{accountInfo.userName}} </span>
  9. <template #dropdown>
  10. <el-dropdown-menu>
  11. <slot name="pre-dropdown"></slot>
  12. <slot name="dropdown" />
  13. </el-dropdown-menu>
  14. </template>
  15. </cip-dropdown>
  16. <span class="header-bar__logout" @click="()=>handleCommand('logout')">退出</span>
  17. </div>
  18. </slot>
  19. </header>
  20. </template>
  21. <script>
  22. import { ElDropdownMenu } from 'element-plus'
  23. import CipDropdown from '../../cip-dropdown'
  24. import CipAvatar from '../../cip-avatar'
  25. import { computed } from 'vue'
  26. import { Token } from '@/lib/token'
  27. import { useRouter } from 'vue-router'
  28. // import { accountService } from '@/api'
  29. import store from '../../store'
  30. import { useCipConfig } from '@cip/components/hooks/use-cip-config'
  31. export default {
  32. name: 'CipHeaderBar',
  33. components: {
  34. CipDropdown, CipAvatar, ElDropdownMenu
  35. },
  36. setup (props, { slots }) {
  37. // const store = useStore()
  38. const cipConfig = useCipConfig()
  39. const router = useRouter()
  40. const accountInfo = computed(() => {
  41. return store.state.accountInfo || {}
  42. })
  43. const handleCommand = (command) => {
  44. if (command === 'logout') {
  45. if (cipConfig.logout) {
  46. cipConfig.logout()
  47. } else {
  48. Token.remove()
  49. location.href = `${router.options.history.base}/login`
  50. }
  51. }
  52. }
  53. return { accountInfo, handleCommand }
  54. }
  55. }
  56. </script>
  57. <style lang="less">
  58. .main-framework__header{
  59. .header-bar{
  60. height: 100%;
  61. display: flex;
  62. align-items: center;
  63. justify-content: flex-end;
  64. padding: 0 32px 0 64px;
  65. margin-left: auto;
  66. }
  67. .account-name{
  68. cursor: pointer;
  69. margin-left: 8px;
  70. //font-weight: bold;
  71. }
  72. .header-user{
  73. display: flex;
  74. align-items: center;
  75. font-size: 14px;
  76. height: 100%;
  77. .@{elNamespace}-dropdown{
  78. height: 100%;
  79. }
  80. .header-bar__logout{
  81. padding-left: 12px;
  82. margin-left: 12px;
  83. border-left: 1px solid transparent;
  84. line-height: 1em;
  85. cursor: pointer;
  86. user-select: none;
  87. }
  88. }
  89. }
  90. </style>