路由处理

This commit is contained in:
zhang zhuo 2025-06-05 17:25:07 +08:00
parent d8c44b2ef6
commit b01ce00641
3 changed files with 8 additions and 15 deletions

View File

@ -53,7 +53,7 @@
<script setup name="tags"> <script setup name="tags">
import Sortable from 'sortablejs' import Sortable from 'sortablejs'
import {getCurrentInstance, nextTick, ref, watch, onMounted} from "vue"; import {getCurrentInstance, nextTick, ref, watch, onMounted, toRaw} from "vue";
import store from "@/store/index"; import store from "@/store/index";
import {useRouter, useRoute} from "vue-router"; import {useRouter, useRoute} from "vue-router";
import {getMenu} from "@/utils/route" import {getMenu} from "@/utils/route"
@ -69,6 +69,7 @@ let contextMenuItem = ref(null)
let left = ref(0) let left = ref(0)
let top = ref(0) let top = ref(0)
let tagList = store.state.viewTags.viewTags let tagList = store.state.viewTags.viewTags
let tipDisplayed = ref(false) let tipDisplayed = ref(false)
if (dashboardRoute) { if (dashboardRoute) {
@ -82,9 +83,8 @@ onMounted(() => {
scrollInit() scrollInit()
}) })
watch(route, (e) => { watch(() => route.path, (e) => {
console.log(111) addViewTags(route);
addViewTags(e);
// //
nextTick(() => { nextTick(() => {
const tags = proxy.$refs.tags const tags = proxy.$refs.tags
@ -105,7 +105,7 @@ watch(route, (e) => {
} }
} }
}) })
}) }, {deep: false})
watch(contextMenuVisible, (value) => { watch(contextMenuVisible, (value) => {
var cm = function (e) { var cm = function (e) {

View File

@ -11,9 +11,9 @@ export default {
let isName = route.name let isName = route.name
if(!target && isName){ if(!target && isName){
if(backPathIndex == -1){ if(backPathIndex == -1){
state.viewTags.push(route) state.viewTags.push(Object.assign({}, route))
}else{ }else{
state.viewTags.splice(backPathIndex+1, 0, route) state.viewTags.splice(backPathIndex+1, 0, Object.assign({}, route))
} }
} }
}, },
@ -25,12 +25,9 @@ export default {
}) })
}, },
updateViewTags(state, route){ updateViewTags(state, route){
// state.viewTags = state.viewTags.map(item =>
// item.fullPath === route.fullPath ? { ...item, ...route } : item
// );
state.viewTags.forEach((item) => { state.viewTags.forEach((item) => {
if (item.fullPath == route.fullPath){ if (item.fullPath == route.fullPath){
// 追加数据
item = Object.assign(item, route) item = Object.assign(item, route)
} }
}) })

View File

@ -8,9 +8,6 @@ export function beforeEach(to: RouteLocationNormalized, from: RouteLocationNorma
if (!piMain) { if (!piMain) {
return false return false
} }
console.log(from)
store.commit("updateViewTags", { store.commit("updateViewTags", {
fullPath: from.fullPath, fullPath: from.fullPath,
scrollTop: piMain.scrollTop scrollTop: piMain.scrollTop
@ -28,7 +25,6 @@ export function afterEach(to: RouteLocationNormalized) {
if (beforeRoute) { if (beforeRoute) {
piMain.scrollTop = beforeRoute.scrollTop || 0 piMain.scrollTop = beforeRoute.scrollTop || 0
} }
}).then(r => {
}) })
} }