vue-stack-tabs 0.1.13 → 0.1.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-stack-tabs",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Vue.js component for router tab.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,136 +1,124 @@
1
- <script lang="ts" setup>
2
- import { onBeforeMount, onUnmounted, provide, ref, watch } from 'vue'
3
- import type { TransitionProps, DefineComponent, VNode } from 'vue'
4
- import { type RouteLocationNormalizedLoaded, useRouter } from 'vue-router'
5
- import { getMaxZIndex } from './utils/TabScrollHelper'
6
- import { type ITabData, TabScrollMode } from './model/TabModel'
7
- import TabHeader from './components/TabHeader/index.vue'
8
- import useTabpanel from './hooks/useTabpanel'
9
- import useStackTab from './hooks/useStackTab'
10
- const { tabs, pageShown, caches, addPage, destroy, initial,setMaxSize } = useTabpanel()
11
- const emit = defineEmits(['onActive'])
12
- const props = withDefaults(
13
- defineProps<{
14
- // 初始页签数据
15
- defaultTabs?: ITabData[]
16
- // 最大打开数量
17
- max?: number
18
- // 新页加入哪个位置
19
- append?: string
20
- // 右键菜单
21
- contextmenu?: boolean | object
22
- // 页面转场效果
23
- pageTransition?: string
24
- // 标签转场效果
25
- tabTransition?: string | TransitionProps
26
- // tab 滚动效果
27
- tabScrollMode?: TabScrollMode
28
- width?: string
29
- height?: string
30
- i18n?: { locale?: string; messages?: object }
31
- messages?: any
32
- reloadable?: boolean
33
- closable?: boolean
34
- space?: number
35
- iframePath: string
36
- }>(),
37
- {
38
- defaultTabs: () => [],
39
- max: 20,
40
- append: 'last',
41
- contextmenu: true,
42
- tabTransition: 'stack-tab-zoom',
43
- pageTransition: 'stack-tab-swap',
44
- tabScrollMode: TabScrollMode.BOTH,
45
- width: '100%',
46
- height: '100%',
47
- i18n: () => ({ locale: 'zh-CN', messages: {} }),
48
- reloadable: true,
49
- closable: true,
50
- space: 300
51
- }
52
- )
53
- provide('locales', { ...props.i18n })
54
- // 最大化,并向下传递
55
- const maximum = ref<boolean>(false)
56
- provide('maximum', maximum)
57
- const { setIFramePath } = useStackTab()
58
- setIFramePath(props.iframePath)
59
- onBeforeMount(() => {
60
- console.log('on Before mount')
61
- initial(props.defaultTabs)
62
- })
63
- const tabWrapper = (route: RouteLocationNormalizedLoaded, component: VNode): DefineComponent => {
64
- // return defineAsyncComponent(() => addPage(route, component))
65
- return addPage(route, component)
66
- }
67
- const onTabActive = (id: string) => {
68
- emit('onActive', id)
69
- }
70
- setMaxSize(props.max)
71
- onUnmounted(() => {
72
- destroy()
73
- })
74
- /**
75
- * 路由真正转换的时候才切换页面
76
- * 有keepalive或组装过Component的都会多次加载
77
- */
78
- const router = useRouter()
79
- watch(
80
- () => router.currentRoute.value.fullPath,
81
- () => {
82
- pageShown.value = true
83
- // routerLeaved.value = true
84
- console.log('route change')
85
- }
86
- )
87
- </script>
88
- <template>
89
- <div
90
- class="stack-tab"
91
- :style="{
92
- width: width,
93
- height: height,
94
- 'z-index': maximum ? getMaxZIndex('body *:not(.stack-tab,.stack-tab *)') : undefined
95
- }"
96
- :class="{ 'stack-tab__maximum': maximum }"
97
- >
98
- <tab-header :space="space" @active="onTabActive" :tab-transition="tabTransition" :max="max">
99
- <template #leftButton>
100
- <slot name="leftButton" />
101
- </template>
102
- <template #rightButton>
103
- <slot name="rightButton" />
104
- </template>
105
- </tab-header>
106
- <div class="stack-tab__container">
107
- <router-view v-slot="{ Component, route }">
108
- <transition :name="pageTransition" appear @after-leave="pageShown = true">
109
- <keep-alive :include="caches">
110
- <suspense>
111
- <template #default>
112
- <component
113
- :is="tabWrapper(route, Component)"
114
- v-if="pageShown"
115
- :key="route.fullPath"
116
- />
117
- </template>
118
- <template #fallback> Loading.... </template>
119
- </suspense>
120
- </keep-alive>
121
- </transition>
122
- </router-view>
123
- <transition-group :name="pageTransition" appear>
124
- <iframe
125
- v-for="frame of tabs.filter((item) => item.iframe)"
126
- v-show="frame.active && pageShown"
127
- :key="frame.id"
128
- class="stack-tab__iframe"
129
- :src="/^(javascript|data):/i.test(frame.url ?? '') ? 'about:blank' : frame.url"
130
- frameborder="0"
131
- />
132
- </transition-group>
133
- </div>
134
- </div>
135
- </template>
136
- <style scoped></style>
1
+ <script lang="ts" setup>
2
+ import { onBeforeMount, onUnmounted, provide, ref } from 'vue'
3
+ import type { TransitionProps, DefineComponent, VNode } from 'vue'
4
+ import { type RouteLocationNormalizedLoaded } from 'vue-router'
5
+ import { getMaxZIndex } from './utils/TabScrollHelper'
6
+ import { type ITabData, TabScrollMode } from './model/TabModel'
7
+ import TabHeader from './components/TabHeader/index.vue'
8
+ import useTabpanel from './hooks/useTabpanel'
9
+ import useStackTab from './hooks/useStackTab'
10
+ const { tabs, pageShown, caches, addPage, destroy, initial,setMaxSize } = useTabpanel()
11
+ const emit = defineEmits(['onActive'])
12
+ const props = withDefaults(
13
+ defineProps<{
14
+ // 初始页签数据
15
+ defaultTabs?: ITabData[]
16
+ // 最大打开数量
17
+ max?: number
18
+ // 新页加入哪个位置
19
+ append?: string
20
+ // 右键菜单
21
+ contextmenu?: boolean | object
22
+ // 页面转场效果
23
+ pageTransition?: string
24
+ // 标签转场效果
25
+ tabTransition?: string | TransitionProps
26
+ // tab 滚动效果
27
+ tabScrollMode?: TabScrollMode
28
+ width?: string
29
+ height?: string
30
+ i18n?: { locale?: string; messages?: object }
31
+ messages?: any
32
+ reloadable?: boolean
33
+ closable?: boolean
34
+ space?: number
35
+ iframePath: string
36
+ }>(),
37
+ {
38
+ defaultTabs: () => [],
39
+ max: 20,
40
+ append: 'last',
41
+ contextmenu: true,
42
+ tabTransition: 'stack-tab-zoom',
43
+ pageTransition: 'stack-tab-swap',
44
+ tabScrollMode: TabScrollMode.BOTH,
45
+ width: '100%',
46
+ height: '100%',
47
+ i18n: () => ({ locale: 'zh-CN', messages: {} }),
48
+ reloadable: true,
49
+ closable: true,
50
+ space: 300
51
+ }
52
+ )
53
+ provide('locales', { ...props.i18n })
54
+ // 最大化,并向下传递
55
+ const maximum = ref<boolean>(false)
56
+ provide('maximum', maximum)
57
+ const { setIFramePath } = useStackTab()
58
+ setIFramePath(props.iframePath)
59
+ onBeforeMount(() => {
60
+ console.log('on Before mount')
61
+ initial(props.defaultTabs)
62
+ })
63
+ const tabWrapper = (route: RouteLocationNormalizedLoaded, component: VNode): DefineComponent => {
64
+ // return defineAsyncComponent(() => addPage(route, component))
65
+ return addPage(route, component)
66
+ }
67
+ const onTabActive = (id: string) => {
68
+ emit('onActive', id)
69
+ }
70
+ setMaxSize(props.max)
71
+ onUnmounted(() => {
72
+ destroy()
73
+ })
74
+
75
+ </script>
76
+ <template>
77
+ <div
78
+ class="stack-tab"
79
+ :style="{
80
+ width: width,
81
+ height: height,
82
+ 'z-index': maximum ? getMaxZIndex('body *:not(.stack-tab,.stack-tab *)') : undefined
83
+ }"
84
+ :class="{ 'stack-tab__maximum': maximum }"
85
+ >
86
+ <tab-header :space="space" @active="onTabActive" :tab-transition="tabTransition" :max="max">
87
+ <template #leftButton>
88
+ <slot name="leftButton" />
89
+ </template>
90
+ <template #rightButton>
91
+ <slot name="rightButton" />
92
+ </template>
93
+ </tab-header>
94
+ <div class="stack-tab__container">
95
+ <router-view v-slot="{ Component, route }">
96
+ <transition :name="pageTransition" @after-leave="pageShown=true" mode="out-in">
97
+ <keep-alive :include="caches">
98
+ <suspense>
99
+ <template #default>
100
+ <component
101
+ :is="tabWrapper(route, Component)"
102
+ v-if="pageShown"
103
+ :key="route.fullPath"
104
+ />
105
+ </template>
106
+ <template #fallback> Loading.... </template>
107
+ </suspense>
108
+ </keep-alive>
109
+ </transition>
110
+ </router-view>
111
+ <transition-group :name="pageTransition" appear>
112
+ <iframe
113
+ v-for="frame of tabs.filter((item) => item.iframe)"
114
+ v-show="frame.active && pageShown"
115
+ :key="frame.id"
116
+ class="stack-tab__iframe"
117
+ :src="/^(javascript|data):/i.test(frame.url ?? '') ? 'about:blank' : frame.url"
118
+ frameborder="0"
119
+ />
120
+ </transition-group>
121
+ </div>
122
+ </div>
123
+ </template>
124
+ <style scoped></style>
@@ -1,40 +1,40 @@
1
- /*
2
- transition 过渡样式
3
- */
4
- .stack-tab-zoom {
5
- &-enter-active,
6
- &-leave-active {
7
- transition: all 0.3s ease-in-out;
8
- }
9
-
10
- &-enter-from,
11
- &-leave-to {
12
- transform: scale(0);
13
- opacity: 0;
14
- }
15
- }
16
-
17
- /*
18
- 页面交换
19
- */
20
- .stack-tab-swap {
21
- $trans: 30px;
22
-
23
- &-enter-active,
24
- &-leave-active {
25
- transition: all 0.3s ease-in-out;
26
- }
27
-
28
- &-enter-from,
29
- &-leave-to {
30
- opacity: 0;
31
- }
32
-
33
- &-enter-from {
34
- transform: translateX(-$trans);
35
- }
36
-
37
- &-leave-to {
38
- transform: translateX($trans);
39
- }
40
- }
1
+ /*
2
+ transition 过渡样式
3
+ */
4
+ .stack-tab-zoom {
5
+ &-enter-active,
6
+ &-leave-active {
7
+ transition: all 0.3s ease-in-out;
8
+ }
9
+
10
+ &-enter-from,
11
+ &-leave-to {
12
+ transform: scale(0);
13
+ opacity: 0;
14
+ }
15
+ }
16
+
17
+ /*
18
+ 页面交换
19
+ */
20
+ .stack-tab-swap {
21
+ $trans: 30px;
22
+
23
+ &-enter-active,
24
+ &-leave-active {
25
+ transition: all 0.3s ease-in-out;
26
+ }
27
+
28
+ &-enter-from,
29
+ &-leave-to {
30
+ opacity: 0;
31
+ }
32
+
33
+ &-enter-from {
34
+ transform: translateX(-$trans);
35
+ }
36
+
37
+ &-leave-to {
38
+ transform: translateX($trans);
39
+ }
40
+ }
@@ -57,6 +57,7 @@ export default () => {
57
57
  query['__src'] = __src
58
58
  }
59
59
 
60
+
60
61
  router.push({
61
62
  path,
62
63
  query
@@ -9,7 +9,7 @@ export default () => {
9
9
  closeTabLoading()
10
10
  })
11
11
  const openTabLoading = () => {
12
- const container = document.querySelector(`#${attrs.tId}`)
12
+ const container = document.querySelector(`#${'W-'+attrs.tId}`)
13
13
  if (loadingInstance === null) {
14
14
  loadingInstance = $loading.show({
15
15
  canCancel: false,
@@ -18,7 +18,6 @@ export default () => {
18
18
  currentId = attrs.tId as string
19
19
  // currentPageId = attrs.pId as string
20
20
  currentTab = route.query.__tab as string
21
-
22
21
  const forward = (to: RouteLocationPathRaw) => {
23
22
  pageShown.value = false
24
23
  const query = defu(