|
@@ -27,6 +27,7 @@ import { useTabs } from '/@/hooks/web/useTabs';
|
|
|
// import { PageEnum } from '/@/enums/pageEnum';
|
|
|
|
|
|
import './index.less';
|
|
|
+import { userStore } from '/@/store/modules/user';
|
|
|
export default defineComponent({
|
|
|
name: 'MultiTabs',
|
|
|
setup() {
|
|
@@ -60,24 +61,27 @@ export default defineComponent({
|
|
|
|
|
|
watch(
|
|
|
() => unref(currentRoute).path,
|
|
|
- (path) => {
|
|
|
- if (activeKeyRef.value !== path) {
|
|
|
- activeKeyRef.value = path;
|
|
|
+ () => {
|
|
|
+ if (!userStore.getTokenState) return;
|
|
|
+ const { path: rPath, fullPath } = unref(currentRoute);
|
|
|
+ if (activeKeyRef.value !== (fullPath || rPath)) {
|
|
|
+ activeKeyRef.value = fullPath || rPath;
|
|
|
}
|
|
|
// 监听路由的话虽然可以,但是路由切换的时间会造成卡顿现象?
|
|
|
// 使用useTab的addTab的话,当用户手动调转,需要自行调用addTab
|
|
|
- // tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw);
|
|
|
- const { affix } = currentRoute.value.meta || {};
|
|
|
- if (affix) return;
|
|
|
- const hasInTab = tabStore.getTabsState.some(
|
|
|
- (item) => item.fullPath === currentRoute.value.fullPath
|
|
|
- );
|
|
|
- if (!hasInTab) {
|
|
|
- tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw);
|
|
|
- }
|
|
|
+ tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw);
|
|
|
+
|
|
|
+ // const { affix } = currentRoute.value.meta || {};
|
|
|
+ // if (affix) return;
|
|
|
+ // const hasInTab = tabStore.getTabsState.some(
|
|
|
+ // (item) => item.fullPath === currentRoute.value.fullPath
|
|
|
+ // );
|
|
|
+ // if (!hasInTab) {
|
|
|
+ // tabStore.commitAddTab((unref(currentRoute) as unknown) as AppRouteRecordRaw);
|
|
|
+ // }
|
|
|
},
|
|
|
{
|
|
|
- flush: 'post',
|
|
|
+ // flush: 'post',
|
|
|
immediate: true,
|
|
|
}
|
|
|
);
|
|
@@ -115,7 +119,9 @@ export default defineComponent({
|
|
|
// 关闭当前ab
|
|
|
function handleEdit(targetKey: string) {
|
|
|
// 新增操作隐藏,目前只使用删除操作
|
|
|
- const index = unref(getTabsState).findIndex((item) => item.path === targetKey);
|
|
|
+ const index = unref(getTabsState).findIndex(
|
|
|
+ (item) => (item.fullPath || item.path) === targetKey
|
|
|
+ );
|
|
|
index !== -1 && closeTab(unref(getTabsState)[index]);
|
|
|
}
|
|
|
|
|
@@ -133,8 +139,10 @@ export default defineComponent({
|
|
|
}
|
|
|
function renderTabs() {
|
|
|
return unref(getTabsState).map((item: TabItem) => {
|
|
|
+ const key = item.query ? item.fullPath : item.path;
|
|
|
+
|
|
|
return (
|
|
|
- <Tabs.TabPane key={item.path} closable={!(item && item.meta && item.meta.affix)}>
|
|
|
+ <Tabs.TabPane key={key} closable={!(item && item.meta && item.meta.affix)}>
|
|
|
{{
|
|
|
tab: () => <TabContent tabItem={item} />,
|
|
|
}}
|