Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 19b57fa4
authored
Jul 06, 2024
by
Li Kui
Committed by
GitHub
Jul 06, 2024
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refactor: remove 'affixTabs' from state (#25)
1 parent
478bbe17
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
54 deletions
packages/@core/forward/stores/src/modules/tabbar.ts
packages/@core/forward/stores/src/modules/tabbar.ts
View file @
19b57fa
...
@@ -28,6 +28,22 @@ function cloneTab(route: TabItem): TabItem {
...
@@ -28,6 +28,22 @@ function cloneTab(route: TabItem): TabItem {
};
};
}
}
/**
* @zh_CN 是否是固定标签页
* @param tab
*/
function
isAffixTab
(
tab
:
TabItem
)
{
return
tab
.
meta
?.
affixTab
??
false
;
}
/**
* @zh_CN 是否显示标签
* @param tab
*/
function
isTabShow
(
tab
:
TabItem
)
{
return
!
tab
.
meta
.
hideInTab
;
}
function
routeToTab
(
route
:
RouteRecordNormalized
)
{
function
routeToTab
(
route
:
RouteRecordNormalized
)
{
return
{
return
{
meta
:
route
.
meta
,
meta
:
route
.
meta
,
...
@@ -38,10 +54,6 @@ function routeToTab(route: RouteRecordNormalized) {
...
@@ -38,10 +54,6 @@ function routeToTab(route: RouteRecordNormalized) {
interface
TabsState
{
interface
TabsState
{
/**
/**
* @zh_CN 固定的标签页列表
*/
affixTabs
:
RouteRecordNormalized
[];
/**
* @zh_CN 当前打开的标签页列表缓存
* @zh_CN 当前打开的标签页列表缓存
*/
*/
cacheTabs
:
Set
<
string
>
;
cacheTabs
:
Set
<
string
>
;
...
@@ -80,7 +92,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -80,7 +92,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
*/
*/
_close
(
tab
:
TabItem
)
{
_close
(
tab
:
TabItem
)
{
const
{
fullPath
}
=
tab
;
const
{
fullPath
}
=
tab
;
if
(
this
.
_
isAffixTab
(
tab
))
{
if
(
isAffixTab
(
tab
))
{
return
;
return
;
}
}
const
index
=
this
.
tabs
.
findIndex
((
item
)
=>
item
.
fullPath
===
fullPath
);
const
index
=
this
.
tabs
.
findIndex
((
item
)
=>
item
.
fullPath
===
fullPath
);
...
@@ -111,20 +123,12 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -111,20 +123,12 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
await
router
.
replace
(
toParams
);
await
router
.
replace
(
toParams
);
},
},
/**
/**
* @zh_CN 是否是固定标签页
* @param tab
*/
_isAffixTab
(
tab
:
TabItem
)
{
return
tab
?.
meta
?.
affixTab
??
false
;
},
/**
* @zh_CN 添加标签页
* @zh_CN 添加标签页
* @param routeTab
* @param routeTab
*/
*/
addTab
(
routeTab
:
TabItem
)
{
addTab
(
routeTab
:
TabItem
)
{
const
tab
=
cloneTab
(
routeTab
);
const
tab
=
cloneTab
(
routeTab
);
const
{
fullPath
,
meta
,
params
,
query
}
=
tab
;
if
(
!
isTabShow
(
tab
))
{
if
(
meta
?.
hideInTab
)
{
return
;
return
;
}
}
...
@@ -137,14 +141,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -137,14 +141,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
}
else
{
}
else
{
// 页面已经存在,不重复添加选项卡,只更新选项卡参数
// 页面已经存在,不重复添加选项卡,只更新选项卡参数
const
currentTab
=
toRaw
(
this
.
tabs
)[
tabIndex
];
const
currentTab
=
toRaw
(
this
.
tabs
)[
tabIndex
];
if
(
!
currentTab
)
{
this
.
tabs
.
splice
(
tabIndex
,
1
,
{
...
currentTab
,
...
tab
});
return
;
}
currentTab
.
params
=
params
||
currentTab
.
params
;
currentTab
.
query
=
query
||
currentTab
.
query
;
currentTab
.
fullPath
=
fullPath
||
currentTab
.
fullPath
;
currentTab
.
meta
=
meta
||
currentTab
.
meta
;
this
.
tabs
.
splice
(
tabIndex
,
1
,
currentTab
);
}
}
this
.
updateCacheTab
();
this
.
updateCacheTab
();
},
},
...
@@ -152,7 +149,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -152,7 +149,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
* @zh_CN 关闭所有标签页
* @zh_CN 关闭所有标签页
*/
*/
async
closeAllTabs
(
router
:
Router
)
{
async
closeAllTabs
(
router
:
Router
)
{
this
.
tabs
=
this
.
tabs
.
filter
((
tab
)
=>
this
.
_
isAffixTab
(
tab
));
this
.
tabs
=
this
.
tabs
.
filter
((
tab
)
=>
isAffixTab
(
tab
));
await
this
.
_goToDefaultTab
(
router
);
await
this
.
_goToDefaultTab
(
router
);
this
.
updateCacheTab
();
this
.
updateCacheTab
();
},
},
...
@@ -169,7 +166,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -169,7 +166,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
const
leftTabs
=
this
.
tabs
.
slice
(
0
,
index
);
const
leftTabs
=
this
.
tabs
.
slice
(
0
,
index
);
const
paths
:
string
[]
=
[];
const
paths
:
string
[]
=
[];
for
(
const
item
of
leftTabs
)
{
for
(
const
item
of
leftTabs
)
{
if
(
!
this
.
_
isAffixTab
(
tab
))
{
if
(
!
isAffixTab
(
tab
))
{
paths
.
push
(
this
.
getTabPath
(
item
));
paths
.
push
(
this
.
getTabPath
(
item
));
}
}
}
}
...
@@ -194,7 +191,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -194,7 +191,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
if
(
!
closeTab
)
{
if
(
!
closeTab
)
{
continue
;
continue
;
}
}
if
(
!
this
.
_
isAffixTab
(
tab
))
{
if
(
!
isAffixTab
(
tab
))
{
paths
.
push
(
this
.
getTabPath
(
closeTab
));
paths
.
push
(
this
.
getTabPath
(
closeTab
));
}
}
}
}
...
@@ -216,7 +213,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -216,7 +213,7 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
const
paths
:
string
[]
=
[];
const
paths
:
string
[]
=
[];
for
(
const
item
of
rightTabs
)
{
for
(
const
item
of
rightTabs
)
{
if
(
!
this
.
_
isAffixTab
(
tab
))
{
if
(
!
isAffixTab
(
tab
))
{
paths
.
push
(
this
.
getTabPath
(
item
));
paths
.
push
(
this
.
getTabPath
(
item
));
}
}
}
}
...
@@ -283,15 +280,8 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -283,15 +280,8 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
(
item
)
=>
this
.
getTabPath
(
item
)
===
this
.
getTabPath
(
tab
),
(
item
)
=>
this
.
getTabPath
(
item
)
===
this
.
getTabPath
(
tab
),
);
);
if
(
index
!==
-
1
)
{
if
(
index
!==
-
1
)
{
this
.
tabs
[
index
].
meta
.
affixTab
=
true
;
}
// TODO: 这里应该把tab从tbs中移除
const
affixIndex
=
this
.
affixTabs
.
findIndex
(
(
item
)
=>
this
.
getTabPath
(
item
)
===
this
.
getTabPath
(
tab
),
);
if
(
affixIndex
===
-
1
)
{
tab
.
meta
.
affixTab
=
true
;
tab
.
meta
.
affixTab
=
true
;
this
.
a
ffixTabs
.
push
(
tab
as
unknown
as
RouteRecordNormalized
);
this
.
a
ddTab
(
tab
);
}
}
},
},
/**
/**
...
@@ -317,23 +307,21 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -317,23 +307,21 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
*/
*/
setAffixTabs
(
tabs
:
RouteRecordNormalized
[])
{
setAffixTabs
(
tabs
:
RouteRecordNormalized
[])
{
for
(
const
tab
of
tabs
)
{
for
(
const
tab
of
tabs
)
{
tab
.
meta
.
affixTab
=
true
;
this
.
addTab
(
routeToTab
(
tab
));
this
.
addTab
(
routeToTab
(
tab
));
}
}
this
.
affixTabs
=
tabs
;
},
},
/**
/**
* @zh_CN 取消固定标签页
* @zh_CN 取消固定标签页
* @param tab
* @param tab
*/
*/
async
unPushPinTab
(
tab
:
TabItem
)
{
async
unPushPinTab
(
tab
:
TabItem
)
{
const
index
=
this
.
affixT
abs
.
findIndex
(
const
index
=
this
.
t
abs
.
findIndex
(
(
item
)
=>
this
.
getTabPath
(
item
)
===
this
.
getTabPath
(
tab
),
(
item
)
=>
this
.
getTabPath
(
item
)
===
this
.
getTabPath
(
tab
),
);
);
if
(
index
!==
-
1
)
{
if
(
index
!==
-
1
)
{
tab
.
meta
.
affixTab
=
false
;
tab
.
meta
.
affixTab
=
false
;
this
.
affixTabs
[
index
].
meta
.
affixTab
=
false
;
this
.
affixTabs
.
splice
(
index
,
1
);
this
.
addTab
(
tab
);
this
.
addTab
(
tab
);
}
}
},
},
...
@@ -363,28 +351,20 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -363,28 +351,20 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
},
},
},
},
getters
:
{
getters
:
{
affixTabs
():
TabItem
[]
{
return
this
.
tabs
.
filter
((
tab
)
=>
isAffixTab
(
tab
));
},
getCacheTabs
():
string
[]
{
getCacheTabs
():
string
[]
{
return
[...
this
.
cacheTabs
];
return
[...
this
.
cacheTabs
];
},
},
getExcludeTabs
():
string
[]
{
getExcludeTabs
():
string
[]
{
return
[...
this
.
excludeCacheTabs
];
return
[...
this
.
excludeCacheTabs
];
},
},
getTabs
():
TabItem
[]
{
getTabs
():
TabItem
[]
{
const
tabs
:
TabItem
[]
=
[];
const
affixTabs
=
this
.
tabs
.
filter
((
tab
)
=>
isAffixTab
(
tab
));
const
affixTabPaths
=
new
Set
<
string
>
();
const
normalTabs
=
this
.
tabs
.
filter
((
tab
)
=>
!
isAffixTab
(
tab
));
for
(
const
tab
of
this
.
affixTabs
)
{
if
(
!
tab
.
meta
.
hideInTab
)
{
return
[...
affixTabs
,
...
normalTabs
];
tabs
.
push
(
routeToTab
(
tab
));
affixTabPaths
.
add
(
tab
.
path
);
}
}
for
(
const
tab
of
this
.
tabs
)
{
if
(
!
affixTabPaths
.
has
(
tab
.
path
)
&&
!
tab
.
meta
.
hideInTab
)
{
tabs
.
push
(
tab
);
}
}
return
tabs
;
},
},
},
},
persist
:
{
persist
:
{
...
@@ -392,7 +372,6 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
...
@@ -392,7 +372,6 @@ const useCoreTabbarStore = defineStore('core-tabbar', {
paths
:
[],
paths
:
[],
},
},
state
:
():
TabsState
=>
({
state
:
():
TabsState
=>
({
affixTabs
:
[],
cacheTabs
:
new
Set
(),
cacheTabs
:
new
Set
(),
excludeCacheTabs
:
new
Set
(),
excludeCacheTabs
:
new
Set
(),
renderRouteView
:
true
,
renderRouteView
:
true
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment