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.
@@ -1,5 +1,13 @@
1
1
  import type { ITabData, ITabItem, ITabPage } from '../model/TabModel'
2
- import { defineComponent, onActivated, onUnmounted, ref, unref } from 'vue'
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
- setup() {
174
- // onMounted(() => {
175
- // addCache(cacheName)
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 class="cache-page-wrapper" id={'W-' + tabInfo.id}>
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
  }
@@ -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
- let combinateMessage = { ...allLangs() }
63
- if (!localeI18n) {
64
- combinateMessage = { ...allLangs(), ...localeI18n.messages }
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: localeI18n.locale,
71
+ locale: 'zh-CN',
69
72
  fallbackLocale: 'en',
70
73
  messages: combinateMessage
71
74
  })
@@ -1,8 +1,8 @@
1
1
  export default {
2
2
  VueStackTab: {
3
3
  close: 'close',
4
- closeLefts: 'close lefts',
5
- closeRights: 'close rights',
4
+ closeLeft: 'close left',
5
+ closeRight: 'close right',
6
6
  closeOthers: 'close others',
7
7
  closeAll: 'close all',
8
8
  reload: 'reload',
@@ -1,8 +1,8 @@
1
1
  export default {
2
2
  VueStackTab: {
3
3
  close: '关闭',
4
- closeLefts: '关闭左侧',
5
- closeRights: '关闭右侧',
4
+ closeLeft: '关闭左侧',
5
+ closeRight: '关闭右侧',
6
6
  closeOthers: '关闭其他',
7
7
  closeAll: '关闭所有',
8
8
  reload: '刷新',
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
  }