TabContent.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(() => (unref(getIsTabs) ? ['contextmenu'] : ['click']));
  40. const { getDropMenuList, handleMenuEvent, handleContextMenu } = useTabDropdown(
  41. props as TabContentProps,
  42. getIsTabs
  43. );
  44. function handleContext(e) {
  45. props.tabItem && handleContextMenu(props.tabItem)(e);
  46. }
  47. return {
  48. prefixCls,
  49. getDropMenuList,
  50. handleMenuEvent,
  51. handleContext,
  52. getTrigger,
  53. getIsTabs,
  54. getTitle,
  55. };
  56. },
  57. });
  58. </script>