Blame view

src/layouts/default/tabs/components/TabContent.vue 2.1 KB
vben authored
1
<template>
2
3
4
5
6
7
8
  <Dropdown
    :dropMenuList="getDropMenuList"
    :trigger="getTrigger"
    placement="bottom"
    overlayClassName="multiple-tabs__dropdown"
    @menu-event="handleMenuEvent"
  >
Vben authored
9
    <div :class="`${prefixCls}__info`" @contextmenu="handleContext" v-if="getIsTabs">
vben authored
10
11
      <span class="ml-1">{{ getTitle }}</span>
    </div>
vben authored
12
    <span :class="`${prefixCls}__extra-quick`" v-else @click="handleContext">
vben authored
13
      <Icon icon="ion:chevron-down" />
vben authored
14
15
16
17
18
    </span>
  </Dropdown>
</template>
<script lang="ts">
  import type { PropType } from 'vue';
Vben authored
19
  import type { RouteLocationNormalized } from 'vue-router';
vben authored
20
Vben authored
21
  import { defineComponent, computed, unref } from 'vue';
vben authored
22
  import { Dropdown } from '/@/components/Dropdown/index';
vben authored
23
  import Icon from '@/components/Icon/Icon.vue';
vben authored
24
Vben authored
25
  import { TabContentProps } from '../types';
vben authored
26
27
28

  import { useDesign } from '/@/hooks/web/useDesign';
  import { useI18n } from '/@/hooks/web/useI18n';
Vben authored
29
  import { useTabDropdown } from '../useTabDropdown';
vben authored
30
31
32

  export default defineComponent({
    name: 'TabContent',
vben authored
33
    components: { Dropdown, Icon },
vben authored
34
35
36
37
38
    props: {
      tabItem: {
        type: Object as PropType<RouteLocationNormalized>,
        default: null,
      },
Vben authored
39
      isExtra: Boolean,
vben authored
40
41
42
43
44
45
46
    },
    setup(props) {
      const { prefixCls } = useDesign('multiple-tabs-content');
      const { t } = useI18n();

      const getTitle = computed(() => {
        const { tabItem: { meta } = {} } = props;
Vben authored
47
        return meta && t(meta.title as string);
vben authored
48
49
      });
Vben authored
50
51
      const getIsTabs = computed(() => !props.isExtra);
Vben authored
52
      const getTrigger = computed((): ('contextmenu' | 'click' | 'hover')[] =>
vben authored
53
        unref(getIsTabs) ? ['contextmenu'] : ['click'],
Vben authored
54
      );
vben authored
55
Vben authored
56
57
      const { getDropMenuList, handleMenuEvent, handleContextMenu } = useTabDropdown(
        props as TabContentProps,
vben authored
58
        getIsTabs,
Vben authored
59
60
61
      );

      function handleContext(e) {
vben authored
62
63
        props.tabItem && handleContextMenu(props.tabItem)(e);
      }
Vben authored
64
vben authored
65
66
67
68
69
70
      return {
        prefixCls,
        getDropMenuList,
        handleMenuEvent,
        handleContext,
        getTrigger,
Vben authored
71
        getIsTabs,
vben authored
72
73
74
75
76
        getTitle,
      };
    },
  });
</script>