vue-stack-tabs 0.1.42 → 0.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/favicon.svg +9 -9
- package/dist/vue-stack-tabs.es.js +2 -2
- package/dist/vue-stack-tabs.umd.js +1 -1
- package/package.json +1 -1
- package/src/lib/StackTabs.vue +141 -141
- package/src/lib/assets/style/transition.scss +62 -62
- package/src/lib/components/TabHeader/TabHeaderScroll.vue +1 -1
- package/src/lib/hooks/useStackTab.ts +119 -119
- package/src/lib/hooks/useTabRouter.ts +103 -103
- package/src/lib/utils/TabIdHelper.ts +70 -70
package/src/lib/StackTabs.vue
CHANGED
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { onBeforeMount, onBeforeUnmount, provide, ref } from 'vue'
|
|
3
|
-
import type { TransitionProps, DefineComponent, VNode } from 'vue'
|
|
4
|
-
import { type RouteLocationNormalizedLoaded } from 'vue-router'
|
|
5
|
-
import { getMaxZIndex } from './utils/TabScrollHelper'
|
|
6
|
-
import { type ITabData, TabScrollMode } from './model/TabModel'
|
|
7
|
-
import TabHeader from './components/TabHeader/index.vue'
|
|
8
|
-
import useTabpanel from './hooks/useTabpanel'
|
|
9
|
-
import useStackTab from './hooks/useStackTab'
|
|
10
|
-
import { useI18n } from 'vue-i18n-lite'
|
|
11
|
-
import { useEmitter } from '@/lib/hooks/useTabMitt'
|
|
12
|
-
const { tabs, pageShown, caches, destroy, addPage, initial, setMaxSize, setGlobalScroll,clearSession ,setSessionPrefix} =
|
|
13
|
-
useTabpanel()
|
|
14
|
-
const emit = defineEmits(['onActive', 'onPageLoaded'])
|
|
15
|
-
const props = withDefaults(
|
|
16
|
-
defineProps<{
|
|
17
|
-
// 初始页签数据
|
|
18
|
-
defaultTabs?: ITabData[]
|
|
19
|
-
// 最大打开数量
|
|
20
|
-
max?: number
|
|
21
|
-
// 新页加入哪个位置
|
|
22
|
-
append?: string
|
|
23
|
-
// 右键菜单
|
|
24
|
-
contextmenu?: boolean | object
|
|
25
|
-
// 页面转场效果
|
|
26
|
-
pageTransition?: string
|
|
27
|
-
pageTransitionBack?: string
|
|
28
|
-
// 标签转场效果
|
|
29
|
-
tabTransition?: string | TransitionProps
|
|
30
|
-
// tab 滚动效果
|
|
31
|
-
tabScrollMode?: TabScrollMode
|
|
32
|
-
width?: string
|
|
33
|
-
height?: string
|
|
34
|
-
i18n?: string
|
|
35
|
-
space?: number
|
|
36
|
-
globalScroll: boolean
|
|
37
|
-
iframePath: string
|
|
38
|
-
sessionPrefix?: string
|
|
39
|
-
}>(),
|
|
40
|
-
{
|
|
41
|
-
defaultTabs: () => [],
|
|
42
|
-
max: 20,
|
|
43
|
-
append: 'last',
|
|
44
|
-
contextmenu: true,
|
|
45
|
-
tabTransition: 'stack-tab-zoom',
|
|
46
|
-
pageTransition: 'stack-tab-swap',
|
|
47
|
-
pageTransitionBack: 'stack-tab-swap-back',
|
|
48
|
-
tabScrollMode: TabScrollMode.BOTH,
|
|
49
|
-
width: '100%',
|
|
50
|
-
height: '100%',
|
|
51
|
-
i18n: 'zh-CN',
|
|
52
|
-
space: 300,
|
|
53
|
-
globalScroll: false,
|
|
54
|
-
sessionPrefix: '',
|
|
55
|
-
}
|
|
56
|
-
)
|
|
57
|
-
// provide('locales', { ...props.i18n })
|
|
58
|
-
// 最大化,并向下传递
|
|
59
|
-
const { changeLocale } = useI18n()
|
|
60
|
-
const maximum = ref<boolean>(false)
|
|
61
|
-
provide('maximum', maximum)
|
|
62
|
-
const { setIFramePath } = useStackTab()
|
|
63
|
-
setIFramePath(props.iframePath)
|
|
64
|
-
setGlobalScroll(props.globalScroll)
|
|
65
|
-
changeLocale(props.i18n)
|
|
66
|
-
onBeforeMount(() => {
|
|
67
|
-
console.log('on Before mount')
|
|
68
|
-
initial(props.defaultTabs)
|
|
69
|
-
setSessionPrefix(props.sessionPrefix)
|
|
70
|
-
})
|
|
71
|
-
const tabWrapper = (route: RouteLocationNormalizedLoaded, component: VNode): DefineComponent => {
|
|
72
|
-
// return defineAsyncComponent(() => addPage(route, component))
|
|
73
|
-
return addPage(route, component)
|
|
74
|
-
}
|
|
75
|
-
const onTabActive = (id: string) => {
|
|
76
|
-
emit('onActive', id)
|
|
77
|
-
}
|
|
78
|
-
setMaxSize(props.max)
|
|
79
|
-
onBeforeUnmount(() => {
|
|
80
|
-
destroy()
|
|
81
|
-
})
|
|
82
|
-
const onComponentLoaded = () => {
|
|
83
|
-
emit('onPageLoaded')
|
|
84
|
-
}
|
|
85
|
-
const pageSwitch = ref<string>(props.pageTransition)
|
|
86
|
-
const emitter = useEmitter()
|
|
87
|
-
emitter.on('FORWARD', () => {
|
|
88
|
-
pageSwitch.value = props.pageTransition
|
|
89
|
-
})
|
|
90
|
-
emitter.on('BACKWARD', () => {
|
|
91
|
-
pageSwitch.value = props.pageTransitionBack
|
|
92
|
-
})
|
|
93
|
-
onBeforeUnmount(() => {
|
|
94
|
-
clearSession()
|
|
95
|
-
})
|
|
96
|
-
</script>
|
|
97
|
-
<template>
|
|
98
|
-
<div
|
|
99
|
-
class="stack-tab"
|
|
100
|
-
:style="{
|
|
101
|
-
width: width,
|
|
102
|
-
height: height,
|
|
103
|
-
'z-index': maximum ? getMaxZIndex('body *:not(.stack-tab,.stack-tab *)') : undefined
|
|
104
|
-
}"
|
|
105
|
-
:class="{ 'stack-tab__maximum': maximum }"
|
|
106
|
-
>
|
|
107
|
-
<tab-header :space="space" @active="onTabActive" :tab-transition="tabTransition" :max="max">
|
|
108
|
-
<template #leftButton>
|
|
109
|
-
<slot name="leftButton" />
|
|
110
|
-
</template>
|
|
111
|
-
<template #rightButton>
|
|
112
|
-
<slot name="rightButton" />
|
|
113
|
-
</template>
|
|
114
|
-
</tab-header>
|
|
115
|
-
<div class="stack-tab__container">
|
|
116
|
-
<router-view v-slot="{ Component, route }">
|
|
117
|
-
<transition :name="pageSwitch" appear mode="out-in">
|
|
118
|
-
<keep-alive :include="caches">
|
|
119
|
-
<component
|
|
120
|
-
:is="tabWrapper(route, Component)"
|
|
121
|
-
v-if="pageShown"
|
|
122
|
-
:key="route.fullPath"
|
|
123
|
-
@on-loaded="onComponentLoaded"
|
|
124
|
-
/>
|
|
125
|
-
</keep-alive>
|
|
126
|
-
</transition>
|
|
127
|
-
</router-view>
|
|
128
|
-
<transition-group :name="pageTransition" appear>
|
|
129
|
-
<iframe
|
|
130
|
-
v-for="frame of tabs.filter((item) => item.iframe)"
|
|
131
|
-
v-show="frame.active"
|
|
132
|
-
:key="frame.id"
|
|
133
|
-
class="stack-tab__iframe"
|
|
134
|
-
:src="/^(javascript|data):/i.test(frame.url ?? '') ? 'about:blank' : frame.url"
|
|
135
|
-
frameborder="0"
|
|
136
|
-
/>
|
|
137
|
-
</transition-group>
|
|
138
|
-
</div>
|
|
139
|
-
</div>
|
|
140
|
-
</template>
|
|
141
|
-
<style scoped></style>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { onBeforeMount, onBeforeUnmount, provide, ref } from 'vue'
|
|
3
|
+
import type { TransitionProps, DefineComponent, VNode } from 'vue'
|
|
4
|
+
import { type RouteLocationNormalizedLoaded } from 'vue-router'
|
|
5
|
+
import { getMaxZIndex } from './utils/TabScrollHelper'
|
|
6
|
+
import { type ITabData, TabScrollMode } from './model/TabModel'
|
|
7
|
+
import TabHeader from './components/TabHeader/index.vue'
|
|
8
|
+
import useTabpanel from './hooks/useTabpanel'
|
|
9
|
+
import useStackTab from './hooks/useStackTab'
|
|
10
|
+
import { useI18n } from 'vue-i18n-lite'
|
|
11
|
+
import { useEmitter } from '@/lib/hooks/useTabMitt'
|
|
12
|
+
const { tabs, pageShown, caches, destroy, addPage, initial, setMaxSize, setGlobalScroll,clearSession ,setSessionPrefix} =
|
|
13
|
+
useTabpanel()
|
|
14
|
+
const emit = defineEmits(['onActive', 'onPageLoaded'])
|
|
15
|
+
const props = withDefaults(
|
|
16
|
+
defineProps<{
|
|
17
|
+
// 初始页签数据
|
|
18
|
+
defaultTabs?: ITabData[]
|
|
19
|
+
// 最大打开数量
|
|
20
|
+
max?: number
|
|
21
|
+
// 新页加入哪个位置
|
|
22
|
+
append?: string
|
|
23
|
+
// 右键菜单
|
|
24
|
+
contextmenu?: boolean | object
|
|
25
|
+
// 页面转场效果
|
|
26
|
+
pageTransition?: string
|
|
27
|
+
pageTransitionBack?: string
|
|
28
|
+
// 标签转场效果
|
|
29
|
+
tabTransition?: string | TransitionProps
|
|
30
|
+
// tab 滚动效果
|
|
31
|
+
tabScrollMode?: TabScrollMode
|
|
32
|
+
width?: string
|
|
33
|
+
height?: string
|
|
34
|
+
i18n?: string
|
|
35
|
+
space?: number
|
|
36
|
+
globalScroll: boolean
|
|
37
|
+
iframePath: string
|
|
38
|
+
sessionPrefix?: string
|
|
39
|
+
}>(),
|
|
40
|
+
{
|
|
41
|
+
defaultTabs: () => [],
|
|
42
|
+
max: 20,
|
|
43
|
+
append: 'last',
|
|
44
|
+
contextmenu: true,
|
|
45
|
+
tabTransition: 'stack-tab-zoom',
|
|
46
|
+
pageTransition: 'stack-tab-swap',
|
|
47
|
+
pageTransitionBack: 'stack-tab-swap-back',
|
|
48
|
+
tabScrollMode: TabScrollMode.BOTH,
|
|
49
|
+
width: '100%',
|
|
50
|
+
height: '100%',
|
|
51
|
+
i18n: 'zh-CN',
|
|
52
|
+
space: 300,
|
|
53
|
+
globalScroll: false,
|
|
54
|
+
sessionPrefix: '',
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
// provide('locales', { ...props.i18n })
|
|
58
|
+
// 最大化,并向下传递
|
|
59
|
+
const { changeLocale } = useI18n()
|
|
60
|
+
const maximum = ref<boolean>(false)
|
|
61
|
+
provide('maximum', maximum)
|
|
62
|
+
const { setIFramePath } = useStackTab()
|
|
63
|
+
setIFramePath(props.iframePath)
|
|
64
|
+
setGlobalScroll(props.globalScroll)
|
|
65
|
+
changeLocale(props.i18n)
|
|
66
|
+
onBeforeMount(() => {
|
|
67
|
+
console.log('on Before mount')
|
|
68
|
+
initial(props.defaultTabs)
|
|
69
|
+
setSessionPrefix(props.sessionPrefix)
|
|
70
|
+
})
|
|
71
|
+
const tabWrapper = (route: RouteLocationNormalizedLoaded, component: VNode): DefineComponent => {
|
|
72
|
+
// return defineAsyncComponent(() => addPage(route, component))
|
|
73
|
+
return addPage(route, component)
|
|
74
|
+
}
|
|
75
|
+
const onTabActive = (id: string) => {
|
|
76
|
+
emit('onActive', id)
|
|
77
|
+
}
|
|
78
|
+
setMaxSize(props.max)
|
|
79
|
+
onBeforeUnmount(() => {
|
|
80
|
+
destroy()
|
|
81
|
+
})
|
|
82
|
+
const onComponentLoaded = () => {
|
|
83
|
+
emit('onPageLoaded')
|
|
84
|
+
}
|
|
85
|
+
const pageSwitch = ref<string>(props.pageTransition)
|
|
86
|
+
const emitter = useEmitter()
|
|
87
|
+
emitter.on('FORWARD', () => {
|
|
88
|
+
pageSwitch.value = props.pageTransition
|
|
89
|
+
})
|
|
90
|
+
emitter.on('BACKWARD', () => {
|
|
91
|
+
pageSwitch.value = props.pageTransitionBack
|
|
92
|
+
})
|
|
93
|
+
onBeforeUnmount(() => {
|
|
94
|
+
clearSession()
|
|
95
|
+
})
|
|
96
|
+
</script>
|
|
97
|
+
<template>
|
|
98
|
+
<div
|
|
99
|
+
class="stack-tab"
|
|
100
|
+
:style="{
|
|
101
|
+
width: width,
|
|
102
|
+
height: height,
|
|
103
|
+
'z-index': maximum ? getMaxZIndex('body *:not(.stack-tab,.stack-tab *)') : undefined
|
|
104
|
+
}"
|
|
105
|
+
:class="{ 'stack-tab__maximum': maximum }"
|
|
106
|
+
>
|
|
107
|
+
<tab-header :space="space" @active="onTabActive" :tab-transition="tabTransition" :max="max">
|
|
108
|
+
<template #leftButton>
|
|
109
|
+
<slot name="leftButton" />
|
|
110
|
+
</template>
|
|
111
|
+
<template #rightButton>
|
|
112
|
+
<slot name="rightButton" />
|
|
113
|
+
</template>
|
|
114
|
+
</tab-header>
|
|
115
|
+
<div class="stack-tab__container">
|
|
116
|
+
<router-view v-slot="{ Component, route }">
|
|
117
|
+
<transition :name="pageSwitch" appear mode="out-in">
|
|
118
|
+
<keep-alive :include="caches">
|
|
119
|
+
<component
|
|
120
|
+
:is="tabWrapper(route, Component)"
|
|
121
|
+
v-if="pageShown"
|
|
122
|
+
:key="route.fullPath"
|
|
123
|
+
@on-loaded="onComponentLoaded"
|
|
124
|
+
/>
|
|
125
|
+
</keep-alive>
|
|
126
|
+
</transition>
|
|
127
|
+
</router-view>
|
|
128
|
+
<transition-group :name="pageTransition" appear>
|
|
129
|
+
<iframe
|
|
130
|
+
v-for="frame of tabs.filter((item) => item.iframe)"
|
|
131
|
+
v-show="frame.active"
|
|
132
|
+
:key="frame.id"
|
|
133
|
+
class="stack-tab__iframe"
|
|
134
|
+
:src="/^(javascript|data):/i.test(frame.url ?? '') ? 'about:blank' : frame.url"
|
|
135
|
+
frameborder="0"
|
|
136
|
+
/>
|
|
137
|
+
</transition-group>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</template>
|
|
141
|
+
<style scoped></style>
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
/*
|
|
2
|
-
transition 过渡样式
|
|
3
|
-
*/
|
|
4
|
-
.stack-tab-zoom {
|
|
5
|
-
&-enter-active,
|
|
6
|
-
&-leave-active {
|
|
7
|
-
transition: all 0.3s ease-in-out;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
&-enter-from,
|
|
11
|
-
&-leave-to {
|
|
12
|
-
transform: scale(0);
|
|
13
|
-
opacity: 0;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
页面交换
|
|
19
|
-
*/
|
|
20
|
-
.stack-tab-swap {
|
|
21
|
-
$trans: 30px;
|
|
22
|
-
|
|
23
|
-
&-enter-active,
|
|
24
|
-
&-leave-active {
|
|
25
|
-
transition: all 0.3s ease-in-out;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
&-enter-from,
|
|
29
|
-
&-leave-to {
|
|
30
|
-
opacity: 0;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
&-enter-from {
|
|
34
|
-
transform: translateX($trans);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
&-leave-to {
|
|
38
|
-
transform: translateX(-$trans);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.stack-tab-swap-back {
|
|
43
|
-
$trans: 30px;
|
|
44
|
-
|
|
45
|
-
&-enter-active,
|
|
46
|
-
&-leave-active {
|
|
47
|
-
transition: all 0.3s ease-in-out;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
&-enter-from,
|
|
51
|
-
&-leave-to {
|
|
52
|
-
opacity: 0;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
&-enter-from {
|
|
56
|
-
transform: translateX(-$trans);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
&-leave-to {
|
|
60
|
-
transform: translateX($trans);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
transition 过渡样式
|
|
3
|
+
*/
|
|
4
|
+
.stack-tab-zoom {
|
|
5
|
+
&-enter-active,
|
|
6
|
+
&-leave-active {
|
|
7
|
+
transition: all 0.3s ease-in-out;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&-enter-from,
|
|
11
|
+
&-leave-to {
|
|
12
|
+
transform: scale(0);
|
|
13
|
+
opacity: 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
页面交换
|
|
19
|
+
*/
|
|
20
|
+
.stack-tab-swap {
|
|
21
|
+
$trans: 30px;
|
|
22
|
+
|
|
23
|
+
&-enter-active,
|
|
24
|
+
&-leave-active {
|
|
25
|
+
transition: all 0.3s ease-in-out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&-enter-from,
|
|
29
|
+
&-leave-to {
|
|
30
|
+
opacity: 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&-enter-from {
|
|
34
|
+
transform: translateX($trans);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&-leave-to {
|
|
38
|
+
transform: translateX(-$trans);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.stack-tab-swap-back {
|
|
43
|
+
$trans: 30px;
|
|
44
|
+
|
|
45
|
+
&-enter-active,
|
|
46
|
+
&-leave-active {
|
|
47
|
+
transition: all 0.3s ease-in-out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&-enter-from,
|
|
51
|
+
&-leave-to {
|
|
52
|
+
opacity: 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&-enter-from {
|
|
56
|
+
transform: translateX(-$trans);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
&-leave-to {
|
|
60
|
+
transform: translateX($trans);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
:disabled="isDisabledLeftButton"
|
|
6
6
|
@click="!isDisabledLeftButton && onButton(-1 * space)"
|
|
7
7
|
/>
|
|
8
|
-
<div ref="headerScroll" class="stack-tab__scroll" @wheel.prevent="onWheel">
|
|
8
|
+
<div ref="headerScroll" class="stack-tab__scroll" @wheel.prevent.passive="onWheel">
|
|
9
9
|
<div
|
|
10
10
|
ref="container"
|
|
11
11
|
class="stack-tab__scroll-container"
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import { useRouter } from 'vue-router'
|
|
2
|
-
import useTabpanel from '../hooks/useTabpanel'
|
|
3
|
-
import { throttle } from 'throttle-debounce'
|
|
4
|
-
import type { ITabData } from '../model/TabModel'
|
|
5
|
-
import { defu } from 'defu'
|
|
6
|
-
|
|
7
|
-
import { encodeTabInfo } from '../utils/TabIdHelper'
|
|
8
|
-
import { uriDecode } from '../utils/UriHelper'
|
|
9
|
-
import { ulid } from 'ulid'
|
|
10
|
-
import { MittType, useEmitter } from './useTabMitt'
|
|
11
|
-
import { nextTick } from 'vue'
|
|
12
|
-
|
|
13
|
-
let iframePath: string
|
|
14
|
-
export default () => {
|
|
15
|
-
const router = useRouter()
|
|
16
|
-
const { active, hasTab, pageShown, reset, canAddTab, renewTab, getTab } = useTabpanel()
|
|
17
|
-
const emitter = useEmitter()
|
|
18
|
-
/**
|
|
19
|
-
* 打开新的TAB页面
|
|
20
|
-
* @param tab
|
|
21
|
-
* @param to
|
|
22
|
-
*/
|
|
23
|
-
const openNewTab = throttle(500, (tab: ITabData, renew = false) => {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
if (!pageShown.value) {
|
|
26
|
-
reject()
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
const tabInfo = defu(tab, {
|
|
30
|
-
refreshable: true,
|
|
31
|
-
closable: true,
|
|
32
|
-
iframe: false
|
|
33
|
-
})
|
|
34
|
-
if (tabInfo.id && renew && hasTab(tabInfo.id!)) {
|
|
35
|
-
renewTab(tab)
|
|
36
|
-
const currentTab = getTab(tab.id!)
|
|
37
|
-
// if current tab is active, then must reload the component of router view for complete remove the cache!!!
|
|
38
|
-
if (currentTab?.active) {
|
|
39
|
-
pageShown.value = false
|
|
40
|
-
nextTick(() => {
|
|
41
|
-
pageShown.value = true
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* In the function of openNewTab, if the tab already 'ACTIVE' then do nothing.
|
|
47
|
-
*/
|
|
48
|
-
if (hasTab(tabInfo.id!) && !renew) {
|
|
49
|
-
emitter.emit(MittType.TAB_ACTIVE, { id: tabInfo.id! })
|
|
50
|
-
// active(tabInfo.id!)
|
|
51
|
-
resolve(tabInfo.id)
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
if (!tabInfo.id) {
|
|
55
|
-
tabInfo.id = ulid()
|
|
56
|
-
}
|
|
57
|
-
if (!canAddTab()) {
|
|
58
|
-
reject('Max Size')
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// if (initialed) {
|
|
63
|
-
// // 增加tab
|
|
64
|
-
// let activeTab: ITabItem | null = null
|
|
65
|
-
// for (const tab of unref(tabs)) {
|
|
66
|
-
// tab.active = false
|
|
67
|
-
// }
|
|
68
|
-
// activeTab = {
|
|
69
|
-
// id: tabInfo.id!,
|
|
70
|
-
// title: tabInfo.title,
|
|
71
|
-
// closable: tabInfo.closable!,
|
|
72
|
-
// refreshable: tabInfo.refreshable!,
|
|
73
|
-
// iframe: tabInfo.iframe!,
|
|
74
|
-
// url: tabInfo.iframe ? tab.path : null,
|
|
75
|
-
// active: true,
|
|
76
|
-
// pages: new Stack<ITabPage>()
|
|
77
|
-
// } as ITabItem
|
|
78
|
-
// addTab(activeTab).finally(() => {
|
|
79
|
-
// toPage(tab, tabInfo)
|
|
80
|
-
// resolve(tabInfo.id)
|
|
81
|
-
// })
|
|
82
|
-
// } else {
|
|
83
|
-
toPage(tab, tabInfo)
|
|
84
|
-
resolve(tabInfo.id)
|
|
85
|
-
// }
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
const toPage = (tab: ITabData, tabInfo: any) => {
|
|
89
|
-
const __tab = encodeTabInfo(tabInfo)
|
|
90
|
-
let query = defu(
|
|
91
|
-
{
|
|
92
|
-
__tab
|
|
93
|
-
},
|
|
94
|
-
tab.query
|
|
95
|
-
) as Record<string, string>
|
|
96
|
-
let path
|
|
97
|
-
if (!tab.iframe) {
|
|
98
|
-
const url = uriDecode(tab.path)
|
|
99
|
-
path = url.path
|
|
100
|
-
query = defu(url.query, query)
|
|
101
|
-
} else {
|
|
102
|
-
const __src = encodeURIComponent(tab.path as string)
|
|
103
|
-
path = iframePath
|
|
104
|
-
query['__src'] = __src
|
|
105
|
-
}
|
|
106
|
-
router.push({
|
|
107
|
-
path,
|
|
108
|
-
query
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
const setIFramePath = (path: string) => {
|
|
112
|
-
iframePath = path
|
|
113
|
-
}
|
|
114
|
-
const getWrapper = () =>{
|
|
115
|
-
return document.getElementsByClassName('cache-page-wrapper')[0]
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return { openNewTab, setIFramePath, active, reset,getWrapper }
|
|
119
|
-
}
|
|
1
|
+
import { useRouter } from 'vue-router'
|
|
2
|
+
import useTabpanel from '../hooks/useTabpanel'
|
|
3
|
+
import { throttle } from 'throttle-debounce'
|
|
4
|
+
import type { ITabData } from '../model/TabModel'
|
|
5
|
+
import { defu } from 'defu'
|
|
6
|
+
|
|
7
|
+
import { encodeTabInfo } from '../utils/TabIdHelper'
|
|
8
|
+
import { uriDecode } from '../utils/UriHelper'
|
|
9
|
+
import { ulid } from 'ulid'
|
|
10
|
+
import { MittType, useEmitter } from './useTabMitt'
|
|
11
|
+
import { nextTick } from 'vue'
|
|
12
|
+
|
|
13
|
+
let iframePath: string
|
|
14
|
+
export default () => {
|
|
15
|
+
const router = useRouter()
|
|
16
|
+
const { active, hasTab, pageShown, reset, canAddTab, renewTab, getTab } = useTabpanel()
|
|
17
|
+
const emitter = useEmitter()
|
|
18
|
+
/**
|
|
19
|
+
* 打开新的TAB页面
|
|
20
|
+
* @param tab
|
|
21
|
+
* @param to
|
|
22
|
+
*/
|
|
23
|
+
const openNewTab = throttle(500, (tab: ITabData, renew = false) => {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
if (!pageShown.value) {
|
|
26
|
+
reject()
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
const tabInfo = defu(tab, {
|
|
30
|
+
refreshable: true,
|
|
31
|
+
closable: true,
|
|
32
|
+
iframe: false
|
|
33
|
+
})
|
|
34
|
+
if (tabInfo.id && renew && hasTab(tabInfo.id!)) {
|
|
35
|
+
renewTab(tab)
|
|
36
|
+
const currentTab = getTab(tab.id!)
|
|
37
|
+
// if current tab is active, then must reload the component of router view for complete remove the cache!!!
|
|
38
|
+
if (currentTab?.active) {
|
|
39
|
+
pageShown.value = false
|
|
40
|
+
nextTick(() => {
|
|
41
|
+
pageShown.value = true
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* In the function of openNewTab, if the tab already 'ACTIVE' then do nothing.
|
|
47
|
+
*/
|
|
48
|
+
if (hasTab(tabInfo.id!) && !renew) {
|
|
49
|
+
emitter.emit(MittType.TAB_ACTIVE, { id: tabInfo.id! })
|
|
50
|
+
// active(tabInfo.id!)
|
|
51
|
+
resolve(tabInfo.id)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
if (!tabInfo.id) {
|
|
55
|
+
tabInfo.id = ulid()
|
|
56
|
+
}
|
|
57
|
+
if (!canAddTab()) {
|
|
58
|
+
reject('Max Size')
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// if (initialed) {
|
|
63
|
+
// // 增加tab
|
|
64
|
+
// let activeTab: ITabItem | null = null
|
|
65
|
+
// for (const tab of unref(tabs)) {
|
|
66
|
+
// tab.active = false
|
|
67
|
+
// }
|
|
68
|
+
// activeTab = {
|
|
69
|
+
// id: tabInfo.id!,
|
|
70
|
+
// title: tabInfo.title,
|
|
71
|
+
// closable: tabInfo.closable!,
|
|
72
|
+
// refreshable: tabInfo.refreshable!,
|
|
73
|
+
// iframe: tabInfo.iframe!,
|
|
74
|
+
// url: tabInfo.iframe ? tab.path : null,
|
|
75
|
+
// active: true,
|
|
76
|
+
// pages: new Stack<ITabPage>()
|
|
77
|
+
// } as ITabItem
|
|
78
|
+
// addTab(activeTab).finally(() => {
|
|
79
|
+
// toPage(tab, tabInfo)
|
|
80
|
+
// resolve(tabInfo.id)
|
|
81
|
+
// })
|
|
82
|
+
// } else {
|
|
83
|
+
toPage(tab, tabInfo)
|
|
84
|
+
resolve(tabInfo.id)
|
|
85
|
+
// }
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
const toPage = (tab: ITabData, tabInfo: any) => {
|
|
89
|
+
const __tab = encodeTabInfo(tabInfo)
|
|
90
|
+
let query = defu(
|
|
91
|
+
{
|
|
92
|
+
__tab
|
|
93
|
+
},
|
|
94
|
+
tab.query
|
|
95
|
+
) as Record<string, string>
|
|
96
|
+
let path
|
|
97
|
+
if (!tab.iframe) {
|
|
98
|
+
const url = uriDecode(tab.path)
|
|
99
|
+
path = url.path
|
|
100
|
+
query = defu(url.query, query)
|
|
101
|
+
} else {
|
|
102
|
+
const __src = encodeURIComponent(tab.path as string)
|
|
103
|
+
path = iframePath
|
|
104
|
+
query['__src'] = __src
|
|
105
|
+
}
|
|
106
|
+
router.push({
|
|
107
|
+
path,
|
|
108
|
+
query
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
const setIFramePath = (path: string) => {
|
|
112
|
+
iframePath = path
|
|
113
|
+
}
|
|
114
|
+
const getWrapper = () =>{
|
|
115
|
+
return document.getElementsByClassName('cache-page-wrapper')[0]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return { openNewTab, setIFramePath, active, reset,getWrapper }
|
|
119
|
+
}
|