vue-stack-tabs 0.1.35 → 0.1.37
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/README.md +2 -2
- package/dist/src/lib/StackTabs.vue.d.ts +140 -13
- package/dist/src/lib/components/ContextMenu/ContextMenuItem.vue.d.ts +3 -3
- package/dist/src/lib/components/ContextMenu/index.vue.d.ts +13 -12
- package/dist/src/lib/components/PageLoading.vue.d.ts +3 -3
- package/dist/src/lib/components/TabHeader/TabHeaderButton.vue.d.ts +11 -11
- package/dist/src/lib/components/TabHeader/TabHeaderItem.vue.d.ts +4 -4
- package/dist/src/lib/components/TabHeader/TabHeaderScroll.vue.d.ts +11 -11
- package/dist/src/lib/components/TabHeader/index.vue.d.ts +15 -14
- package/dist/src/lib/hooks/useContextMenu.d.ts +3 -2
- package/dist/src/lib/hooks/useStackTab.d.ts +4 -2
- package/dist/src/lib/hooks/useTabMitt.d.ts +3 -2
- package/dist/src/lib/hooks/useTabRouter.d.ts +2 -1
- package/dist/src/lib/hooks/useTabpanel.d.ts +7 -6
- package/dist/src/lib/i18n/index.d.ts +1 -1
- package/dist/src/lib/iframe.vue.d.ts +1 -1
- package/dist/src/lib/index.d.ts +8 -8
- package/dist/src/lib/utils/TabIdHelper.d.ts +2 -1
- package/dist/src/lib/utils/TabScrollHelper.d.ts +3 -3
- package/dist/style.css +1 -1
- package/dist/vue-stack-tabs.es.js +1370 -1516
- package/dist/vue-stack-tabs.umd.js +2 -3
- package/package.json +47 -50
- package/src/lib/StackTabs.vue +14 -3
- package/src/lib/assets/style/transition.scss +22 -0
- package/src/lib/hooks/useStackTab.ts +116 -103
- package/src/lib/hooks/useTabRouter.ts +4 -0
- package/src/lib/hooks/useTabpanel.tsx +2 -1
|
@@ -1,103 +1,116 @@
|
|
|
1
|
-
import { useRouter } from 'vue-router'
|
|
2
|
-
import useTabpanel from '../hooks/useTabpanel'
|
|
3
|
-
import { throttle } from '
|
|
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 '
|
|
10
|
-
import { MittType, useEmitter } from './useTabMitt'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* @param
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// active
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
|
|
115
|
+
return { openNewTab, setIFramePath, active, reset }
|
|
116
|
+
}
|
|
@@ -6,12 +6,14 @@ import { type RouteLocationPathRaw, useRoute, useRouter } from 'vue-router'
|
|
|
6
6
|
|
|
7
7
|
import useTabpanel from '@/lib/hooks/useTabpanel'
|
|
8
8
|
import { uriDecode } from '@/lib/utils/UriHelper'
|
|
9
|
+
import { useEmitter } from '@/lib/hooks/useTabMitt'
|
|
9
10
|
export default () => {
|
|
10
11
|
const { attrs, props } = getCurrentInstance() as ComponentInternalInstance
|
|
11
12
|
const { pageShown, getTab, markDeletableCache, removeComponent, getComponent, addPageScroller } =
|
|
12
13
|
useTabpanel()
|
|
13
14
|
const route = useRoute()
|
|
14
15
|
const router = useRouter()
|
|
16
|
+
const emitter = useEmitter()
|
|
15
17
|
let currentId = ''
|
|
16
18
|
// const currentPageId = ''
|
|
17
19
|
let currentTab = ''
|
|
@@ -31,6 +33,7 @@ export default () => {
|
|
|
31
33
|
},
|
|
32
34
|
to.query
|
|
33
35
|
)
|
|
36
|
+
emitter.emit('FORWARD')
|
|
34
37
|
router.push({
|
|
35
38
|
path: to.path,
|
|
36
39
|
query
|
|
@@ -85,6 +88,7 @@ export default () => {
|
|
|
85
88
|
const sourceComponent = component.components.DynamicComponent
|
|
86
89
|
sourceComponent.props = defu(query, sourceComponent.props)
|
|
87
90
|
}
|
|
91
|
+
emitter.emit('BACKWARD')
|
|
88
92
|
router.push({
|
|
89
93
|
path: pageRoute!.path,
|
|
90
94
|
query: pageRoute!.query
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import type { DefineComponent, VNode } from 'vue'
|
|
13
13
|
import { useRouter } from 'vue-router'
|
|
14
14
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
15
|
-
import { ulid } from '
|
|
15
|
+
import { ulid } from 'ulid'
|
|
16
16
|
import { encodeTabInfo, createPageId, decodeTabInfo } from '../utils/TabIdHelper'
|
|
17
17
|
import { defu } from 'defu'
|
|
18
18
|
import { Stack } from '../model/TabModel'
|
|
@@ -588,6 +588,7 @@ export default () => {
|
|
|
588
588
|
*/
|
|
589
589
|
const active = (id: string, route = true) => {
|
|
590
590
|
// return new Promise((resolve)=>{
|
|
591
|
+
emitter.emit('FORWARD')
|
|
591
592
|
for (let i = tabs.value.length - 1; i >= 0; i--) {
|
|
592
593
|
const tab = tabs.value[i] as ITabItem
|
|
593
594
|
if (tab.id === id) {
|