Blame view

src/layouts/default/header/index.vue 5.02 KB
vben authored
1
2
3
4
5
<template>
  <Header :class="getHeaderClass">
    <!-- left start -->
    <div :class="`${prefixCls}-left`">
      <!-- logo -->
6
7
8
      <AppLogo
        v-if="getShowHeaderLogo || getIsMobile"
        :class="`${prefixCls}-logo`"
vben authored
9
        :theme="getHeaderTheme"
10
        :style="getLogoWidth"
vben authored
11
      />
12
      <LayoutTrigger
13
14
15
        v-if="
          (getShowContent && getShowHeaderTrigger && !getSplit && !getIsMixSidebar) || getIsMobile
        "
vben authored
16
        :theme="getHeaderTheme"
17
        :sider="false"
vben authored
18
      />
19
      <LayoutBreadcrumb v-if="getShowContent && getShowBread" :theme="getHeaderTheme" />
vben authored
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    </div>
    <!-- left end -->

    <!-- menu start -->
    <div :class="`${prefixCls}-menu`" v-if="getShowTopMenu && !getIsMobile">
      <LayoutMenu
        :isHorizontal="true"
        :theme="getHeaderTheme"
        :splitType="getSplitType"
        :menuMode="getMenuMode"
      />
    </div>
    <!-- menu-end -->

    <!-- action  -->
    <div :class="`${prefixCls}-action`">
36
      <AppSearch :class="`${prefixCls}-action__item `" />
vben authored
37
38
      <ErrorAction v-if="getUseErrorHandle" :class="`${prefixCls}-action__item error-action`" />
vben authored
39
40
      <LockItem v-if="getUseLockPage" :class="`${prefixCls}-action__item lock-item`" />
vben authored
41
42
      <Notify v-if="getShowNotice" :class="`${prefixCls}-action__item notify-item`" />
vben authored
43
44
      <FullScreen v-if="getShowFullScreen" :class="`${prefixCls}-action__item fullscreen-item`" />
vben authored
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

      <UserDropDown :theme="getHeaderTheme" />

      <AppLocalePicker
        v-if="getShowLocale"
        :reload="true"
        :showText="false"
        :class="`${prefixCls}-action__item`"
      />
    </div>
  </Header>
</template>
<script lang="ts">
  import { defineComponent, unref, computed } from 'vue';

  import { propTypes } from '/@/utils/propTypes';

  import { Layout } from 'ant-design-vue';
  import { AppLogo } from '/@/components/Application';
  import LayoutMenu from '../menu';
  import LayoutTrigger from '../trigger/index.vue';

  import { AppSearch } from '/@/components/Application';

  import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
  import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
  import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  import { useLocaleSetting } from '/@/hooks/setting/useLocaleSetting';

  import { MenuModeEnum, MenuSplitTyeEnum } from '/@/enums/menuEnum';
  import { AppLocalePicker } from '/@/components/Application';

  import {
    UserDropDown,
    LayoutBreadcrumb,
    FullScreen,
    Notify,
    LockItem,
    ErrorAction,
  } from './components';
  import { useAppInject } from '/@/hooks/web/useAppInject';
  import { useDesign } from '/@/hooks/web/useDesign';
87
  import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
vben authored
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

  export default defineComponent({
    name: 'LayoutHeader',
    components: {
      Header: Layout.Header,
      AppLogo,
      LayoutTrigger,
      LayoutBreadcrumb,
      LayoutMenu,
      UserDropDown,
      AppLocalePicker,
      FullScreen,
      Notify,
      LockItem,
      AppSearch,
      ErrorAction,
    },
    props: {
      fixed: propTypes.bool,
    },
    setup(props) {
      const { prefixCls } = useDesign('layout-header');
110
111
112
113
114
115
      const {
        getShowTopMenu,
        getShowHeaderTrigger,
        getSplit,
        getIsMixMode,
        getMenuWidth,
116
        getIsMixSidebar,
117
      } = useMenuSetting();
vben authored
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
      const { getShowLocale } = useLocaleSetting();
      const { getUseErrorHandle } = useRootSetting();

      const {
        getHeaderTheme,
        getUseLockPage,
        getShowFullScreen,
        getShowNotice,
        getShowContent,
        getShowBread,
        getShowHeaderLogo,
      } = useHeaderSetting();

      const { getIsMobile } = useAppInject();

      const getHeaderClass = computed(() => {
        const theme = unref(getHeaderTheme);
        return [
          prefixCls,
137
138
139
140
141
          {
            [`${prefixCls}--fixed`]: props.fixed,
            [`${prefixCls}--mobile`]: unref(getIsMobile),
            [`${prefixCls}--${theme}`]: theme,
          },
vben authored
142
143
144
        ];
      });
145
146
147
148
149
150
151
152
      const getLogoWidth = computed(() => {
        if (!unref(getIsMixMode)) {
          return {};
        }
        const width = unref(getMenuWidth) < 180 ? 180 : unref(getMenuWidth);
        return { width: `${width}px` };
      });
vben authored
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
      const getSplitType = computed(() => {
        return unref(getSplit) ? MenuSplitTyeEnum.TOP : MenuSplitTyeEnum.NONE;
      });

      const getMenuMode = computed(() => {
        return unref(getSplit) ? MenuModeEnum.HORIZONTAL : null;
      });

      return {
        prefixCls,
        getHeaderClass,
        getShowHeaderLogo,
        getHeaderTheme,
        getShowHeaderTrigger,
        getIsMobile,
        getShowBread,
        getShowContent,
        getSplitType,
171
        getSplit,
vben authored
172
173
174
175
176
177
178
        getMenuMode,
        getShowTopMenu,
        getShowLocale,
        getShowFullScreen,
        getShowNotice,
        getUseLockPage,
        getUseErrorHandle,
179
        getLogoWidth,
180
        getIsMixSidebar,
vben authored
181
182
183
184
185
186
187
      };
    },
  });
</script>
<style lang="less">
  @import './index.less';
</style>