TabContent.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import type { PropType } from 'vue';
  2. import { Dropdown } from '/@/components/Dropdown/index';
  3. import { defineComponent, unref, FunctionalComponent } from 'vue';
  4. import { TabContentProps } from './types';
  5. import { RightOutlined } from '@ant-design/icons-vue';
  6. import { TabContentEnum } from './types';
  7. import { useTabDropdown } from './useTabDropdown';
  8. import { useI18n } from '/@/hooks/web/useI18n';
  9. import { RouteLocationNormalized } from 'vue-router';
  10. const { t: titleT } = useI18n();
  11. const ExtraContent: FunctionalComponent = () => {
  12. return (
  13. <span class={`multiple-tabs-content__extra `}>
  14. <RightOutlined />
  15. </span>
  16. );
  17. };
  18. const TabContent: FunctionalComponent<{ tabItem: RouteLocationNormalized; handler: Fn }> = (
  19. props
  20. ) => {
  21. const { tabItem: { meta } = {} } = props;
  22. return (
  23. <div class={`multiple-tabs-content__content `} onContextmenu={props.handler(props.tabItem)}>
  24. <span class="ml-1">{meta && titleT(meta.title)}</span>
  25. </div>
  26. );
  27. };
  28. export default defineComponent({
  29. name: 'TabContent',
  30. props: {
  31. tabItem: {
  32. type: Object as PropType<RouteLocationNormalized>,
  33. default: null,
  34. },
  35. type: {
  36. type: Number as PropType<TabContentEnum>,
  37. default: TabContentEnum.TAB_TYPE,
  38. },
  39. },
  40. setup(props) {
  41. const {
  42. getDropMenuList,
  43. handleMenuEvent,
  44. handleContextMenu,
  45. getTrigger,
  46. isTabs,
  47. } = useTabDropdown(props as TabContentProps);
  48. return () => {
  49. return (
  50. <Dropdown
  51. dropMenuList={unref(getDropMenuList)}
  52. trigger={unref(getTrigger)}
  53. onMenuEvent={handleMenuEvent}
  54. >
  55. {() => {
  56. if (!unref(isTabs)) {
  57. return <ExtraContent />;
  58. }
  59. return <TabContent handler={handleContextMenu} tabItem={props.tabItem} />;
  60. }}
  61. </Dropdown>
  62. );
  63. };
  64. },
  65. });