当前位置:网站首页>Tabbar implementation of dynamic bottom navigation bar in uniapp, authority management
Tabbar implementation of dynamic bottom navigation bar in uniapp, authority management
2022-04-23 06:34:00 【Fan Ke】
uniapp middle voice tabbar Realization
Sometimes according to the needs of the business , Need to implement permissions , Or the dynamic bottom navigation bar , This is one of the implementation methods , I use it myself .
This method requires the help of uView Custom navigation bar
Introduce... In the normal way uView, Just import it on the page where you need to use the navigation bar .
however page.json It should also be configured normally
Pages needed
<template>
<view class="body">
<u-tabbar v-model="current" :before-switch="beforeSwitch" active-color="#1d6869" :list="tabarList"></u-tabbar>
</view>
</template>
<script>
import {
mapState,
mapMutations
} from "vuex";
export default {
components: {},
data() {
return {};
},
computed: {
...mapState(["tabarList"]),
},
onLoad() {},
methods: {
...mapMutations(["setTabarList"]),
beforeSwitch(index) {
if (this.tabarList[index].text == " Customer service ") {
this.kfshow = true;
return false;
} else {
return true;
}
},
}
};
</script>
<style lang="scss" scoped>
</style>
Create directory utils/tabBar.js
This is the directory that encapsulates permissions
// Individual users
const member = [{
iconPath: "home",
selectedIconPath: "home-fill",
text: ' Personal homepage ',
customIcon: false,
pagePath: '/pages/index/index',
},
{
iconPath: "account",
selectedIconPath: "account-fill",
text: ' my ',
isDot: false,
pagePath: '/pages/my/my',
},
]
// Enterprise users
const firm = [
{
iconPath: "account",
selectedIconPath: "account-fill",
text: ' Enterprise homepage ',
isDot: false,
pagePath: '/pages/enterprise/enterprise'
},
{
iconPath: "account",
selectedIconPath: "account-fill",
text: ' my ',
isDot: false,
pagePath: '/pages/my/my',
},
]
export default {
member,
firm
}
utilize vuex, Create directory store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import storage from '../common/storage'
import tabBar from '@/untils/tabBar.js'
Vue.use(Vuex)
// Get the type of user , You can also judge the specific permissions according to the business
let userInfo = storage.getJson('userInfo')
let type = 'member'
if(userInfo != null){
switch(userInfo.utype){
case '1':
type = 'member'
break;
case '2':
type = 'firm'
break;
default:
break;
}
}
const store = new Vuex.Store({
state: {
tabarList: tabBar[type], // Dynamic bottom navigation bar
},
mutations: {
setTabarList(state, list) {
state.tabarList = list
},
},
getters: {
},
actions: {
}
})
export default store
main.js To configure
import store from './store'
Vue.prototype.$store = store
Encapsulate methods that can be called globally , Call... Where needed , Change the bottom navigation bar in real time
import storage from "./storage";
import store from '../store'
import tabBar from '@/untils/tabBar.js'
export default {
set(name, value) {
uni.setStorageSync(name, value);
},
get(name) {
return uni.getStorageSync(name);
},
remove(name) {
uni.removeStorageSync(name);
},
clear() {
uni.clearStorageSync();
},
changeList() {
let userInfo = storage.getJson("userInfo");
let type = "member";
if (userInfo != null) {
switch (userInfo.utype) {
case "1":
type = "member";
break;
case "2":
type = "firm";
break;
default:
break;
}
}
store.state.tabarList = tabBar[type];
},
};
Log in successfully , Exit account , Log in again , Or switching identities and other calls
// Call it once , Avoid secondary rendering , Log out , eliminate this.$storage.clear()
let isTabbar = this.$storage.get("isTabbar");
if (isTabbar == "") {
this.$storage.set("isTabbar", 1);
this.$storage.changeList()
}
版权声明
本文为[Fan Ke]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210614037637.html
边栏推荐
猜你喜欢
[leetcode 54] spiral matrix
P1586 solution to tetragonal theorem
Call procedure of function
Graduation project, viewing screenshots of epidemic psychological counseling system
SQL -- data filtering and grouping
非参数化相机畸变模型简介
【UDS统一诊断服务】一、诊断概述(3)— ISO 15765体系结构
Class inheritance and derivation
Database - sorting data
【UDS统一诊断服务】四、诊断典型服务(4)— 在线编程功能单元(0x34-0x38)
随机推荐
The most practical chrome plug-in
Qthread simple test understanding
selenium+webdriver+chrome实现百度以图搜图
gst-launch-1.0用法小记
Jeu de devinettes
根据SQL语句查询出的结果集,将其封装为json
Export the articles written in CSDN to PDF format
深拷贝和浅拷贝的区别
Robocode教程3——Robo机器剖析
识别验证码
C语言实现2048小游戏方向合并逻辑
-- SQL query and return limit rows
Call procedure of function
Gesture recognition research
pyppeteer爬虫
Rust:在线程池中共享变量
GNU EFI header file
Programmers can also write novels
Export of data
The onnx model of yolov5 removes the transfer layer