1- import { defineComponent , unref , computed } from 'vue' ;
2-
31import type { PropType } from 'vue' ;
42
3+ import { defineComponent , unref , computed , FunctionalComponent } from 'vue' ;
4+
55import { TabItem , tabStore } from '/@/store/modules/tab' ;
6- import { getScaleAction , TabContentProps } from './tab. data' ;
6+ import { getScaleAction , TabContentProps } from './data' ;
77
88import { Dropdown } from '/@/components/Dropdown/index' ;
99import { RightOutlined } from '@ant-design/icons-vue' ;
10- import { appStore } from '/@/store/modules/app' ;
1110
12- import { TabContentEnum } from './tab. data' ;
11+ import { TabContentEnum } from './data' ;
1312import { useTabDropdown } from './useTabDropdown' ;
13+ import { useMenuSetting } from '/@/hooks/setting/useMenuSetting' ;
14+ import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting' ;
15+ import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting' ;
16+
17+ const ExtraContent : FunctionalComponent = ( ) => {
18+ return (
19+ < span class = { `multiple-tabs-content__extra ` } >
20+ < RightOutlined />
21+ </ span >
22+ ) ;
23+ } ;
24+
25+ const TabContent : FunctionalComponent < { tabItem : TabItem } > = ( props ) => {
26+ const { tabItem : { meta } = { } } = props ;
27+
28+ function handleContextMenu ( e : Event ) {
29+ if ( ! props . tabItem ) return ;
30+ const tableItem = props . tabItem ;
31+ e ?. preventDefault ( ) ;
32+ const index = unref ( tabStore . getTabsState ) . findIndex ( ( tab ) => tab . path === tableItem . path ) ;
33+
34+ tabStore . commitCurrentContextMenuIndexState ( index ) ;
35+ tabStore . commitCurrentContextMenuState ( props . tabItem ) ;
36+ }
37+
38+ return (
39+ < div class = { `multiple-tabs-content__content ` } onContextmenu = { handleContextMenu } >
40+ < span class = "ml-1" > { meta && meta . title } </ span >
41+ </ div >
42+ ) ;
43+ } ;
1444
1545export default defineComponent ( {
1646 name : 'TabContent' ,
@@ -19,82 +49,39 @@ export default defineComponent({
1949 type : Object as PropType < TabItem > ,
2050 default : null ,
2151 } ,
52+
2253 type : {
23- type : Number as PropType < number > ,
54+ type : Number as PropType < TabContentEnum > ,
2455 default : TabContentEnum . TAB_TYPE ,
2556 } ,
26- trigger : {
27- type : Array as PropType < string [ ] > ,
28- default : ( ) => {
29- return [ 'contextmenu' ] ;
30- } ,
31- } ,
3257 } ,
3358 setup ( props ) {
34- const getProjectConfigRef = computed ( ( ) => {
35- return appStore . getProjectConfig ;
36- } ) ;
59+ const { getShowMenu } = useMenuSetting ( ) ;
60+ const { getShowHeader } = useHeaderSetting ( ) ;
61+ const { getShowQuick } = useMultipleTabSetting ( ) ;
3762
38- const getIsScaleRef = computed ( ( ) => {
39- const {
40- menuSetting : { show : showMenu } ,
41- headerSetting : { show : showHeader } ,
42- } = unref ( getProjectConfigRef ) ;
43- return ! showMenu && ! showHeader ;
63+ const getIsScale = computed ( ( ) => {
64+ return ! unref ( getShowMenu ) && ! unref ( getShowHeader ) ;
4465 } ) ;
4566
46- function handleContextMenu ( e : Event ) {
47- if ( ! props . tabItem ) return ;
48- const tableItem = props . tabItem ;
49- e . preventDefault ( ) ;
50- const index = unref ( tabStore . getTabsState ) . findIndex ( ( tab ) => tab . path === tableItem . path ) ;
51-
52- tabStore . commitCurrentContextMenuIndexState ( index ) ;
53- tabStore . commitCurrentContextMenuState ( props . tabItem ) ;
54- }
55-
56- /**
57- * @description : 渲染图标
58- */
59-
60- function renderTabContent ( ) {
61- const { tabItem : { meta } = { } } = props ;
62- return (
63- < div class = { `multiple-tabs-content__content ` } onContextmenu = { handleContextMenu } >
64- < span class = "ml-1" > { meta && meta . title } </ span >
65- </ div >
66- ) ;
67- }
68- function renderExtraContent ( ) {
69- return (
70- < span class = { `multiple-tabs-content__extra ` } >
71- < RightOutlined />
72- </ span >
73- ) ;
74- }
67+ const getIsTab = computed ( ( ) => {
68+ return ! unref ( getShowQuick ) ? true : props . type === TabContentEnum . TAB_TYPE ;
69+ } ) ;
7570
7671 const { getDropMenuList, handleMenuEvent } = useTabDropdown ( props as TabContentProps ) ;
7772
7873 return ( ) => {
79- const { trigger, type } = props ;
80- const {
81- multiTabsSetting : { showQuick } ,
82- } = unref ( getProjectConfigRef ) ;
83-
84- const isTab = ! showQuick ? true : type === TabContentEnum . TAB_TYPE ;
85- const scaleAction = getScaleAction (
86- unref ( getIsScaleRef ) ? '缩小' : '放大' ,
87- unref ( getIsScaleRef )
88- ) ;
74+ const scaleAction = getScaleAction ( unref ( getIsScale ) ? '收起' : '展开' , unref ( getIsScale ) ) ;
8975 const dropMenuList = unref ( getDropMenuList ) || [ ] ;
9076
77+ const isTab = unref ( getIsTab ) ;
9178 return (
9279 < Dropdown
9380 dropMenuList = { ! isTab ? [ scaleAction , ...dropMenuList ] : dropMenuList }
94- trigger = { isTab ? trigger : [ 'hover ' ] }
81+ trigger = { isTab ? [ 'contextmenu' ] : [ 'click ' ] }
9582 onMenuEvent = { handleMenuEvent }
9683 >
97- { ( ) => ( isTab ? renderTabContent ( ) : renderExtraContent ( ) ) }
84+ { ( ) => ( isTab ? < TabContent tabItem = { props . tabItem } /> : < ExtraContent /> ) }
9885 </ Dropdown >
9986 ) ;
10087 } ;
0 commit comments