TabContent.vue 2.0 KB

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