修复bug ,底部导航,装修优化

This commit is contained in:
Jason
2022-09-14 16:41:39 +08:00
parent a1fc2fed1c
commit cf99b35b79
28 changed files with 323 additions and 112 deletions

View File

@@ -1,21 +1,30 @@
<template>
<u-tabbar v-bind="tabbarStyle" :list="tabbarList" @change="handleChange"></u-tabbar>
<u-tabbar
v-model="current"
v-bind="tabbarStyle"
:list="tabbarList"
@change="handleChange"
:hide-tab-bar="false"
></u-tabbar>
</template>
<script lang="ts" setup>
import { useAppStore } from '@/stores/app'
import { currentPage, navigateTo } from '@/utils/util'
import { onLoad } from '@dcloudio/uni-app'
import { computed, onMounted, ref } from 'vue'
import { navigateTo } from '@/utils/util'
import { computed, ref } from 'vue'
const current = ref()
const appStore = useAppStore()
const tabbarList = computed(() => {
return appStore.getTabbarConfig.map((item: any) => ({
iconPath: item.unselected,
selectedIconPath: item.selected,
text: item.name,
link: JSON.parse(item.link),
pagePath: JSON.parse(item.link).path
}))
return appStore.getTabbarConfig.map((item: any) => {
const link = JSON.parse(item.link)
return {
iconPath: item.unselected,
selectedIconPath: item.selected,
text: item.name,
link,
pagePath: link.path
}
})
})
const tabbarStyle = computed(() => ({
@@ -26,8 +35,4 @@ const handleChange = (index: number) => {
const selectTab = tabbarList.value[index]
navigateTo(selectTab.link, 'reLaunch')
}
// onMounted(() => {
// const page = currentPage()
// console.log(page)
// })
</script>

View File

@@ -238,16 +238,20 @@ export default {
},
// 切换tab
switchTab(index) {
// 发出事件和修改v-model绑定的值
this.$emit("change", index);
let pagePath = this.list[index].pagePath;
// 如果有配置pagePath属性使用uni.switchTab进行跳转
if (this.list[index].pagePath) {
if (pagePath) {
if(pagePath == this.pageUrl || pagePath == "/" + this.pageUrl) return
// 发出事件和修改v-model绑定的值
this.$emit("change", index);
uni.switchTab({
url: this.list[index].pagePath
url: pagePath
});
} else {
// 如果配置了papgePath属性将不会双向绑定v-model传入的value值
// 因为这个模式下不再需要v-model绑定的value值了而是通过getCurrentPages()适配
this.$emit("change", index);
this.$emit("input", index);
this.$emit("update:modelValue", index);
}
@@ -370,4 +374,4 @@ export default {
}
}
}
</style>
</style>

View File

@@ -53,15 +53,8 @@ export enum LinkTypeEnum {
}
export function navigateTo(link: Link, navigateType: 'navigateTo' | 'reLaunch' = 'navigateTo') {
let url: string
switch (link.type) {
case LinkTypeEnum.SHOP_PAGES:
url = link.query ? `${link.path}?${objectToQuery(link.query)}` : link.path
uni[navigateType]({ url })
break
case LinkTypeEnum.CUSTOM_LINK:
uni[navigateType]({ url: `/pages/webview/webview?url=${link.path}` })
}
const url = link.query ? `${link.path}?${objectToQuery(link.query)}` : link.path
uni[navigateType]({ url })
}
/**