Ben Lin
2024-06-18 ebbd788fbb2c0b45d4473798efc57eec8ba74a25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<template>
  <Dropdown
    :dropMenuList="getDropMenuList"
    :trigger="getTrigger"
    placement="bottomLeft"
    overlayClassName="multiple-tabs__dropdown"
    @menu-event="handleMenuEvent"
  >
    <div :class="`${prefixCls}__info`" @contextmenu="handleContext" v-if="getIsTabs">
      <span class="ml-1">{{ getTitle }}</span>
    </div>
    <span :class="`${prefixCls}__extra-quick`" v-else @click="handleContext">
      <Icon icon="ion:chevron-down" />
    </span>
  </Dropdown>
</template>
<script lang="ts" setup>
  import type { PropType } from 'vue';
  import type { RouteLocationNormalized } from 'vue-router';
 
  import { computed, unref } from 'vue';
  import { Dropdown } from '@/components/Dropdown';
  import Icon from '@/components/Icon/Icon.vue';
 
  import { TabContentProps } from '../types';
 
  import { useDesign } from '@/hooks/web/useDesign';
  import { useI18n } from '@/hooks/web/useI18n';
  import { useTabDropdown } from '../useTabDropdown';
 
  defineOptions({ name: 'TabContent' });
 
  const props = defineProps({
    tabItem: {
      type: Object as PropType<RouteLocationNormalized>,
      default: null,
    },
    isExtra: Boolean,
  });
 
  const { prefixCls } = useDesign('multiple-tabs-content');
  const { t } = useI18n();
 
  const getTitle = computed(() => {
    const { tabItem: { meta } = {} } = props;
    return meta && t(meta.title as string);
  });
 
  const getIsTabs = computed(() => !props.isExtra);
 
  const getTrigger = computed((): ('contextmenu' | 'click' | 'hover')[] =>
    unref(getIsTabs) ? ['contextmenu'] : ['click'],
  );
 
  const { getDropMenuList, handleMenuEvent, handleContextMenu } = useTabDropdown(
    props as TabContentProps,
    getIsTabs,
  );
 
  function handleContext(e) {
    props.tabItem && handleContextMenu(props.tabItem)(e);
  }
</script>