linwe
2024-08-08 3c738f4fe2762bba8087e5a22fc0dc06560eab0e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template>
    <view>
        <u-tabbar class="custom-tabbar" zIndex="9999" :value="current" :fixed="true" :active-color="activeColor"
            :inactive-color="inactiveColor">
            <u-tabbar-item :text="item.name" @click="changeTabbar(item.url,index,item.name)"
                v-for="(item,index) in tabbarList" :key="index">
                <image class="tabbar-icon" slot="active-icon" :src="item.iconPathSelected"></image>
                <image class="tabbar-icon" slot="inactive-icon" :src="item.iconPath"></image>
            </u-tabbar-item>
        </u-tabbar>
    </view>
</template>
 
<script>
    export default {
        props: {
            current: Number,
            list: {
                type: Array,
                default: () => []
            }
        },
        data() {
            return {
                tabbarList: [],
                inactiveColor: '#C7CED7',
                activeColor: '#017BFC',
                // activeColor: '#003399'
            }
        },
        watch: {
            list: {
                handler(newVal) {
                    if (newVal && newVal.length > 0) {
                        this.tabbarList = newVal;
                        if (uni.getStorageSync("activeRole").roleName == "民警") {
                            this.inactiveColor = "#AFB8C3";
                            this.activeColor = "#003399";
                        } else {
                            this.inactiveColor = "#C7CED7"
                            this.activeColor = "#017BFC";
                        }
                    }
                },
                deep: true,
                immediate: true
            }
        },
 
        methods: {
            changeTabbar(url, index) {
                if (this.current == index) return
                uni.switchTab({
                    url
                })
                this.$emit("change", index)
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .tabbar-icon {
        width: 56rpx;
        height: 56rpx;
    }
 
    /deep/.u-tabbar {
        box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(107, 134, 159, 0.2);
    }
</style>