Skip to content

Commit 40b81b9

Browse files
committed
opti: remove vuex in API.nvue
1 parent 309ad1f commit 40b81b9

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

pages/tabBar/API/API.nvue

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
:inWhiteList="true"></u-link>
1414
</view>
1515
<view class="uni-panel" v-for="(item, index) in list" :key="item.id">
16-
<view class="uni-panel-h" :class="activeOpen === item.id ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index, item.id)">
16+
<view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index, item.id)">
1717
<text class="uni-panel-text">{{item.name}}</text>
18-
<text class="uni-panel-icon uni-icon" :class="activeOpen === item.id ? 'uni-panel-icon-on' : ''">{{item.pages ? '&#xe581;' : '&#xe470;'}}</text>
18+
<text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">{{item.pages ? '&#xe581;' : '&#xe470;'}}</text>
1919
</view>
20-
<view class="uni-panel-c" v-if="activeOpen === item.id">
20+
<view class="uni-panel-c" v-if="item.open">
2121
<view :class="{'left-win-active': leftWinActive === item2.url && hasLeftWin, 'pc-hide': item2.name === '设置TabBar' && hasLeftWin}" class="uni-navigate-item" v-for="(item2,key) in item.pages" :key="key" :url="item.url" @click="goDetailPage(item.id, item2.url)">
2222
<text class="uni-navigate-text">{{item2.name ? item2.name : item2}}</text>
2323
<text class="uni-navigate-icon uni-icon">&#xe470;</text>
@@ -29,11 +29,18 @@
2929
</template>
3030
<script>
3131
import setTabBar from '@/components/api-set-tabbar.nvue';
32-
import { mapState, mapMutations } from 'vuex';
3332
export default {
3433
components: {
3534
setTabBar
3635
},
36+
props: {
37+
hasLeftWin: {
38+
type: Boolean
39+
},
40+
leftWinActive: {
41+
type: String
42+
}
43+
},
3744
data() {
3845
// 暂时这么写,后面看怎么优化。
3946
let mediaPages = [{
@@ -413,29 +420,19 @@
413420
onHide() {
414421
this.leaveSetTabBarPage();
415422
},
416-
computed: {
417-
...mapState({
418-
hasLeftWin: state => !state.noMatchLeftWindow,
419-
leftWinActive: state => state.leftWinActive.split('/')[3],
420-
activeOpen: state => state.activeOpen
421-
})
422-
},
423+
423424
// #ifdef H5
424425
watch:{
425426
$route: {
426427
immediate: true,
427428
handler(newRoute) {
428429
if (newRoute.matched.length) {
429-
this.setLeftWinActive(newRoute.path)
430430
let path = newRoute.path.split('/')[3]
431431
for (const item of this.list) {
432432
if (Array.isArray(item.pages)) {
433433
for (const page of item.pages) {
434-
if (page === path) {
435-
this.setActiveOpen(item.id)
436-
}
437-
if (page.url && page.url === path) {
438-
this.setActiveOpen(item.id)
434+
if (page === path || page.url && page.url === path) {
435+
item.open = true
439436
}
440437
}
441438
}
@@ -446,16 +443,18 @@
446443
},
447444
// #endif
448445
methods: {
449-
...mapMutations(['setLeftWinActive', 'setActiveOpen']),
450446
triggerCollapse(e, id) {
451447
if (!this.list[e].pages) {
452448
this.goDetailPage('', this.list[e].url);
453449
return;
454450
}
455-
if (id === this.activeOpen) {
456-
id = ''
451+
for (var i = 0; i < this.list.length; ++i) {
452+
if (e === i) {
453+
this.list[i].open = !this.list[i].open;
454+
} else {
455+
this.list[i].open = false;
456+
}
457457
}
458-
this.setActiveOpen(id)
459458
},
460459
goDetailPage(panel, e) {
461460
if (e === 'set-tabbar') {

0 commit comments

Comments
 (0)