vue-stack-tabs 0.1.16 → 0.1.18

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.
@@ -1,93 +1,93 @@
1
- import { defu } from 'defu'
2
-
3
- import { getCurrentInstance } from 'vue'
4
- import type { ComponentInternalInstance } from 'vue'
5
- import { type RouteLocationPathRaw, useRoute, useRouter } from 'vue-router'
6
-
7
- import useTabpanel from '@/lib/hooks/useTabpanel'
8
- import { uriDecode } from '@/lib/utils/UriHelper'
9
- export default () => {
10
- const { attrs } = getCurrentInstance() as ComponentInternalInstance
11
- const { pageShown, getTab, markDeletableCache, removeComponent, getComponent } = useTabpanel()
12
- const route = useRoute()
13
- const router = useRouter()
14
- let currentId = ''
15
- // const currentPageId = ''
16
- let currentTab = ''
17
-
18
- currentId = attrs.tId as string
19
- // currentPageId = attrs.pId as string
20
- currentTab = route.query.__tab as string
21
- const forward = (to: RouteLocationPathRaw) => {
22
- pageShown.value = false
23
- const query = defu(
24
- {
25
- __tab: currentTab
26
- },
27
- to.query
28
- )
29
- router.push({
30
- path: to.path,
31
- query
32
- })
33
- }
34
- /**
35
- * 返回
36
- * @param to url or step
37
- * @param query 返回时要加截的数据
38
- */
39
- const backward = (to: number | string, query?: Object) => {
40
- pageShown.value = false
41
-
42
- const tab = getTab(currentId)
43
- if (!tab) {
44
- return
45
- }
46
- const tabStack = tab.pages
47
- let absTo = 0
48
- if (typeof to === 'number') {
49
- absTo = Math.abs(to)
50
- } else {
51
- let index = 1
52
- let hasPath = false
53
- const pageItems = tabStack.list()
54
- const url = uriDecode(to)
55
- query = defu(url.query, query)
56
- for (let i = tabStack.size() - 2; i >= 0; i--) {
57
- if (pageItems[i].path === url.path) {
58
- hasPath = true
59
- break
60
- }
61
- index += 1
62
- }
63
- if (hasPath) {
64
- absTo = index
65
- }
66
- }
67
-
68
- if (absTo === 0 || tabStack!.size() <= absTo) {
69
- return
70
- }
71
- // const removeCaches = new Set()
72
- for (let i = 0; i < absTo; i++) {
73
- const popRoute = tabStack.pop()
74
- removeComponent(popRoute!.id)
75
- markDeletableCache(popRoute!.id)
76
- }
77
- const pageRoute = tabStack?.peek()
78
- const component = getComponent(pageRoute!.id)
79
- if (component !== null && component !== undefined) {
80
- const sourceComponent = component.components.DynamicComponent
81
- sourceComponent.props = defu(query, sourceComponent.props)
82
- }
83
- router.push({
84
- path: pageRoute!.path,
85
- query: pageRoute!.query
86
- })
87
- }
88
-
89
- return {
90
- forward,
91
- backward
92
- }
93
- }
1
+ import { defu } from 'defu'
2
+
3
+ import { getCurrentInstance } from 'vue'
4
+ import type { ComponentInternalInstance } from 'vue'
5
+ import { type RouteLocationPathRaw, useRoute, useRouter } from 'vue-router'
6
+
7
+ import useTabpanel from '@/lib/hooks/useTabpanel'
8
+ import { uriDecode } from '@/lib/utils/UriHelper'
9
+ export default () => {
10
+ const { attrs } = getCurrentInstance() as ComponentInternalInstance
11
+ const { pageShown, getTab, markDeletableCache, removeComponent, getComponent } = useTabpanel()
12
+ const route = useRoute()
13
+ const router = useRouter()
14
+ let currentId = ''
15
+ // const currentPageId = ''
16
+ let currentTab = ''
17
+
18
+ currentId = attrs.tId as string
19
+ // currentPageId = attrs.pId as string
20
+ currentTab = route.query.__tab as string
21
+ const forward = (to: RouteLocationPathRaw) => {
22
+ pageShown.value = false
23
+ const query = defu(
24
+ {
25
+ __tab: currentTab
26
+ },
27
+ to.query
28
+ )
29
+ router.push({
30
+ path: to.path,
31
+ query
32
+ })
33
+ }
34
+ /**
35
+ * 返回
36
+ * @param to url or step
37
+ * @param query 返回时要加截的数据
38
+ */
39
+ const backward = (to: number | string, query?: Object) => {
40
+ pageShown.value = false
41
+
42
+ const tab = getTab(currentId)
43
+ if (!tab) {
44
+ return
45
+ }
46
+ const tabStack = tab.pages
47
+ let absTo = 0
48
+ if (typeof to === 'number') {
49
+ absTo = Math.abs(to)
50
+ } else {
51
+ let index = 1
52
+ let hasPath = false
53
+ const pageItems = tabStack.list()
54
+ const url = uriDecode(to)
55
+ query = defu(url.query, query)
56
+ for (let i = tabStack.size() - 2; i >= 0; i--) {
57
+ if (pageItems[i].path === url.path) {
58
+ hasPath = true
59
+ break
60
+ }
61
+ index += 1
62
+ }
63
+ if (hasPath) {
64
+ absTo = index
65
+ }
66
+ }
67
+
68
+ if (absTo === 0 || tabStack!.size() <= absTo) {
69
+ return
70
+ }
71
+ // const removeCaches = new Set()
72
+ for (let i = 0; i < absTo; i++) {
73
+ const popRoute = tabStack.pop()
74
+ removeComponent(popRoute!.id)
75
+ markDeletableCache(popRoute!.id)
76
+ }
77
+ const pageRoute = tabStack?.peek()
78
+ const component = getComponent(pageRoute!.id)
79
+ if (component !== null && component !== undefined) {
80
+ const sourceComponent = component.components.DynamicComponent
81
+ sourceComponent.props = defu(query, sourceComponent.props)
82
+ }
83
+ router.push({
84
+ path: pageRoute!.path,
85
+ query: pageRoute!.query
86
+ })
87
+ }
88
+
89
+ return {
90
+ forward,
91
+ backward
92
+ }
93
+ }