| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <template>
- <view id="tabbar">
- <uv-tabbar v-if="menuList.length>0" :value="index" @change="pageTo" activeColor="var(--color)">
- <uv-tabbar-item :text="v.name" :badge="v.badge?v.badge:''" v-for="(v,k) in menuList" :key="k">
- <span class="text">{{v.name}}</span>
- <template v-slot:inactive-icon>
- <uv-image class="icon" :src="'/static/icons/'+v.icon+'.png'" width="20" height="20"></uv-image>
- </template>
- <template v-slot:active-icon>
- <uv-image class="icon" :src="'/static/icons/'+v.icon+'-active.png'" width="20"
- height="20"></uv-image>
- </template>
- </uv-tabbar-item>
- </uv-tabbar>
- </view>
- </template>
- <script>
- export default {
- name: "tabbar",
- props: {
- index: {
- type: [Boolean, Number],
- default: 0
- },
- menuType: {
- type: [Boolean, Number],
- default: 1
- },
- },
- data() {
- return {
- tab: this.index,
- menuList: []
- };
- },
- created() {
- let userInfo = uni.getStorageSync('yd.userInfo');
- userInfo = typeof(userInfo) != 'undefined' && userInfo ? JSON.parse(userInfo) : {};
- let userType = typeof(userInfo.user_type) != 'undefined' && userInfo.user_type ? userInfo.user_type : 3;
- if (userType == 5 || this.menuType == 2) {
- this.menuList = this.$store.state.adminMenuList
- } else {
- this.menuList = this.$store.state.stockMenuList
- }
- },
- watch: {
- index(val) {
- this.tab = val
- }
- },
- methods: {
- onFeedTap() {
- let platform = uni.getSystemInfoSync().platform
- // #ifdef APP-PLUS
- if (platform == "ios") {
- let UIImpactFeedbackGenerator = plus.ios.importClass('UIImpactFeedbackGenerator');
- let impact = new UIImpactFeedbackGenerator();
- impact.prepare();
- impact.init(1);
- impact.impactOccurred();
- }
- if (platform == "android") {
- uni.vibrateShort();
- }
- // #endif
- },
- pageTo(index) {
- let item = this.menuList[index]
- this.onFeedTap();
- console.log(item.page)
- // #ifdef H5
- if (item.page == '/pages/index/index' || item.page == '/pages/group/create' || item.page ==
- '/pages/group/index' || item.page ==
- '/pages/mine/index') {
- uni.switchTab({
- url: item.page
- });
- } else {
- uni.navigateTo({
- url: item.page
- });
- }
- // #endif
- // #ifdef APP||APP-NVUE||APP-PLUS||APP-VUE||MP-WEIXIN||MP
- uni.switchTab({
- url: item.page
- });
- // #endif
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- #tabbar {
- position: relative;
- z-index: 999;
- width: 100%;
- min-height: 80rpx;
- border-top: .05rem solid #f2f2f2;
- .icon {
- width: 20rpx;
- }
- }
- .icon-left {
- margin-left: 20rpx;
- }
- .icon-right {
- margin-right: 20rpx;
- }
- </style>
|