vue-stack-tabs 2.3.0 → 2.5.0

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,9 +1,8 @@
1
- import { getCurrentInstance } from 'vue'
2
- import type { ComponentInternalInstance } from 'vue'
3
1
  import type { LocationQueryRaw, RouteLocationPathRaw } from 'vue-router'
4
2
  import { isNavigationFailure, useRoute, useRouter } from 'vue-router'
5
3
 
6
4
  import useTabPanel from './useTabPanel'
5
+ import { resolveTabPageContext } from './tabPageContext'
7
6
  import {
8
7
  parseUrl,
9
8
  cloneLocationQuery,
@@ -22,30 +21,26 @@ import { createPageId } from '../utils/tabInfoEncoder'
22
21
  * useTabRouter - 标签内路由 Hook
23
22
  *
24
23
  * 职责:在单个标签内实现「前进/后退」栈式导航,以及滚动位置的记录与恢复
25
- * 使用范围:仅在标签内的页面组件中使用,依赖 StackTabs 通过 cloneVNode 注入的 tId / pId
24
+ * 使用范围:仅在标签内的页面组件中使用;页面上下文由缓存包装组件 provide,
25
+ * 通过 tabPageContext 解析(兼容旧版 attrs / props 注入)。
26
26
  *
27
27
  * 主要 API:
28
28
  * - forward(to) 前进:push 新页面到该标签的 pages 栈
29
29
  * - backward(to, backQuery) 后退:pop 栈顶、驱逐缓存,跳转到新栈顶
30
30
  * - addScrollTarget(...) 注册需要记录滚动位置的选择器
31
+ * - tabId / pageId 当前页面所属标签与缓存页 id(只读)
31
32
  */
32
33
  export default function useTabRouter() {
33
- const instance = getCurrentInstance() as ComponentInternalInstance
34
- const { attrs, props } = instance
34
+ const pageContext = resolveTabPageContext()
35
35
 
36
- /**
37
- * 当前标签 ID。
38
- * StackTabs 在 StackTabs.vue 的 tabWrapper 里通过 cloneVNode(Node, { tId, pId }) 注入,
39
- * 未在子组件 setup 中声明为 prop 的属性会落入 attrs,
40
- * 因此优先读 attrs.tId,再 fallback 到 props.tId。
41
- */
42
- const tabId = (attrs.tId ?? props.tId) as string
36
+ /** 当前标签 ID,用于定位页面栈与标签激活状态。 */
37
+ const tabId = pageContext?.tabId ?? ''
43
38
 
44
39
  /**
45
40
  * 当前页面的缓存 ID(即 cacheName / keep-alive include 中的名称)。
46
41
  * 用于 addScrollTarget 向 useTabPanel 绑定该页面的可滚动容器选择器。
47
42
  */
48
- const pageId = (attrs.pId ?? props.pId) as string
43
+ const pageId = pageContext?.pageId ?? ''
49
44
 
50
45
  const route = useRoute()
51
46
  const router = useRouter()
@@ -249,6 +244,8 @@ export default function useTabRouter() {
249
244
  return {
250
245
  forward,
251
246
  backward,
252
- addScrollTarget
247
+ addScrollTarget,
248
+ tabId,
249
+ pageId
253
250
  }
254
251
  }