Skip to content

Commit a26674b

Browse files
committed
opti: refactor left-window
1 parent a33d305 commit a26674b

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

windows/left-window.vue

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<view class="left-window-style">
33
<view class="second-menu">
4-
<component v-bind:is="active"></component>
4+
<!-- <keep-alive> -->
5+
<component v-bind:is="active" :hasLeftWin="hasLeftWin" :leftWinActive="leftWinActive"></component>
6+
<!-- </keep-alive> -->
57
</view>
68
</view>
79
</template>
@@ -40,45 +42,59 @@
4042
computed: {
4143
...mapState({
4244
active: state => state.active,
45+
hasLeftWin: state => !state.noMatchLeftWindow,
46+
leftWinActive: state => state.leftWinActive.split('/')[3],
4347
})
4448
},
4549
watch: {
4650
matchLeftWindow: {
4751
immediate: true,
48-
handler(newMatches) {
52+
handler(newMatches) {
4953
this.setMatchLeftWindow(newMatches)
5054
}
51-
},
55+
},
56+
// #ifndef VUE3
5257
$route: {
5358
immediate: true,
54-
handler(newRoute) {
55-
if (this.matchLeftWindow) {
56-
if (newRoute.path === '/') {
57-
uni.redirectTo({
58-
url: 'pages/component/view/view'
59-
})
60-
} else if (!newRoute.matched.length) {
61-
uni.redirectTo({
62-
url: 'pages/error/404'
63-
})
64-
} else {
65-
let active = newRoute.path.split('/')[2]
66-
if (this.nav.includes(active)) {
67-
if (active === 'component') {
68-
active = 'componentPage'
69-
}
70-
if (active === 'template') {
71-
active = 'templatePage'
72-
}
73-
this.setActive(active)
74-
}
75-
}
76-
}
59+
handler(newRoute) {
60+
this.handlerRoute(newRoute)
7761
}
62+
},
63+
// #endif
64+
// #ifdef VUE3
65+
$route(newRoute) {
66+
this.handlerRoute(newRoute)
7867
}
68+
// #endif
7969
},
8070
methods: {
81-
...mapMutations(['setMatchLeftWindow', 'setActive']),
71+
...mapMutations(['setMatchLeftWindow', 'setActive', 'setLeftWinActive']),
72+
73+
handlerRoute(newRoute) {
74+
if (this.matchLeftWindow) {
75+
if (newRoute.path === '/') {
76+
uni.redirectTo({
77+
url: 'pages/component/view/view'
78+
})
79+
} else if (!newRoute.matched.length) {
80+
uni.redirectTo({
81+
url: 'pages/error/404'
82+
})
83+
} else {
84+
this.setLeftWinActive(newRoute.path)
85+
let active = newRoute.path.split('/')[2]
86+
if (this.nav.includes(active)) {
87+
if (active === 'component') {
88+
active = 'componentPage'
89+
}
90+
if (active === 'template') {
91+
active = 'templatePage'
92+
}
93+
this.setActive(active)
94+
}
95+
}
96+
}
97+
}
8298
}
8399
}
84100
</script>

0 commit comments

Comments
 (0)