vue-stack-tabs 0.1.20 → 0.1.21
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/src/lib/StackTabs.vue.d.ts +12 -32
- package/dist/src/lib/hooks/useTabRouter.d.ts +1 -0
- package/dist/src/lib/hooks/useTabpanel.d.ts +2 -0
- package/dist/src/lib/i18n/index.d.ts +4 -1
- package/dist/src/lib/i18n/lang/en.d.ts +2 -2
- package/dist/src/lib/i18n/lang/zh-CN.d.ts +2 -2
- package/dist/src/lib/index.d.ts +1 -1
- package/dist/style.css +1 -1
- package/dist/vue-stack-tabs.es.js +1281 -1226
- package/dist/vue-stack-tabs.umd.js +3 -3
- package/package.json +1 -1
- package/src/lib/StackTabs.vue +16 -11
- package/src/lib/components/ContextMenu/index.vue +2 -2
- package/src/lib/hooks/useTabRouter.ts +11 -5
- package/src/lib/hooks/useTabpanel.tsx +77 -7
- package/src/lib/i18n/index.ts +8 -5
- package/src/lib/i18n/lang/en.ts +2 -2
- package/src/lib/i18n/lang/zh-CN.ts +2 -2
- package/src/lib/index.ts +1 -4
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { ITabData, ITabItem, ITabPage } from '../model/TabModel'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
defineComponent,
|
|
4
|
+
onActivated,
|
|
5
|
+
onDeactivated,
|
|
6
|
+
onMounted,
|
|
7
|
+
onUnmounted,
|
|
8
|
+
ref,
|
|
9
|
+
unref
|
|
10
|
+
} from 'vue'
|
|
3
11
|
import type { DefineComponent, VNode } from 'vue'
|
|
4
12
|
import { useRouter } from 'vue-router'
|
|
5
13
|
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
@@ -19,8 +27,10 @@ const components = new Map<string, any>()
|
|
|
19
27
|
const deletableCache = new Set<String>()
|
|
20
28
|
const pageShown = ref<boolean>(true)
|
|
21
29
|
const SESSION_TAB_NAME = 'stacktab-active-tab'
|
|
30
|
+
const pageScroller = new Map<string, Map<string, any>>()
|
|
22
31
|
let initialed = false
|
|
23
32
|
let max = 0
|
|
33
|
+
let scrollbar = false
|
|
24
34
|
export default () => {
|
|
25
35
|
const router = useRouter()
|
|
26
36
|
const emitter = useEmitter()
|
|
@@ -170,23 +180,37 @@ export default () => {
|
|
|
170
180
|
components: {
|
|
171
181
|
DynamicComponent: component
|
|
172
182
|
},
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
183
|
+
emits: {
|
|
184
|
+
onLoaded: null
|
|
185
|
+
},
|
|
186
|
+
setup(props, context) {
|
|
187
|
+
onMounted(() => {
|
|
188
|
+
context.emit('onLoaded')
|
|
189
|
+
addPageScroller(cacheName, '.cache-page-wrapper')
|
|
190
|
+
})
|
|
191
|
+
onDeactivated(() => {
|
|
192
|
+
saveScroller(cacheName)
|
|
193
|
+
})
|
|
177
194
|
onActivated(() => {
|
|
195
|
+
restoreScroller(cacheName)
|
|
196
|
+
console.log(pageScroller.get(cacheName))
|
|
178
197
|
removeDeletableCache()
|
|
179
198
|
component.props = null
|
|
180
199
|
})
|
|
181
200
|
onUnmounted(() => {
|
|
182
201
|
console.log('on unMounted', cacheName)
|
|
202
|
+
removeScroller(cacheName)
|
|
183
203
|
// setTimeout(() => {
|
|
184
204
|
// 刷新时重置路由
|
|
185
205
|
// pageShown.value = true
|
|
186
206
|
// }, 500)
|
|
187
207
|
})
|
|
188
208
|
return () => (
|
|
189
|
-
<div
|
|
209
|
+
<div
|
|
210
|
+
class="cache-page-wrapper"
|
|
211
|
+
id={'W-' + tabInfo.id}
|
|
212
|
+
style={[scrollbar ? 'overflow:auto' : 'overflow:hidden']}
|
|
213
|
+
>
|
|
190
214
|
<dynamic-component tId={tabInfo.id} pId={cacheName} />
|
|
191
215
|
<PageLoading tId={tabInfo.id!} />
|
|
192
216
|
</div>
|
|
@@ -208,6 +232,47 @@ export default () => {
|
|
|
208
232
|
addCache(cacheName)
|
|
209
233
|
return cacheComponent
|
|
210
234
|
}
|
|
235
|
+
const restoreScroller = (pageId: string) => {
|
|
236
|
+
const scroller = pageScroller.get(pageId)
|
|
237
|
+
if (scroller) {
|
|
238
|
+
for (const key of scroller.keys()) {
|
|
239
|
+
if (document.querySelector(key)) {
|
|
240
|
+
const result = scroller.get(key)!
|
|
241
|
+
document.querySelector(key)!.scrollTop = result.top
|
|
242
|
+
document.querySelector(key)!.scrollLeft = result.left
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const saveScroller = (pageId: string) => {
|
|
248
|
+
const scroller = pageScroller.get(pageId)
|
|
249
|
+
if (scroller) {
|
|
250
|
+
for (const key of scroller.keys()) {
|
|
251
|
+
const result = {
|
|
252
|
+
top: document.querySelector(key)?.scrollTop ?? 0,
|
|
253
|
+
left: document.querySelector(key)?.scrollLeft ?? 0
|
|
254
|
+
}
|
|
255
|
+
scroller.set(key, result)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const removeScroller = (pageId: string) => {
|
|
261
|
+
const scroller = pageScroller.get(pageId)!
|
|
262
|
+
if (scroller) {
|
|
263
|
+
scroller.clear()
|
|
264
|
+
pageScroller.delete(pageId)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const addPageScroller = (pageId: string, ...scrollerIds: string[]) => {
|
|
268
|
+
if (!pageScroller.has(pageId)) {
|
|
269
|
+
pageScroller.set(pageId, new Map<string, number>())
|
|
270
|
+
}
|
|
271
|
+
const scroller = pageScroller.get(pageId)!
|
|
272
|
+
for (const sId of scrollerIds) {
|
|
273
|
+
scroller.set(sId, { top: 0, left: 0 })
|
|
274
|
+
}
|
|
275
|
+
}
|
|
211
276
|
/**
|
|
212
277
|
* if id is null , then remove all tab that deleted is true
|
|
213
278
|
* @param id
|
|
@@ -492,6 +557,9 @@ export default () => {
|
|
|
492
557
|
const setMaxSize = (size: number) => {
|
|
493
558
|
max = size
|
|
494
559
|
}
|
|
560
|
+
const setGlobalScroll = (globalScroll: boolean) => {
|
|
561
|
+
scrollbar = globalScroll
|
|
562
|
+
}
|
|
495
563
|
|
|
496
564
|
return {
|
|
497
565
|
tabs,
|
|
@@ -522,6 +590,8 @@ export default () => {
|
|
|
522
590
|
markDeletableCache,
|
|
523
591
|
removeDeletableCache,
|
|
524
592
|
refreshTab,
|
|
525
|
-
refreshAllTabs
|
|
593
|
+
refreshAllTabs,
|
|
594
|
+
addPageScroller,
|
|
595
|
+
setGlobalScroll
|
|
526
596
|
}
|
|
527
597
|
}
|
package/src/lib/i18n/index.ts
CHANGED
|
@@ -58,14 +58,17 @@ export default () => {
|
|
|
58
58
|
return message
|
|
59
59
|
}
|
|
60
60
|
// const localeI18n = inject('locales') as { locale: string; messages: object }
|
|
61
|
-
const getI18n = (localeI18n?: any) => {
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
61
|
+
const getI18n = (localeI18n?: { locale: string; messages: any }[]) => {
|
|
62
|
+
const combinateMessage = { ...allLangs() }
|
|
63
|
+
if (localeI18n) {
|
|
64
|
+
for (const l of localeI18n!) {
|
|
65
|
+
combinateMessage[l.locale] = l.messages
|
|
66
|
+
}
|
|
67
|
+
// combinateMessage = { ...allLangs(), ...localeI18n.messages }
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
return createI18n({
|
|
68
|
-
locale:
|
|
71
|
+
locale: 'zh-CN',
|
|
69
72
|
fallbackLocale: 'en',
|
|
70
73
|
messages: combinateMessage
|
|
71
74
|
})
|
package/src/lib/i18n/lang/en.ts
CHANGED
package/src/lib/index.ts
CHANGED
|
@@ -27,10 +27,7 @@ declare module '@vue/runtime-core' {
|
|
|
27
27
|
|
|
28
28
|
export { IFrame, useTabLoading, useTabRouter, useStackTab, TabHeaderButton, StackTab }
|
|
29
29
|
export default {
|
|
30
|
-
install(
|
|
31
|
-
Vue: App,
|
|
32
|
-
options: { locale: string; messages: any } = { locale: 'zh-CN', messages: {} }
|
|
33
|
-
): void {
|
|
30
|
+
install(Vue: App, options?: { locale: string; messages: any }[]): void {
|
|
34
31
|
tabVersion(import.meta.env.PACKAGE_VERSION)
|
|
35
32
|
Vue.component('VueStackTabs', StackTab).use(useTabMitt).use(i18n().getI18n(options))
|
|
36
33
|
}
|