修改tab刷新位置问题
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<el-main>
|
<el-main>
|
||||||
<router-view v-slot="{ Component, route }" style="height:100%;">
|
<router-view v-slot="{ Component, route }" style="height:100%;">
|
||||||
<!-- <transition name="slide-right" mode="out-in"> -->
|
<!-- <transition name="slide-right" mode="out-in"> -->
|
||||||
<keep-alive :include="keepAliveName" >
|
<keep-alive :include="tabsMenuList" >
|
||||||
<component :is="Component" :key="route.fullPath" />
|
<component :is="Component" :key="route.fullPath" />
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
<!-- </transition> -->
|
<!-- </transition> -->
|
||||||
@@ -25,11 +25,12 @@ import Maximize from "./components/Maximize.vue";
|
|||||||
import Tabs from "@/layouts/components/Tabs/index.vue";
|
import Tabs from "@/layouts/components/Tabs/index.vue";
|
||||||
import Footer from "@/layouts/components/Footer/index.vue";
|
import Footer from "@/layouts/components/Footer/index.vue";
|
||||||
import { useAuthStore } from "@/stores/modules/auth";
|
import { useAuthStore } from "@/stores/modules/auth";
|
||||||
import { useRoute, type RouteLocationNormalized } from 'vue-router'
|
import { useTabsStore } from '@/stores/modules/tabs'
|
||||||
|
const tabStore = useTabsStore()
|
||||||
const globalStore = useGlobalStore();
|
const globalStore = useGlobalStore();
|
||||||
|
const tabsMenuList = computed(() => tabStore.tabsMenuList.map(item => item.name))
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const { maximize, isCollapse, layout, tabs, footer } = storeToRefs(globalStore);
|
const { maximize, isCollapse, layout, tabs, footer } = storeToRefs(globalStore);
|
||||||
const route = useRoute()
|
|
||||||
const keepAliveStore = useKeepAliveStore();
|
const keepAliveStore = useKeepAliveStore();
|
||||||
const { keepAliveName } = storeToRefs(keepAliveStore);
|
const { keepAliveName } = storeToRefs(keepAliveStore);
|
||||||
// console.log("🚀 ~ keepAliveName:", keepAliveName)
|
// console.log("🚀 ~ keepAliveName:", keepAliveName)
|
||||||
@@ -60,14 +61,7 @@ watch(
|
|||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
watch(
|
|
||||||
() => route.path,
|
|
||||||
() => {
|
|
||||||
console.log(123, route.path);
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
// 监听窗口大小变化,折叠侧边栏
|
// 监听窗口大小变化,折叠侧边栏
|
||||||
const screenWidth = ref(0);
|
const screenWidth = ref(0);
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ const initTabs = () => {
|
|||||||
name: item.name,
|
name: item.name,
|
||||||
close: !item.meta.isAffix,
|
close: !item.meta.isAffix,
|
||||||
isKeepAlive: item.meta.isKeepAlive,
|
isKeepAlive: item.meta.isKeepAlive,
|
||||||
|
unshift:true
|
||||||
}
|
}
|
||||||
tabStore.addTabs(tabsParams)
|
tabStore.addTabs(tabsParams)
|
||||||
}
|
}
|
||||||
@@ -100,6 +101,7 @@ const tabsDrop = () => {
|
|||||||
// Tab Click
|
// Tab Click
|
||||||
const tabClick = (tabItem: TabsPaneContext) => {
|
const tabClick = (tabItem: TabsPaneContext) => {
|
||||||
const fullPath = tabItem.props.name as string
|
const fullPath = tabItem.props.name as string
|
||||||
|
console.log("🚀 ~ tabClick ~ fullPath:", tabItem)
|
||||||
router.push(fullPath)
|
router.push(fullPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export interface TabsMenuProps {
|
|||||||
name: string;
|
name: string;
|
||||||
close: boolean;
|
close: boolean;
|
||||||
isKeepAlive: boolean;
|
isKeepAlive: boolean;
|
||||||
|
unshift?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TabsState */
|
/* TabsState */
|
||||||
|
|||||||
@@ -16,8 +16,14 @@ export const useTabsStore = defineStore({
|
|||||||
actions: {
|
actions: {
|
||||||
// Add Tabs
|
// Add Tabs
|
||||||
async addTabs(tabItem: TabsMenuProps) {
|
async addTabs(tabItem: TabsMenuProps) {
|
||||||
|
|
||||||
if (this.tabsMenuList.every(item => item.path !== tabItem.path)) {
|
if (this.tabsMenuList.every(item => item.path !== tabItem.path)) {
|
||||||
this.tabsMenuList.push(tabItem);
|
if (tabItem?.unshift) {
|
||||||
|
this.tabsMenuList.unshift(tabItem);
|
||||||
|
}else{
|
||||||
|
this.tabsMenuList.push(tabItem);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!keepAliveStore.keepAliveName.includes(tabItem.name) && tabItem.isKeepAlive) {
|
if (!keepAliveStore.keepAliveName.includes(tabItem.name) && tabItem.isKeepAlive) {
|
||||||
keepAliveStore.addKeepAliveName(tabItem.name);
|
keepAliveStore.addKeepAliveName(tabItem.name);
|
||||||
|
|||||||
Reference in New Issue
Block a user