|
|
@@ -5,7 +5,9 @@
|
|
|
v-for="(item, index) in state.tabbarList" :key="index"
|
|
|
:class="[item.centerItem ? ' center-item' : '']"
|
|
|
@click="handleTabbarClick(item)">
|
|
|
- <view class="item-top"><image :src="state.currentItem == item.id ? item.selectIcon : item.icon" mode="widthFit"></image></view>
|
|
|
+ <view class="item-top">
|
|
|
+ <image :src="state.currentItem == item.id ? item.selectIcon : item.icon" mode="widthFit"></image>
|
|
|
+ </view>
|
|
|
<view class="item-bottom" :class="[state.currentItem == item.id ? 'item-active' : '',state.isIOS?'ios11':'']">
|
|
|
<text>{{ item.text }}</text>
|
|
|
</view>
|
|
|
@@ -15,81 +17,81 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="TabBar">
|
|
|
- import {onMounted, reactive, ref} from 'vue'
|
|
|
- import {onLoad, onShow} from "@dcloudio/uni-app";
|
|
|
+import {onMounted, reactive, ref} from 'vue'
|
|
|
+import {onLoad, onShow} from "@dcloudio/uni-app";
|
|
|
|
|
|
- const props = defineProps({
|
|
|
- index: {
|
|
|
- type: Number,
|
|
|
- default: 0
|
|
|
- }
|
|
|
- })
|
|
|
+const props = defineProps({
|
|
|
+ index: {
|
|
|
+ type: Number,
|
|
|
+ default: 0
|
|
|
+ }
|
|
|
+})
|
|
|
|
|
|
- const state = reactive({
|
|
|
- currentItem:0,
|
|
|
- isIOS:false,
|
|
|
-
|
|
|
- tabbarList:[
|
|
|
- {
|
|
|
- id: 0,
|
|
|
- path: '/pages/index/index',
|
|
|
- icon: '/static/iconfont/default/wash.svg',
|
|
|
- selectIcon: '/static/iconfont/wash.svg',
|
|
|
- text: '网点',
|
|
|
- centerItem: false
|
|
|
- },
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- path: '/pages-wash/scan/index',
|
|
|
- icon: '/static/iconfont/scan.svg',
|
|
|
- selectIcon: '/static/iconfont/scan.svg',
|
|
|
- text: '扫码',
|
|
|
- centerItem: true
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- path: '/pages/user/index',
|
|
|
- icon: '/static/iconfont/default/me.svg',
|
|
|
- selectIcon: '/static/iconfont/me.svg',
|
|
|
- text: '我的',
|
|
|
- centerItem: false
|
|
|
- }
|
|
|
- ]
|
|
|
- })
|
|
|
+const state = reactive({
|
|
|
+ currentItem: 0,
|
|
|
+ isIOS: false,
|
|
|
|
|
|
- onLoad(() => {
|
|
|
- state.currentItem = props.index;
|
|
|
+ tabbarList: [
|
|
|
+ {
|
|
|
+ id: 0,
|
|
|
+ path: '/pages/index/index',
|
|
|
+ icon: '/static/iconfont/default/wash.svg',
|
|
|
+ selectIcon: '/static/iconfont/wash.svg',
|
|
|
+ text: '网点',
|
|
|
+ centerItem: false
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 1,
|
|
|
+ path: '/pages-wash/scan/index',
|
|
|
+ icon: '/static/iconfont/scan.svg',
|
|
|
+ selectIcon: '/static/iconfont/scan.svg',
|
|
|
+ text: '扫码',
|
|
|
+ centerItem: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 2,
|
|
|
+ path: '/pages/user/index',
|
|
|
+ icon: '/static/iconfont/default/me.svg',
|
|
|
+ selectIcon: '/static/iconfont/me.svg',
|
|
|
+ text: '我的',
|
|
|
+ centerItem: false
|
|
|
+ }
|
|
|
+ ]
|
|
|
+})
|
|
|
|
|
|
- })
|
|
|
+onLoad(() => {
|
|
|
+ state.currentItem = props.index;
|
|
|
|
|
|
- onShow(() => {
|
|
|
- state.currentItem = props.index;
|
|
|
- const device = uni.getSystemInfoSync();
|
|
|
- state.isIOS = device.osName === "ios";
|
|
|
- })
|
|
|
+})
|
|
|
|
|
|
- onMounted(()=>{
|
|
|
- state.currentItem = props.index;
|
|
|
- })
|
|
|
+onShow(() => {
|
|
|
+ state.currentItem = props.index;
|
|
|
+ const device = uni.getDeviceInfo();
|
|
|
+ state.isIOS = device.system.includes("ios");
|
|
|
+})
|
|
|
|
|
|
+onMounted(() => {
|
|
|
+ state.currentItem = props.index;
|
|
|
+})
|
|
|
|
|
|
- const handleTabbarClick = (item: string) => {
|
|
|
- if(item.path.includes("scan")){
|
|
|
- uni.navigateTo({url:item.path})
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- uni.switchTab({
|
|
|
- url: item?.path,
|
|
|
- success: (e: any) => {
|
|
|
- console.log("tabbar switch>>>>", item,e)
|
|
|
- },
|
|
|
- fail: (e: any) => {
|
|
|
- console.error("swtich error >>>>>", JSON.stringify(e))
|
|
|
- }
|
|
|
- })
|
|
|
+const handleTabbarClick = (item: string) => {
|
|
|
+ if (item.path.includes("scan")) {
|
|
|
+ uni.navigateTo({url: item.path})
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+ uni.switchTab({
|
|
|
+ url: item?.path,
|
|
|
+ success: (e: any) => {
|
|
|
+ console.log("tabbar switch>>>>", item, e)
|
|
|
+ },
|
|
|
+ fail: (e: any) => {
|
|
|
+ console.error("swtich error >>>>>", JSON.stringify(e))
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
|
view {
|
|
|
@@ -97,6 +99,7 @@ view {
|
|
|
margin: 0;
|
|
|
box-sizing: border-box;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container {
|
|
|
position: fixed;
|
|
|
bottom: 0;
|
|
|
@@ -109,8 +112,9 @@ view {
|
|
|
padding: 25rpx 0;
|
|
|
//color: #999999;
|
|
|
|
|
|
- box-shadow: 0 -2px 5px #efefef;
|
|
|
+ box-shadow: 0 -2px 5px #efefef;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container .tabbar-item {
|
|
|
width: 33.3%;
|
|
|
height: 100rpx;
|
|
|
@@ -120,18 +124,22 @@ view {
|
|
|
align-items: center;
|
|
|
text-align: center;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container .item-active {
|
|
|
color: $uni-color-primary;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container .center-item {
|
|
|
display: block;
|
|
|
position: relative;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container .tabbar-item .item-top {
|
|
|
width: 70rpx;
|
|
|
height: 70rpx;
|
|
|
padding: 10rpx;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container .center-item .item-top {
|
|
|
//flex-shrink: 0;
|
|
|
width: 120rpx;
|
|
|
@@ -148,24 +156,28 @@ view {
|
|
|
|
|
|
box-shadow: 0 0 10px #efefef; /* 阴影效果 */
|
|
|
}
|
|
|
-.tabbar-container .center-item .item-top image{
|
|
|
+
|
|
|
+.tabbar-container .center-item .item-top image {
|
|
|
//width: 110rpx !important;
|
|
|
//height: 110rpx !important;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container .tabbar-item .item-top image {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container .tabbar-item .item-bottom {
|
|
|
font-size: 22rpx;
|
|
|
width: 100%;
|
|
|
}
|
|
|
+
|
|
|
.tabbar-container .center-item .item-bottom {
|
|
|
position: absolute;
|
|
|
bottom: 0;
|
|
|
}
|
|
|
|
|
|
-.ios{
|
|
|
+.ios {
|
|
|
bottom: 30rpx !important;
|
|
|
}
|
|
|
</style>
|