123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import { TabItem, tabStore } from '/@/store/modules/tab';
- import type { PropType } from 'vue';
- import { getScaleAction, TabContentProps } from './tab.data';
- import { defineComponent, unref, computed } from 'vue';
- import { Dropdown } from '/@/components/Dropdown/index';
- import Icon from '/@/components/Icon/index';
- import { DoubleRightOutlined } from '@ant-design/icons-vue';
- import { appStore } from '/@/store/modules/app';
- import { TabContentEnum } from './tab.data';
- import { useTabDropdown } from './useTabDropdown';
- export default defineComponent({
- name: 'TabContent',
- props: {
- tabItem: {
- type: Object as PropType<TabItem>,
- default: null,
- },
- type: {
- type: Number as PropType<number>,
- default: TabContentEnum.TAB_TYPE,
- },
- trigger: {
- type: Array as PropType<string[]>,
- default: () => {
- return ['contextmenu'];
- },
- },
- },
- setup(props) {
- const getProjectConfigRef = computed(() => {
- return appStore.getProjectConfig;
- });
- const getIsScaleRef = computed(() => {
- const {
- menuSetting: { show: showMenu },
- headerSetting: { show: showHeader },
- } = unref(getProjectConfigRef);
- return !showMenu && !showHeader;
- });
- function handleContextMenu(e: Event) {
- if (!props.tabItem) return;
- const tableItem = props.tabItem;
- e.preventDefault();
- const index = unref(tabStore.getTabsState).findIndex((tab) => tab.path === tableItem.path);
- tabStore.commitCurrentContextMenuIndexState(index);
- tabStore.commitCurrentContextMenuState(props.tabItem);
- }
- /**
- * @description: 渲染图标
- */
- function renderIcon() {
- const { tabItem } = props;
- if (!tabItem) return;
- const icon = tabItem.meta && tabItem.meta.icon;
- if (!icon || !unref(getProjectConfigRef).multiTabsSetting.showIcon) return null;
- return <Icon icon={icon} class="align-middle " style={{ marginBottom: '2px' }} />;
- }
- function renderTabContent() {
- const { tabItem: { meta } = {} } = props;
- return (
- <div class={`multiple-tabs-content__content `} onContextmenu={handleContextMenu}>
- {renderIcon()}
- <span class="ml-1">{meta && meta.title}</span>
- </div>
- );
- }
- function renderExtraContent() {
- return (
- <span class={`multiple-tabs-content__extra `}>
- <DoubleRightOutlined />
- </span>
- );
- }
- const { getDropMenuList, handleMenuEvent } = useTabDropdown(props as TabContentProps);
- return () => {
- const { trigger, type } = props;
- const {
- multiTabsSetting: { showQuick },
- } = unref(getProjectConfigRef);
- const isTab = !showQuick ? true : type === TabContentEnum.TAB_TYPE;
- const scaleAction = getScaleAction(
- unref(getIsScaleRef) ? '缩小' : '放大',
- unref(getIsScaleRef)
- );
- const dropMenuList = unref(getDropMenuList) || [];
- return (
- <Dropdown
- dropMenuList={!isTab ? [scaleAction, ...dropMenuList] : dropMenuList}
- trigger={isTab ? trigger : ['hover']}
- onMenuEvent={handleMenuEvent}
- >
- {() => (isTab ? renderTabContent() : renderExtraContent())}
- </Dropdown>
- );
- };
- },
- });
|