vue-stack-tabs 0.1.34 → 0.1.35
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/favicon.svg +9 -9
- package/dist/vue-stack-tabs.es.js +34 -34
- package/dist/vue-stack-tabs.umd.js +1 -1
- package/package.json +1 -1
- package/src/lib/hooks/useStackTab.ts +103 -103
- package/src/lib/hooks/useTabpanel.tsx +684 -684
- package/src/lib/utils/TabIdHelper.ts +70 -70
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import { useRouter } from 'vue-router'
|
|
2
|
-
import useTabpanel from '../hooks/useTabpanel'
|
|
3
|
-
import { throttle } from 'lodash-es'
|
|
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 'ulidx'
|
|
10
|
-
import { MittType, useEmitter } from './useTabMitt'
|
|
11
|
-
|
|
12
|
-
let iframePath: string
|
|
13
|
-
export default () => {
|
|
14
|
-
const router = useRouter()
|
|
15
|
-
const { active, hasTab, pageShown, reset, canAddTab ,renewTab} = useTabpanel()
|
|
16
|
-
const emitter = useEmitter()
|
|
17
|
-
/**
|
|
18
|
-
* 打开新的TAB页面
|
|
19
|
-
* @param tab
|
|
20
|
-
* @param to
|
|
21
|
-
*/
|
|
22
|
-
const openNewTab = throttle((tab: ITabData,renew=false) => {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
if (!pageShown.value) {
|
|
25
|
-
reject()
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
const tabInfo = defu(tab, { refreshable: true, closable: true, iframe: false })
|
|
29
|
-
if(tabInfo.id && renew && hasTab(tabInfo.id!)){
|
|
30
|
-
renewTab(tab)
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* In the function of openNewTab, if the tab already 'ACTIVE' then do nothing.
|
|
34
|
-
*/
|
|
35
|
-
if (hasTab(tabInfo.id!) && !renew) {
|
|
36
|
-
emitter.emit(MittType.TAB_ACTIVE, { id: tabInfo.id! })
|
|
37
|
-
// active(tabInfo.id!)
|
|
38
|
-
resolve(tabInfo.id)
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
if (!tabInfo.id) {
|
|
42
|
-
tabInfo.id = ulid()
|
|
43
|
-
}
|
|
44
|
-
if (!canAddTab()) {
|
|
45
|
-
reject('Max Size')
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// if (initialed) {
|
|
50
|
-
// // 增加tab
|
|
51
|
-
// let activeTab: ITabItem | null = null
|
|
52
|
-
// for (const tab of unref(tabs)) {
|
|
53
|
-
// tab.active = false
|
|
54
|
-
// }
|
|
55
|
-
// activeTab = {
|
|
56
|
-
// id: tabInfo.id!,
|
|
57
|
-
// title: tabInfo.title,
|
|
58
|
-
// closable: tabInfo.closable!,
|
|
59
|
-
// refreshable: tabInfo.refreshable!,
|
|
60
|
-
// iframe: tabInfo.iframe!,
|
|
61
|
-
// url: tabInfo.iframe ? tab.path : null,
|
|
62
|
-
// active: true,
|
|
63
|
-
// pages: new Stack<ITabPage>()
|
|
64
|
-
// } as ITabItem
|
|
65
|
-
// addTab(activeTab).finally(() => {
|
|
66
|
-
// toPage(tab, tabInfo)
|
|
67
|
-
// resolve(tabInfo.id)
|
|
68
|
-
// })
|
|
69
|
-
// } else {
|
|
70
|
-
toPage(tab, tabInfo)
|
|
71
|
-
resolve(tabInfo.id)
|
|
72
|
-
// }
|
|
73
|
-
})
|
|
74
|
-
}, 500)
|
|
75
|
-
const toPage = (tab: ITabData, tabInfo: any) => {
|
|
76
|
-
const __tab = encodeTabInfo(tabInfo)
|
|
77
|
-
let query = defu(
|
|
78
|
-
{
|
|
79
|
-
__tab
|
|
80
|
-
},
|
|
81
|
-
tab.query
|
|
82
|
-
) as Record<string, string>
|
|
83
|
-
let path
|
|
84
|
-
if (!tab.iframe) {
|
|
85
|
-
const url = uriDecode(tab.path)
|
|
86
|
-
path = url.path
|
|
87
|
-
query = defu(url.query, query)
|
|
88
|
-
} else {
|
|
89
|
-
const __src = encodeURIComponent(tab.path as string)
|
|
90
|
-
path = iframePath
|
|
91
|
-
query['__src'] = __src
|
|
92
|
-
}
|
|
93
|
-
router.push({
|
|
94
|
-
path,
|
|
95
|
-
query
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
const setIFramePath = (path: string) => {
|
|
99
|
-
iframePath = path
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return { openNewTab, setIFramePath, active, reset }
|
|
103
|
-
}
|
|
1
|
+
import { useRouter } from 'vue-router'
|
|
2
|
+
import useTabpanel from '../hooks/useTabpanel'
|
|
3
|
+
import { throttle } from 'lodash-es'
|
|
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 'ulidx'
|
|
10
|
+
import { MittType, useEmitter } from './useTabMitt'
|
|
11
|
+
|
|
12
|
+
let iframePath: string
|
|
13
|
+
export default () => {
|
|
14
|
+
const router = useRouter()
|
|
15
|
+
const { active, hasTab, pageShown, reset, canAddTab ,renewTab} = useTabpanel()
|
|
16
|
+
const emitter = useEmitter()
|
|
17
|
+
/**
|
|
18
|
+
* 打开新的TAB页面
|
|
19
|
+
* @param tab
|
|
20
|
+
* @param to
|
|
21
|
+
*/
|
|
22
|
+
const openNewTab = throttle((tab: ITabData,renew=false) => {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
if (!pageShown.value) {
|
|
25
|
+
reject()
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
const tabInfo = defu(tab, { refreshable: true, closable: true, iframe: false })
|
|
29
|
+
if(tabInfo.id && renew && hasTab(tabInfo.id!)){
|
|
30
|
+
renewTab(tab)
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* In the function of openNewTab, if the tab already 'ACTIVE' then do nothing.
|
|
34
|
+
*/
|
|
35
|
+
if (hasTab(tabInfo.id!) && !renew) {
|
|
36
|
+
emitter.emit(MittType.TAB_ACTIVE, { id: tabInfo.id! })
|
|
37
|
+
// active(tabInfo.id!)
|
|
38
|
+
resolve(tabInfo.id)
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
if (!tabInfo.id) {
|
|
42
|
+
tabInfo.id = ulid()
|
|
43
|
+
}
|
|
44
|
+
if (!canAddTab()) {
|
|
45
|
+
reject('Max Size')
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// if (initialed) {
|
|
50
|
+
// // 增加tab
|
|
51
|
+
// let activeTab: ITabItem | null = null
|
|
52
|
+
// for (const tab of unref(tabs)) {
|
|
53
|
+
// tab.active = false
|
|
54
|
+
// }
|
|
55
|
+
// activeTab = {
|
|
56
|
+
// id: tabInfo.id!,
|
|
57
|
+
// title: tabInfo.title,
|
|
58
|
+
// closable: tabInfo.closable!,
|
|
59
|
+
// refreshable: tabInfo.refreshable!,
|
|
60
|
+
// iframe: tabInfo.iframe!,
|
|
61
|
+
// url: tabInfo.iframe ? tab.path : null,
|
|
62
|
+
// active: true,
|
|
63
|
+
// pages: new Stack<ITabPage>()
|
|
64
|
+
// } as ITabItem
|
|
65
|
+
// addTab(activeTab).finally(() => {
|
|
66
|
+
// toPage(tab, tabInfo)
|
|
67
|
+
// resolve(tabInfo.id)
|
|
68
|
+
// })
|
|
69
|
+
// } else {
|
|
70
|
+
toPage(tab, tabInfo)
|
|
71
|
+
resolve(tabInfo.id)
|
|
72
|
+
// }
|
|
73
|
+
})
|
|
74
|
+
}, 500)
|
|
75
|
+
const toPage = (tab: ITabData, tabInfo: any) => {
|
|
76
|
+
const __tab = encodeTabInfo(tabInfo)
|
|
77
|
+
let query = defu(
|
|
78
|
+
{
|
|
79
|
+
__tab
|
|
80
|
+
},
|
|
81
|
+
tab.query
|
|
82
|
+
) as Record<string, string>
|
|
83
|
+
let path
|
|
84
|
+
if (!tab.iframe) {
|
|
85
|
+
const url = uriDecode(tab.path)
|
|
86
|
+
path = url.path
|
|
87
|
+
query = defu(url.query, query)
|
|
88
|
+
} else {
|
|
89
|
+
const __src = encodeURIComponent(tab.path as string)
|
|
90
|
+
path = iframePath
|
|
91
|
+
query['__src'] = __src
|
|
92
|
+
}
|
|
93
|
+
router.push({
|
|
94
|
+
path,
|
|
95
|
+
query
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
const setIFramePath = (path: string) => {
|
|
99
|
+
iframePath = path
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return { openNewTab, setIFramePath, active, reset }
|
|
103
|
+
}
|