赞
踩
思路:
1.创建自定义的tabbar组件
2.增加启动页面page/index/index
3.在启动页面加载所有tab页面,使用tabbar组件进行切换
主要代码:
mytabbar.vue
- <template>
- <view class="uni-tabbar">
- <view class="uni-tabbar__item" v-for="(item,index) in tabList" :key="index" @tap="changeTab(item)">
- <view class="uni-tabbar__icon" :class="[tabs[item].fontIcon, item == activeTab? 'active':'']"></view>
- <view class="uni-tabbar__label" :class="{'active': item == activeTab}">
- {{tabs[item].text}}
- </view>
- </view>
- </view>
- </template>
-
- <script>
- export default {
- props: {
- tabList: {
- type: Array,
- default: ['tabMyIndex']
- },
- activeTab: {
- type: String,
- default: ''
- }
- },
- emits:['update:activeTab'],
- data() {
- return {
- tabs: {
- tabAdminIndex: {
- "pagePath": "/pages/admin/index",
- "selectedIconPath": "/static/tabBar/home_col.png",
- "text": "首页",
- "fontIcon": "w-icon-home"
- },
- tabAdminCustom: {
- "pagePath": "/pages/admin/custom",
- "selectedIconPath": "/static/tabBar/home_col.png",
- "text": "客户",
- "fontIcon": "w-icon-qq"
- },
- tabAdminDepartment: {
- "pagePath": "/pages/admin/department",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "部门",
- "fontIcon": "w-icon-user"
- },
- tabAdminPersonnel: {
- "pagePath": "/pages/admin/personnel",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "员工",
- "fontIcon": "w-icon-user"
- },
-
- tabSaleCustom: {
- "pagePath": "/pages/sale/custom",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "客户",
- "fontIcon": "w-icon-user"
- },
-
- tabSaleAdminCustom: {
- "pagePath": "/pages/saleadmin/custom",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "客户",
- "fontIcon": "w-icon-user"
- },
- tabSaleAdminPerformance: {
- "pagePath": "/pages/saleadmin/performance",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "业绩",
- "fontIcon": "w-icon-user"
- },
- tabSaleadminPersonnel: {
- "pagePath": "/pages/saleadmin/personnel",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "员工",
- "fontIcon": "w-icon-user"
- },
-
- tabEvaluateCustom: {
- "pagePath": "/pages/evaluate/custom",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "客户",
- "fontIcon": "w-icon-user"
- },
-
- tabEvaluateadminCustom: {
- "pagePath": "/pages/evaluateadmin/custom",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "客户",
- "fontIcon": "w-icon-user"
- },
- tabEvaluateadminPerformance: {
- "pagePath": "/pages/evaluateadmin/performance",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "业绩",
- "fontIcon": "w-icon-user"
- },
- tabEvaluateadminPersonnel: {
- "pagePath": "/pages/evaluateadmin/personnel",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "员工",
- "fontIcon": "w-icon-user"
- },
-
- tabOperationCustom: {
- "pagePath": "/pages/operation/custom",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "客户",
- "fontIcon": "w-icon-user"
- },
-
- tabOperationadminCustom: {
- "pagePath": "/pages/operationadmin/custom",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "客户",
- "fontIcon": "w-icon-user"
- },
- tabOperationadminPerformance: {
- "pagePath": "/pages/operationadmin/performance",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "业绩",
- "fontIcon": "w-icon-user"
- },
- tabOperationadminPersonnel: {
- "pagePath": "/pages/operationadmin/personnel",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "员工",
- "fontIcon": "w-icon-user"
- },
-
- tabMyIndex: {
- "pagePath": "/pages/my/index",
- "selectedIconPath": "/static/tabBar/person_col.png",
- "text": "我的",
- "fontIcon": "w-icon-user"
- },
- },
- };
- },
- methods: {
- changeTab(item) {
- this.$emit('update:activeTab', item)
- },
- }
- }
- </script>
-
- <style lang="scss" scoped>
- [nvue] uni-scroll-view,
- [nvue] uni-swiper-item,
- [nvue] uni-view {
- flex-direction: unset;
- }
-
- [nvue-dir-column] uni-swiper-item,
- [nvue-dir-column] uni-view {
- flex-direction: unset;
- }
-
- .uni-tabbar {
- display: flex;
- position: fixed;
- justify-content: space-around;
- bottom: 0;
- z-index: 999;
- width: 100%;
- height: 101upx;
- padding: 10upx 0;
- box-sizing: border-box;
- -moz-box-sizing: border-box;
- border-top: solid 1upx #ccc;
- background-color: #fff;
- box-shadow: 0px 0px 17upx 1upx rgba(206, 206, 206, 0.32);
-
- .uni-tabbar__item {
- display: block;
- line-height: 40upx;
- font-size: 36upx;
- text-align: center;
- }
-
- .uni-tabbar__icon {
- font-size: 36upx;
- padding-bottom: 4upx;
-
- &.active {
- color: #1ca6ec;
- }
- }
-
- .uni-tabbar__label {
- font-size: 30upx;
-
- &.active {
- color: #1ca6ec;
- }
- }
- }
- </style>
page/index/index/vue
- <template>
- <view>
- <view class="main">
- <adminIndex v-if="activeTab == 'tabAdminIndex'"></adminIndex>
- <adminCustom v-if="activeTab == 'tabAdminCustom'"></adminCustom>
- <adminDepartment v-if="activeTab == 'tabAdminDepartment'"></adminDepartment>
- <adminPersonnel v-if="activeTab == 'tabAdminPersonnel'"></adminPersonnel>
-
- <saleCustom v-if="activeTab == 'tabSaleCustom'"></saleCustom>
-
- <saleadminCustom v-if="activeTab == 'tabSaleAdminCustom'"></saleadminCustom>
- <saleadminPerformance v-if="activeTab == 'tabSaleAdminPerformance'"></saleadminPerformance>
- <saleadminPersonnel v-if="activeTab == 'tabSaleadminPersonnel'"></saleadminPersonnel>
-
- <evaluateCustom v-if="activeTab == 'tabEvaluateCustom'"></evaluateCustom>
-
- <evaluateadminCustom v-if="activeTab == 'tabEvaluateadminCustom'"></evaluateadminCustom>
- <evaluateadminPerformance v-if="activeTab == 'tabEvaluateadminPerformance'"></evaluateadminPerformance>
- <evaluateadminPersonnel v-if="activeTab == 'tabEvaluateadminPersonnel'"></evaluateadminPersonnel>
-
- <operationCustom v-if="activeTab == 'tabOperationCustom'"></operationCustom>
-
- <operationadminCustom v-if="activeTab == 'tabOperationadminCustom'"></operationadminCustom>
- <operationadminPerformance v-if="activeTab == 'tabOperationadminPerformance'"></operationadminPerformance>
- <operationadminPersonnel v-if="activeTab == 'tabOperationadminPersonnel'"></operationadminPersonnel>
-
- <my v-if="activeTab == 'tabMyIndex'"></my>
- </view>
- <view class="footer">
- <myTabbar :tabList="tabbar" v-model:activeTab="activeTab"></myTabbar>
- </view>
- </view>
- </template>
-
- <script>
- import myTabbar from '@/components/mytabbar.vue'
-
- import adminIndex from '@/pages/admin/index.vue'
- import adminCustom from '@/pages/admin/custom.vue'
- import adminDepartment from '@/pages/admin/department.vue'
- import adminPersonnel from '@/pages/admin/personnel.vue'
-
- import saleCustom from '@/pages/sale/custom.vue'
-
- import saleadminCustom from '@/pages/saleadmin/custom.vue'
- import saleadminPerformance from '@/pages/saleadmin/performance.vue'
- import saleadminPersonnel from '@/pages/saleadmin/personnel.vue'
-
- import evaluateCustom from '@/pages/evaluate/custom.vue'
-
- import evaluateadminCustom from '@/pages/evaluateadmin/custom.vue'
- import evaluateadminPerformance from '@/pages/evaluateadmin/performance.vue'
- import evaluateadminPersonnel from '@/pages/evaluateadmin/personnel.vue'
-
- import operationCustom from '@/pages/operation/custom.vue'
-
- import operationadminCustom from '@/pages/operationadmin/custom.vue'
- import operationadminPerformance from '@/pages/operationadmin/performance.vue'
- import operationadminPersonnel from '@/pages/operationadmin/personnel.vue'
-
- import my from '@/pages/my/index.vue'
-
- export default {
- data() {
- return {
- tabbar: [],
- activeTab: '',
- }
- },
- methods: {},
- onLoad() {
- let _role = localStorage.getItem('token')
-
- console.log(_role)
- if (_role == null || _role == '') {
- uni.reLaunch({
- url: '/pages/login/index'
- })
- }
-
- if (_role == 'admin') {
- this.tabbar = [
- 'tabAdminIndex', 'tabAdminCustom', 'tabAdminDepartment', 'tabAdminPersonnel', 'tabMyIndex'
- ]
- this.activeTab = 'tabAdminIndex'
- }
- if (_role == 'sale') {
- this.tabbar = [
- 'tabSaleCustom', 'tabMyIndex'
- ]
- this.activeTab = 'tabSaleCustom'
- }
- if (_role == 'saleadmin') {
- this.tabbar = [
- 'tabSaleAdminCustom', 'tabSaleAdminPerformance', 'tabSaleadminPersonnel', 'tabMyIndex'
- ]
- this.activeTab = 'tabSaleAdminCustom'
- }
- if (_role == 'evaluate') {
- this.tabbar = [
- 'tabEvaluateCustom', 'tabMyIndex'
- ]
- this.activeTab = 'tabEvaluateCustom'
- }
- if (_role == 'evaluateadmin') {
- this.tabbar = [
- 'tabEvaluateadminCustom', 'tabEvaluateadminPerformance', 'tabEvaluateadminPersonnel',
- 'tabMyIndex'
- ]
- this.activeTab = 'tabEvaluateadminCustom'
- }
- if (_role == 'operation') {
- this.tabbar = [
- 'tabOperationCustom', 'tabMyIndex'
- ]
- this.activeTab = 'tabOperationCustom'
- }
- if (_role == 'operationadmin') {
- this.tabbar = [
- 'tabOperationadminCustom', 'tabOperationadminPerformance', 'tabOperationadminPersonnel',
- 'tabMyIndex'
- ]
- this.activeTab = 'tabOperationadminCustom'
- }
- },
- components: {
- myTabbar,
- adminIndex,
- adminCustom,
- adminDepartment,
- adminPersonnel,
- saleCustom,
- saleadminCustom,
- saleadminPerformance,
- saleadminPersonnel,
- evaluateCustom,
- evaluateadminCustom,
- evaluateadminPerformance,
- evaluateadminPersonnel,
- operationCustom,
- operationadminCustom,
- operationadminPerformance,
- operationadminPersonnel,
- my
- }
- }
- </script>
-
- <style lang="scss" scoped>
- .main {
- height: calc(100vh - 101upx);
- overflow-y: scroll;
- }
- .footer {
- height: 101upx;
- }
- </style>
page/login/index.vue
- <template>
- <view class="page">
- <view class="content">
- <view class="title">用户登录</view>
- <form class="login-form">
- <view class="form-item form-item-inline">
- <text class="w-icon-user"></text>
- <input v-model="loginData.account" placeholder="请输入密码" />
- <text v-if="loginData.account.length > 0" class="w-icon-circle-close"
- @click="loginData.account = ''"></text>
- </view>
- <view class="form-item form-item-inline">
- <text class="w-icon-lock"></text>
- <input v-model="loginData.password" placeholder="请输入密码" :password="!showpwd" />
- <text v-if="showpwd && loginData.password.length > 0" class="w-icon-eye-o" @click="showpwd = !showpwd"></text>
- <text v-if="!showpwd && loginData.password.length > 0" class="w-icon-eye" @click="showpwd = !showpwd"></text>
-
- </view>
- <button class="submit-btn" @click="doLogin">登 录</button>
-
- <button class="" @click="toHome('admin')">管理员</button>
- <button class="" @click="toHome('sale')">销售</button>
- <button class="" @click="toHome('saleadmin')">销售管理</button>
- <button class="" @click="toHome('evaluate')">测评</button>
- <button class="" @click="toHome('evaluateadmin')">测评管理</button>
- <button class="" @click="toHome('operation')">运营管理</button>
- <button class="" @click="toHome('operationadmin')">运营管理</button>
- </form>
- </view>
- </view>
- </template>
-
- <script>
- import fun from '../../common/fun'
- export default {
- data() {
- return {
- loginData: {
- account: '',
- password: '',
- },
- showpwd: false,
- }
- },
- methods: {
- doLogin() {
- fun.toPage('/pages/index/index')
- },
-
- toHome(type) {
- localStorage.setItem('token', type)
-
- uni.reLaunch({
- url: '/pages/index/index'
- })
- },
- }
- }
- </script>
-
- <style lang="scss">
- .content {
- position: absolute;
- width: calc(100% - 60px);
- top: 100px;
- left: 50%;
- transform: translateX(-50%);
-
- .title {
- width: 100%;
- font-size: 20px;
- text-align: center;
- margin-bottom: 30px;
- }
-
- .login-form {
- width: 100%;
-
- .form-item-inline {
- display: inline-flex;
- }
-
- .form-item {
- border-bottom: solid 1px #ddd;
- padding: 8px 3px;
- height: 56px;
- width: 100%;
- box-sizing: border-box;
- -moz-box-sizing: border-box;
- -webkit-box-sizing: border-box;
-
- input {
- height: 40px;
- width: 100%;
- line-height: 40px;
- font-size: 16px;
- padding: 0 5px;
- }
-
- [class^="w-icon-"],
- [class*=" w-icon-"] {
- font-size: 18px;
- margin-top: 10px;
- }
- }
-
- .submit-btn {
- margin-top: 50px;
- background-color: deepskyblue;
- color: #fff;
- }
- }
- }
- </style>
page.json
- {
- "easycom": {
- "autoscan": true,
- "custom": {
- // uni-ui 规则如下配置
- "^uni-(.*)": "@uni_modules/uni-$1/uni-$1.vue"
- }
- },
- "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
- {
- "path": "pages/login/index",
- "style": {
- "navigationStyle": "custom"
- }
- }
-
- , {
- "path": "pages/index/index"
- }
-
- , {
- "path": "pages/my/index"
- }
-
- , {
- "path": "pages/admin/index"
- }, {
- "path": "pages/admin/custom"
- }, {
- "path": "pages/admin/department"
- }, {
- "path": "pages/admin/personnel"
- }
-
- , {
- "path": "pages/sale/custom"
- }
-
- , {
- "path": "pages/saleadmin/custom"
- }, {
- "path": "pages/saleadmin/performance"
- }, {
- "path": "pages/saleadmin/personnel"
- }
-
- , {
- "path": "pages/evaluate/custom"
- }
-
- , {
- "path": "pages/evaluateadmin/custom"
- }, {
- "path": "pages/evaluateadmin/performance"
- }, {
- "path": "pages/evaluateadmin/personnel"
- }
-
- , {
- "path": "pages/operation/custom"
- }
-
- , {
- "path": "pages/operationadmin/custom"
- }, {
- "path": "pages/operationadmin/performance"
- }, {
- "path": "pages/operationadmin/personnel"
- }
- ],
- "globalStyle": {
- "navigationBarTextStyle": "black",
- "navigationBarTitleText": "uni-app",
- "navigationBarBackgroundColor": "#F8F8F8",
- "backgroundColor": "#F8F8F8"
- },
- "uniIdRouter": {}
- }
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。