TabContent.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import type { PropType } from 'vue';
  2. import { defineComponent, unref, computed, FunctionalComponent } from 'vue';
  3. import { TabItem, tabStore } from '/@/store/modules/tab';
  4. import { getScaleAction, TabContentProps } from './data';
  5. import { Dropdown } from '/@/components/Dropdown/index';
  6. import { RightOutlined } from '@ant-design/icons-vue';
  7. import { TabContentEnum } from './data';
  8. import { useTabDropdown } from './useTabDropdown';
  9. import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
  10. import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
  11. import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
  12. import { useI18n } from '/@/hooks/web/useI18n';
  13. const { t: titleT } = useI18n();
  14. const ExtraContent: FunctionalComponent = () => {
  15. return (
  16. <span class={`multiple-tabs-content__extra `}>
  17. <RightOutlined />
  18. </span>
  19. );
  20. };
  21. const TabContent: FunctionalComponent<{ tabItem: TabItem }> = (props) => {
  22. const { tabItem: { meta } = {} } = props;
  23. function handleContextMenu(e: Event) {
  24. if (!props.tabItem) return;
  25. const tableItem = props.tabItem;
  26. e?.preventDefault();
  27. const index = unref(tabStore.getTabsState).findIndex((tab) => tab.path === tableItem.path);
  28. tabStore.commitCurrentContextMenuIndexState(index);
  29. tabStore.commitCurrentContextMenuState(props.tabItem);
  30. }
  31. return (
  32. <div class={`multiple-tabs-content__content `} onContextmenu={handleContextMenu}>
  33. <span class="ml-1">{meta && titleT(meta.title)}</span>
  34. </div>
  35. );
  36. };
  37. export default defineComponent({
  38. name: 'TabContent',
  39. props: {
  40. tabItem: {
  41. type: Object as PropType<TabItem>,
  42. default: null,
  43. },
  44. type: {
  45. type: Number as PropType<TabContentEnum>,
  46. default: TabContentEnum.TAB_TYPE,
  47. },
  48. },
  49. setup(props) {
  50. const { t } = useI18n();
  51. const { getShowMenu } = useMenuSetting();
  52. const { getShowHeader } = useHeaderSetting();
  53. const { getShowQuick } = useMultipleTabSetting();
  54. const getIsScale = computed(() => {
  55. return !unref(getShowMenu) && !unref(getShowHeader);
  56. });
  57. const getIsTab = computed(() => {
  58. return !unref(getShowQuick) ? true : props.type === TabContentEnum.TAB_TYPE;
  59. });
  60. const { getDropMenuList, handleMenuEvent } = useTabDropdown(props as TabContentProps);
  61. return () => {
  62. const scaleAction = getScaleAction(
  63. unref(getIsScale) ? t('layout.multipleTab.putAway') : t('layout.multipleTab.unfold'),
  64. unref(getIsScale)
  65. );
  66. const dropMenuList = unref(getDropMenuList) || [];
  67. const isTab = unref(getIsTab);
  68. return (
  69. <Dropdown
  70. dropMenuList={!isTab ? [scaleAction, ...dropMenuList] : dropMenuList}
  71. trigger={isTab ? ['contextmenu'] : ['click']}
  72. onMenuEvent={handleMenuEvent}
  73. >
  74. {() => (isTab ? <TabContent tabItem={props.tabItem} /> : <ExtraContent />)}
  75. </Dropdown>
  76. );
  77. };
  78. },
  79. });