vue-stack-tabs 0.1.11 → 0.1.13
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/{types → dist}/src/lib/hooks/useStackTab.d.ts +2 -2
- package/{types → dist}/src/lib/hooks/useTabpanel.d.ts +6 -2
- package/{types → dist}/src/lib/index.d.ts +7 -1
- package/{types → dist}/src/lib/model/TabModel.d.ts +2 -1
- package/dist/style.css +1 -1
- package/dist/vue-stack-tabs.es.js +2340 -2321
- package/dist/vue-stack-tabs.umd.js +10 -10
- package/package.json +3 -4
- package/src/lib/StackTabs.vue +136 -126
- package/src/lib/assets/style/common/mixins.scss +45 -45
- package/src/lib/assets/style/common/var.scss +65 -65
- package/src/lib/assets/style/icon.scss +93 -93
- package/src/lib/assets/style/index.scss +4 -4
- package/src/lib/assets/style/overlayer.scss +40 -40
- package/src/lib/assets/style/stackTab.scss +395 -395
- package/src/lib/assets/style/transition.scss +40 -40
- package/src/lib/banner.ts +51 -51
- package/src/lib/components/ContextMenu/ContextMenuItem.vue +15 -15
- package/src/lib/components/ContextMenu/index.vue +129 -129
- package/src/lib/components/OverlayLoading/Component.vue +182 -191
- package/src/lib/components/OverlayLoading/api.ts +31 -31
- package/src/lib/components/OverlayLoading/helpers.ts +31 -31
- package/src/lib/components/OverlayLoading/index.ts +12 -12
- package/src/lib/components/OverlayLoading/loaders/bars.vue +79 -79
- package/src/lib/components/OverlayLoading/loaders/dots.vue +92 -92
- package/src/lib/components/OverlayLoading/loaders/index.ts +9 -9
- package/src/lib/components/OverlayLoading/loaders/spinner.vue +41 -41
- package/src/lib/components/TabHeader/TabHeaderButton.vue +35 -35
- package/src/lib/components/TabHeader/TabHeaderItem.vue +63 -63
- package/src/lib/components/TabHeader/TabHeaderScroll.vue +240 -240
- package/src/lib/components/TabHeader/index.vue +135 -135
- package/src/lib/hooks/useContextMenu.ts +50 -50
- package/src/lib/hooks/useStackTab.ts +74 -65
- package/src/lib/hooks/useTabLoading.ts +34 -34
- package/src/lib/hooks/useTabRouter.ts +94 -94
- package/src/lib/hooks/useTabpanel.tsx +516 -491
- package/src/lib/i18n/index.ts +72 -72
- package/src/lib/i18n/lang/en.ts +15 -15
- package/src/lib/i18n/lang/zh-CN.ts +15 -15
- package/src/lib/iframe.vue +7 -7
- package/src/lib/index.ts +32 -23
- package/src/lib/model/TabModel.ts +178 -169
- package/src/lib/utils/TabIdHelper.ts +70 -70
- package/src/lib/utils/TabScrollHelper.ts +104 -104
- package/src/lib/utils/UriHelper.ts +22 -22
- /package/{types → dist}/index.d.ts +0 -0
- /package/{types → dist}/src/lib/StackTabs.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/banner.d.ts +0 -0
- /package/{types → dist}/src/lib/components/ContextMenu/ContextMenuItem.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/ContextMenu/index.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/OverlayLoading/Component.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/OverlayLoading/api.d.ts +0 -0
- /package/{types → dist}/src/lib/components/OverlayLoading/helpers.d.ts +0 -0
- /package/{types → dist}/src/lib/components/OverlayLoading/index.d.ts +0 -0
- /package/{types → dist}/src/lib/components/OverlayLoading/loaders/bars.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/OverlayLoading/loaders/dots.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/OverlayLoading/loaders/index.d.ts +0 -0
- /package/{types → dist}/src/lib/components/OverlayLoading/loaders/spinner.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/TabHeader/TabHeaderButton.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/TabHeader/TabHeaderItem.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/TabHeader/TabHeaderScroll.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/components/TabHeader/index.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/hooks/useContextMenu.d.ts +0 -0
- /package/{types → dist}/src/lib/hooks/useTabLoading.d.ts +0 -0
- /package/{types → dist}/src/lib/hooks/useTabRouter.d.ts +0 -0
- /package/{types → dist}/src/lib/i18n/index.d.ts +0 -0
- /package/{types → dist}/src/lib/i18n/lang/en.d.ts +0 -0
- /package/{types → dist}/src/lib/i18n/lang/zh-CN.d.ts +0 -0
- /package/{types → dist}/src/lib/iframe.vue.d.ts +0 -0
- /package/{types → dist}/src/lib/utils/TabIdHelper.d.ts +0 -0
- /package/{types → dist}/src/lib/utils/TabScrollHelper.d.ts +0 -0
- /package/{types → dist}/src/lib/utils/UriHelper.d.ts +0 -0
|
@@ -1,491 +1,516 @@
|
|
|
1
|
-
import type { ITabData, ITabItem, ITabPage } from '../model/TabModel'
|
|
2
|
-
import { defineComponent, onActivated, onUnmounted, ref, unref } from 'vue'
|
|
3
|
-
import type { DefineComponent, VNode } from 'vue'
|
|
4
|
-
import { useRouter } from 'vue-router'
|
|
5
|
-
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
6
|
-
import { ulid } from 'ulidx'
|
|
7
|
-
import { encodeTabInfo, createPageId, decodeTabInfo } from '../utils/TabIdHelper'
|
|
8
|
-
import { defu } from 'defu'
|
|
9
|
-
import { Stack } from '../model/TabModel'
|
|
10
|
-
import { uriDecode } from '../utils/UriHelper'
|
|
11
|
-
|
|
12
|
-
const tabs = ref<ITabItem[]>([])
|
|
13
|
-
const defaultTabs: ITabItem[] = []
|
|
14
|
-
// cache
|
|
15
|
-
const caches = ref<string[]>([])
|
|
16
|
-
// Dynamic components
|
|
17
|
-
const components = new Map<string, any>()
|
|
18
|
-
const deletableCache = new Set<String>()
|
|
19
|
-
const pageShown = ref<boolean>(true)
|
|
20
|
-
const SESSION_TAB_NAME = 'stacktab-active-tab'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
pages
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
const
|
|
92
|
-
tabs.value
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
for (
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
for (
|
|
326
|
-
if (
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
caches.value
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
tabs.value[i]
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
1
|
+
import type { ITabData, ITabItem, ITabPage } from '../model/TabModel'
|
|
2
|
+
import { defineComponent, onActivated, onUnmounted, ref, unref } from 'vue'
|
|
3
|
+
import type { DefineComponent, VNode } from 'vue'
|
|
4
|
+
import { useRouter } from 'vue-router'
|
|
5
|
+
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
6
|
+
import { ulid } from 'ulidx'
|
|
7
|
+
import { encodeTabInfo, createPageId, decodeTabInfo } from '../utils/TabIdHelper'
|
|
8
|
+
import { defu } from 'defu'
|
|
9
|
+
import { Stack } from '../model/TabModel'
|
|
10
|
+
import { uriDecode } from '../utils/UriHelper'
|
|
11
|
+
|
|
12
|
+
const tabs = ref<ITabItem[]>([])
|
|
13
|
+
const defaultTabs: ITabItem[] = []
|
|
14
|
+
// cache
|
|
15
|
+
const caches = ref<string[]>([])
|
|
16
|
+
// Dynamic components
|
|
17
|
+
const components = new Map<string, any>()
|
|
18
|
+
const deletableCache = new Set<String>()
|
|
19
|
+
const pageShown = ref<boolean>(true)
|
|
20
|
+
const SESSION_TAB_NAME = 'stacktab-active-tab'
|
|
21
|
+
let max =0;
|
|
22
|
+
export default () => {
|
|
23
|
+
const router = useRouter()
|
|
24
|
+
const size = (): number => {
|
|
25
|
+
return tabs.value.length
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Init the Tab list
|
|
29
|
+
*/
|
|
30
|
+
const initial = (staticTabs: ITabData[]) => {
|
|
31
|
+
// add default tabs
|
|
32
|
+
defaultTabs.splice(0)
|
|
33
|
+
for (const item of staticTabs) {
|
|
34
|
+
// const id = ulid()
|
|
35
|
+
const fullItem = defu(item, { id: ulid() })
|
|
36
|
+
const __tab = encodeTabInfo(fullItem)
|
|
37
|
+
const uri = uriDecode(fullItem.path)
|
|
38
|
+
const config = defu(fullItem, {
|
|
39
|
+
closable: true,
|
|
40
|
+
refreshable: true,
|
|
41
|
+
iframe: false
|
|
42
|
+
})
|
|
43
|
+
const cacheName = createPageId(fullItem.id, uri.path, uri.query)
|
|
44
|
+
const page: ITabPage = {
|
|
45
|
+
id: cacheName,
|
|
46
|
+
tabId: fullItem.id,
|
|
47
|
+
path: uri.path,
|
|
48
|
+
query: defu(uri.query, { __tab })
|
|
49
|
+
}
|
|
50
|
+
const pages = new Stack<ITabPage>()
|
|
51
|
+
pages.push(page)
|
|
52
|
+
const tab: ITabItem = {
|
|
53
|
+
id: fullItem.id,
|
|
54
|
+
title: config.title,
|
|
55
|
+
closable: config.closable,
|
|
56
|
+
refreshable: config.refreshable,
|
|
57
|
+
iframe: config.iframe,
|
|
58
|
+
active: false,
|
|
59
|
+
pages
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
defaultTabs.push(tab)
|
|
63
|
+
tabs.value.push(tab)
|
|
64
|
+
caches.value.push(cacheName)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// add temp tab from session
|
|
68
|
+
const tempTab = window.sessionStorage.getItem(SESSION_TAB_NAME)
|
|
69
|
+
if (tempTab !== null && tempTab !== undefined) {
|
|
70
|
+
// const tempItems = JSON.parse(window.sessionStorage.getItem('tabItems')!)
|
|
71
|
+
const temp= JSON.parse(tempTab,(k,v)=>{
|
|
72
|
+
if(k==='pages'){
|
|
73
|
+
return new Stack<ITabPage>(v)
|
|
74
|
+
}else{
|
|
75
|
+
return v;
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
// const temp = defu({ pages: new Stack<ITabPage>() }, tempItems) as ITabItem
|
|
79
|
+
let hasTab = false
|
|
80
|
+
for (const tab of tabs.value) {
|
|
81
|
+
if (tab.id === temp.id) {
|
|
82
|
+
hasTab = true
|
|
83
|
+
break
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!hasTab) {
|
|
87
|
+
tabs.value.push(temp)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const hasTab = (id: string) => {
|
|
92
|
+
for (const tab of tabs.value) {
|
|
93
|
+
if (tab.id === id) {
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
const canAddTab = ()=>{
|
|
100
|
+
return (max<=0||(max>0 && max> tabs.value.length))
|
|
101
|
+
}
|
|
102
|
+
const addTab = (tab: ITabItem) => {
|
|
103
|
+
return new Promise((resolve)=>{
|
|
104
|
+
tabs.value.push(tab)
|
|
105
|
+
resolve(true)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
const getTab = (id: string) => {
|
|
110
|
+
for (const tab of tabs.value) {
|
|
111
|
+
if (tab.id === id) {
|
|
112
|
+
return tab
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return null
|
|
116
|
+
}
|
|
117
|
+
const addPage = (route: RouteLocationNormalizedLoaded, component: VNode): DefineComponent => {
|
|
118
|
+
let cacheComponent: DefineComponent
|
|
119
|
+
const tabInfo = decodeTabInfo(route.query.__tab as string)
|
|
120
|
+
const cacheName = createPageId(tabInfo.id!, route.path, route.query.valueOf())
|
|
121
|
+
const src = route.query.__src
|
|
122
|
+
// 增加tab
|
|
123
|
+
let activeTab: ITabItem | null = null
|
|
124
|
+
for (const tab of unref(tabs)) {
|
|
125
|
+
tab.active = false
|
|
126
|
+
if (tab.id === tabInfo.id) {
|
|
127
|
+
activeTab = tab as ITabItem
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const page: ITabPage = {
|
|
131
|
+
id: cacheName,
|
|
132
|
+
tabId: tabInfo.id!,
|
|
133
|
+
path: route.path,
|
|
134
|
+
query: route.query as Record<string, string>
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (activeTab === null) {
|
|
138
|
+
const pages = new Stack<ITabPage>()
|
|
139
|
+
pages.push(page)
|
|
140
|
+
activeTab = {
|
|
141
|
+
id: tabInfo.id!,
|
|
142
|
+
title: tabInfo.title,
|
|
143
|
+
closable: tabInfo.closable!,
|
|
144
|
+
refreshable: tabInfo.refreshable!,
|
|
145
|
+
iframe: tabInfo.iframe!,
|
|
146
|
+
url: decodeURIComponent(src as string),
|
|
147
|
+
active: true,
|
|
148
|
+
pages
|
|
149
|
+
}
|
|
150
|
+
addTab(activeTab)
|
|
151
|
+
} else {
|
|
152
|
+
activeTab.active = true
|
|
153
|
+
if (activeTab.pages.isEmpty() || activeTab.pages.peek()!.id !== page.id) {
|
|
154
|
+
activeTab.pages.push(page)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
updateSession(activeTab)
|
|
158
|
+
// const cacheSet = new Set(caches.value)
|
|
159
|
+
if (components.has(cacheName)) {
|
|
160
|
+
cacheComponent = components.get(cacheName)!
|
|
161
|
+
} else {
|
|
162
|
+
// 增加控件
|
|
163
|
+
cacheComponent = defineComponent({
|
|
164
|
+
name: cacheName!,
|
|
165
|
+
components: {
|
|
166
|
+
DynamicComponent: component
|
|
167
|
+
},
|
|
168
|
+
setup() {
|
|
169
|
+
// onMounted(() => {
|
|
170
|
+
// addCache(cacheName)
|
|
171
|
+
// })
|
|
172
|
+
onActivated(() => {
|
|
173
|
+
removeDeletableCache()
|
|
174
|
+
component.props = null
|
|
175
|
+
})
|
|
176
|
+
onUnmounted(() => {
|
|
177
|
+
console.log('on unMounted', cacheName)
|
|
178
|
+
// setTimeout(() => {
|
|
179
|
+
// 刷新时重置路由
|
|
180
|
+
// pageShown.value = true
|
|
181
|
+
// }, 500)
|
|
182
|
+
})
|
|
183
|
+
return () => (
|
|
184
|
+
<div class="cache-page-wrapper" id={tabInfo.id}>
|
|
185
|
+
<dynamic-component tId={tabInfo.id} pId={cacheName} />
|
|
186
|
+
</div>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
components.set(cacheName, cacheComponent)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
//
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 加入缓存
|
|
197
|
+
// const cacheSet = new Set(caches.value)
|
|
198
|
+
// if (routerAlive.value) {
|
|
199
|
+
// if (!cacheSet.has(cacheName)) {
|
|
200
|
+
// caches.value.push(cacheName)
|
|
201
|
+
// }
|
|
202
|
+
// }
|
|
203
|
+
addCache(cacheName)
|
|
204
|
+
return cacheComponent
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* if id is null , then remove all tab that deleted is true
|
|
208
|
+
* @param id
|
|
209
|
+
*/
|
|
210
|
+
const removeTab = (id: string): string => {
|
|
211
|
+
let activeTabId = ''
|
|
212
|
+
for (let i = tabs.value.length - 1; i >= 0; i--) {
|
|
213
|
+
if (id === unref(tabs)[i].id) {
|
|
214
|
+
//if it's not closable then return
|
|
215
|
+
if (!unref(tabs)[i].closable) {
|
|
216
|
+
return id
|
|
217
|
+
}
|
|
218
|
+
for (const item of unref(tabs)[i].pages.list()) {
|
|
219
|
+
removeComponent(item.id)
|
|
220
|
+
markDeletableCache(item.id)
|
|
221
|
+
}
|
|
222
|
+
unref(tabs)[i].pages.clear()
|
|
223
|
+
if (tabs.value.length > 1 && unref(tabs)[i].active) {
|
|
224
|
+
if (i === 0) {
|
|
225
|
+
activeTabId = unref(tabs)[i + 1].id
|
|
226
|
+
} else {
|
|
227
|
+
activeTabId = unref(tabs)[i - 1].id
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
unref(tabs).splice(i, 1)
|
|
231
|
+
|
|
232
|
+
break
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (activeTabId !== '') {
|
|
236
|
+
active(activeTabId)
|
|
237
|
+
}
|
|
238
|
+
// if remove inactive tab,then we need remove the cache manually.
|
|
239
|
+
removeDeletableCache()
|
|
240
|
+
return activeTabId
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const removeAllTabs = () => {
|
|
244
|
+
const uTabs = unref(tabs)
|
|
245
|
+
for (let i = uTabs.length - 1; i >= 0; i--) {
|
|
246
|
+
if (uTabs[i].closable) {
|
|
247
|
+
for (const item of uTabs[i].pages.list()) {
|
|
248
|
+
removeComponent(item.id)
|
|
249
|
+
markDeletableCache(item.id)
|
|
250
|
+
}
|
|
251
|
+
unref(tabs)[i].pages.clear()
|
|
252
|
+
unref(tabs).splice(i, 1)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
for (const stay of uTabs) {
|
|
256
|
+
if (stay.active) {
|
|
257
|
+
removeDeletableCache()
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// 如果都是非Active状态,就把最后一个active
|
|
262
|
+
active(uTabs[uTabs.length - 1].id)
|
|
263
|
+
}
|
|
264
|
+
const removeOtherTabs = (id: string) => {
|
|
265
|
+
const uTabs = unref(tabs)
|
|
266
|
+
let activeTab
|
|
267
|
+
for (let i = uTabs.length - 1; i >= 0; i--) {
|
|
268
|
+
if (uTabs[i].id === id) {
|
|
269
|
+
activeTab = uTabs[i]
|
|
270
|
+
} else if (uTabs[i].closable && uTabs[i].id !== id) {
|
|
271
|
+
for (const item of uTabs[i].pages.list()) {
|
|
272
|
+
removeComponent(item.id)
|
|
273
|
+
markDeletableCache(item.id)
|
|
274
|
+
}
|
|
275
|
+
unref(tabs)[i].pages.clear()
|
|
276
|
+
unref(tabs).splice(i, 1)
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (!activeTab!.active) {
|
|
280
|
+
active(id)
|
|
281
|
+
} else {
|
|
282
|
+
removeDeletableCache()
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* 关闭左边
|
|
287
|
+
* @param id
|
|
288
|
+
*/
|
|
289
|
+
const removeLeftTabs = (id: string) => {
|
|
290
|
+
let startIndex = -1
|
|
291
|
+
const uTabs = unref(tabs)
|
|
292
|
+
for (let i = 0; i < uTabs.length; i++) {
|
|
293
|
+
if (uTabs[i].id === id) {
|
|
294
|
+
startIndex = i - 1
|
|
295
|
+
break
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
for (let i = startIndex; i >= 0; i--) {
|
|
299
|
+
if (uTabs[i].closable) {
|
|
300
|
+
for (const item of uTabs[i].pages.list()) {
|
|
301
|
+
removeComponent(item.id)
|
|
302
|
+
markDeletableCache(item.id)
|
|
303
|
+
}
|
|
304
|
+
unref(tabs)[i].pages.clear()
|
|
305
|
+
unref(tabs).splice(i, 1)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
for (const stay of uTabs) {
|
|
309
|
+
if (stay.active) {
|
|
310
|
+
removeDeletableCache()
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// 如果都是非Active状态,就把最后一个active
|
|
315
|
+
active(uTabs[0].id)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 关闭右边
|
|
320
|
+
* @param id
|
|
321
|
+
*/
|
|
322
|
+
const removeRightTabs = (id: string) => {
|
|
323
|
+
const uTabs = unref(tabs)
|
|
324
|
+
let startIndex = uTabs.length
|
|
325
|
+
for (let i = 0; i < uTabs.length; i++) {
|
|
326
|
+
if (uTabs[i].id === id) {
|
|
327
|
+
startIndex = i + 1
|
|
328
|
+
break
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
for (let i = uTabs.length - 1; i >= startIndex; i--) {
|
|
332
|
+
if (uTabs[i].closable) {
|
|
333
|
+
for (const item of uTabs[i].pages.list()) {
|
|
334
|
+
removeComponent(item.id)
|
|
335
|
+
markDeletableCache(item.id)
|
|
336
|
+
}
|
|
337
|
+
unref(tabs)[i].pages.clear()
|
|
338
|
+
unref(tabs).splice(i, 1)
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (const stay of uTabs) {
|
|
342
|
+
if (stay.active) {
|
|
343
|
+
removeDeletableCache()
|
|
344
|
+
return
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
active(uTabs[uTabs.length - 1].id)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* 刷新
|
|
352
|
+
*/
|
|
353
|
+
const refreshTab = (id: string) => {
|
|
354
|
+
// const uTabs = unref(tabs)
|
|
355
|
+
for (const uTabs of unref(tabs)) {
|
|
356
|
+
if (uTabs.id === id) {
|
|
357
|
+
const currentPageId = uTabs.pages.peek()?.id
|
|
358
|
+
for (let i = caches.value.length - 1; i >= 0; i--) {
|
|
359
|
+
const cacheId = caches.value[i]
|
|
360
|
+
if (cacheId === currentPageId) {
|
|
361
|
+
caches.value.splice(i, 1)
|
|
362
|
+
// 如果要刷新的是显示的TAB
|
|
363
|
+
if (uTabs.active) {
|
|
364
|
+
pageShown.value = false
|
|
365
|
+
}
|
|
366
|
+
break
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
break
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* 全部刷新
|
|
375
|
+
*/
|
|
376
|
+
const refreshAllTabs = () => {
|
|
377
|
+
const refreshPage = new Set<string>()
|
|
378
|
+
tabs.value.forEach((value) => {
|
|
379
|
+
refreshPage.add(value.pages.peek()!.id)
|
|
380
|
+
})
|
|
381
|
+
for (let i = caches.value.length - 1; i >= 0; i--) {
|
|
382
|
+
const cacheId = caches.value[i]
|
|
383
|
+
if (refreshPage.has(cacheId)) {
|
|
384
|
+
caches.value.splice(i, 1)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
pageShown.value = false
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const addComponent = (id: string, comp: DefineComponent) => {
|
|
391
|
+
components.set(id, comp)
|
|
392
|
+
}
|
|
393
|
+
const getComponent = (id: string) => {
|
|
394
|
+
return components.get(id)
|
|
395
|
+
}
|
|
396
|
+
const removeComponent = (id: string) => {
|
|
397
|
+
components.delete(id)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Delete the cache after new Page loaded.
|
|
402
|
+
* @param cacheName
|
|
403
|
+
*/
|
|
404
|
+
const markDeletableCache = (cacheName: string) => {
|
|
405
|
+
deletableCache.add(cacheName)
|
|
406
|
+
}
|
|
407
|
+
const removeDeletableCache = () => {
|
|
408
|
+
for (let i = caches.value.length - 1; i >= 0; i--) {
|
|
409
|
+
if (deletableCache.has(caches.value[i])) {
|
|
410
|
+
unref(caches).splice(i, 1)
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
deletableCache.clear()
|
|
414
|
+
}
|
|
415
|
+
const removeCache = (cacheName: string) => {
|
|
416
|
+
for (let i = caches.value.length - 1; i >= 0; i--) {
|
|
417
|
+
if (cacheName === caches.value[i]) {
|
|
418
|
+
unref(caches).splice(i, 1)
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const addCache = (cacheName: string) => {
|
|
423
|
+
const cacheSet = new Set(caches.value)
|
|
424
|
+
if (!cacheSet.has(cacheName)) {
|
|
425
|
+
caches.value.push(cacheName)
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* active the tab,
|
|
431
|
+
* @param id
|
|
432
|
+
* @param route
|
|
433
|
+
* @return true if already actived
|
|
434
|
+
*/
|
|
435
|
+
const active = (id: string, route = true) => {
|
|
436
|
+
return new Promise((resolve)=>{
|
|
437
|
+
for (let i = tabs.value.length - 1; i >= 0; i--) {
|
|
438
|
+
const tab = tabs.value[i] as ITabItem
|
|
439
|
+
if (tab.id === id) {
|
|
440
|
+
if (tab.active) {
|
|
441
|
+
break
|
|
442
|
+
} else {
|
|
443
|
+
tab.active = true
|
|
444
|
+
pageShown.value = false
|
|
445
|
+
updateSession(tab)
|
|
446
|
+
if (route) {
|
|
447
|
+
const top = tab.pages.peek()
|
|
448
|
+
router.push({
|
|
449
|
+
path: top!.path,
|
|
450
|
+
query: top!.query
|
|
451
|
+
})
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
} else {
|
|
455
|
+
tabs.value[i].active = false
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
resolve(true)
|
|
459
|
+
})
|
|
460
|
+
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* save current tab info into Browser's session
|
|
464
|
+
* @param id
|
|
465
|
+
*/
|
|
466
|
+
const updateSession = (tab: ITabItem) => {
|
|
467
|
+
// window.sessionStorage.setItem('tabItems', JSON.stringify(currentItems?.values()))
|
|
468
|
+
window.sessionStorage.setItem(SESSION_TAB_NAME, JSON.stringify(tab))
|
|
469
|
+
}
|
|
470
|
+
const reset = () => {
|
|
471
|
+
destroy()
|
|
472
|
+
unref(tabs).push(...defaultTabs)
|
|
473
|
+
active(defaultTabs[0].id)
|
|
474
|
+
}
|
|
475
|
+
const destroy = () => {
|
|
476
|
+
unref(tabs).splice(0)
|
|
477
|
+
components.clear()
|
|
478
|
+
deletableCache.clear()
|
|
479
|
+
unref(caches).splice(0)
|
|
480
|
+
pageShown.value = true
|
|
481
|
+
}
|
|
482
|
+
const setMaxSize=(size:number)=>{
|
|
483
|
+
max =size
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return {
|
|
487
|
+
tabs,
|
|
488
|
+
caches,
|
|
489
|
+
pageShown,
|
|
490
|
+
setMaxSize,
|
|
491
|
+
canAddTab,
|
|
492
|
+
initial,
|
|
493
|
+
size,
|
|
494
|
+
active,
|
|
495
|
+
destroy,
|
|
496
|
+
reset,
|
|
497
|
+
addCache,
|
|
498
|
+
removeCache,
|
|
499
|
+
getTab,
|
|
500
|
+
addTab,
|
|
501
|
+
removeTab,
|
|
502
|
+
removeAllTabs,
|
|
503
|
+
removeLeftTabs,
|
|
504
|
+
removeRightTabs,
|
|
505
|
+
removeOtherTabs,
|
|
506
|
+
hasTab,
|
|
507
|
+
addPage,
|
|
508
|
+
addComponent,
|
|
509
|
+
getComponent,
|
|
510
|
+
removeComponent,
|
|
511
|
+
markDeletableCache,
|
|
512
|
+
removeDeletableCache,
|
|
513
|
+
refreshTab,
|
|
514
|
+
refreshAllTabs
|
|
515
|
+
}
|
|
516
|
+
}
|