当前位置:   article > 正文

uniapp 自定义底部tabbar(无闪烁)_uniapp h5苹果tabbar跳动

uniapp h5苹果tabbar跳动

思路:

1.创建自定义的tabbar组件

2.增加启动页面page/index/index

3.在启动页面加载所有tab页面,使用tabbar组件进行切换

主要代码:

mytabbar.vue

  1. <template>
  2. <view class="uni-tabbar">
  3. <view class="uni-tabbar__item" v-for="(item,index) in tabList" :key="index" @tap="changeTab(item)">
  4. <view class="uni-tabbar__icon" :class="[tabs[item].fontIcon, item == activeTab? 'active':'']"></view>
  5. <view class="uni-tabbar__label" :class="{'active': item == activeTab}">
  6. {{tabs[item].text}}
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. props: {
  14. tabList: {
  15. type: Array,
  16. default: ['tabMyIndex']
  17. },
  18. activeTab: {
  19. type: String,
  20. default: ''
  21. }
  22. },
  23. emits:['update:activeTab'],
  24. data() {
  25. return {
  26. tabs: {
  27. tabAdminIndex: {
  28. "pagePath": "/pages/admin/index",
  29. "selectedIconPath": "/static/tabBar/home_col.png",
  30. "text": "首页",
  31. "fontIcon": "w-icon-home"
  32. },
  33. tabAdminCustom: {
  34. "pagePath": "/pages/admin/custom",
  35. "selectedIconPath": "/static/tabBar/home_col.png",
  36. "text": "客户",
  37. "fontIcon": "w-icon-qq"
  38. },
  39. tabAdminDepartment: {
  40. "pagePath": "/pages/admin/department",
  41. "selectedIconPath": "/static/tabBar/person_col.png",
  42. "text": "部门",
  43. "fontIcon": "w-icon-user"
  44. },
  45. tabAdminPersonnel: {
  46. "pagePath": "/pages/admin/personnel",
  47. "selectedIconPath": "/static/tabBar/person_col.png",
  48. "text": "员工",
  49. "fontIcon": "w-icon-user"
  50. },
  51. tabSaleCustom: {
  52. "pagePath": "/pages/sale/custom",
  53. "selectedIconPath": "/static/tabBar/person_col.png",
  54. "text": "客户",
  55. "fontIcon": "w-icon-user"
  56. },
  57. tabSaleAdminCustom: {
  58. "pagePath": "/pages/saleadmin/custom",
  59. "selectedIconPath": "/static/tabBar/person_col.png",
  60. "text": "客户",
  61. "fontIcon": "w-icon-user"
  62. },
  63. tabSaleAdminPerformance: {
  64. "pagePath": "/pages/saleadmin/performance",
  65. "selectedIconPath": "/static/tabBar/person_col.png",
  66. "text": "业绩",
  67. "fontIcon": "w-icon-user"
  68. },
  69. tabSaleadminPersonnel: {
  70. "pagePath": "/pages/saleadmin/personnel",
  71. "selectedIconPath": "/static/tabBar/person_col.png",
  72. "text": "员工",
  73. "fontIcon": "w-icon-user"
  74. },
  75. tabEvaluateCustom: {
  76. "pagePath": "/pages/evaluate/custom",
  77. "selectedIconPath": "/static/tabBar/person_col.png",
  78. "text": "客户",
  79. "fontIcon": "w-icon-user"
  80. },
  81. tabEvaluateadminCustom: {
  82. "pagePath": "/pages/evaluateadmin/custom",
  83. "selectedIconPath": "/static/tabBar/person_col.png",
  84. "text": "客户",
  85. "fontIcon": "w-icon-user"
  86. },
  87. tabEvaluateadminPerformance: {
  88. "pagePath": "/pages/evaluateadmin/performance",
  89. "selectedIconPath": "/static/tabBar/person_col.png",
  90. "text": "业绩",
  91. "fontIcon": "w-icon-user"
  92. },
  93. tabEvaluateadminPersonnel: {
  94. "pagePath": "/pages/evaluateadmin/personnel",
  95. "selectedIconPath": "/static/tabBar/person_col.png",
  96. "text": "员工",
  97. "fontIcon": "w-icon-user"
  98. },
  99. tabOperationCustom: {
  100. "pagePath": "/pages/operation/custom",
  101. "selectedIconPath": "/static/tabBar/person_col.png",
  102. "text": "客户",
  103. "fontIcon": "w-icon-user"
  104. },
  105. tabOperationadminCustom: {
  106. "pagePath": "/pages/operationadmin/custom",
  107. "selectedIconPath": "/static/tabBar/person_col.png",
  108. "text": "客户",
  109. "fontIcon": "w-icon-user"
  110. },
  111. tabOperationadminPerformance: {
  112. "pagePath": "/pages/operationadmin/performance",
  113. "selectedIconPath": "/static/tabBar/person_col.png",
  114. "text": "业绩",
  115. "fontIcon": "w-icon-user"
  116. },
  117. tabOperationadminPersonnel: {
  118. "pagePath": "/pages/operationadmin/personnel",
  119. "selectedIconPath": "/static/tabBar/person_col.png",
  120. "text": "员工",
  121. "fontIcon": "w-icon-user"
  122. },
  123. tabMyIndex: {
  124. "pagePath": "/pages/my/index",
  125. "selectedIconPath": "/static/tabBar/person_col.png",
  126. "text": "我的",
  127. "fontIcon": "w-icon-user"
  128. },
  129. },
  130. };
  131. },
  132. methods: {
  133. changeTab(item) {
  134. this.$emit('update:activeTab', item)
  135. },
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. [nvue] uni-scroll-view,
  141. [nvue] uni-swiper-item,
  142. [nvue] uni-view {
  143. flex-direction: unset;
  144. }
  145. [nvue-dir-column] uni-swiper-item,
  146. [nvue-dir-column] uni-view {
  147. flex-direction: unset;
  148. }
  149. .uni-tabbar {
  150. display: flex;
  151. position: fixed;
  152. justify-content: space-around;
  153. bottom: 0;
  154. z-index: 999;
  155. width: 100%;
  156. height: 101upx;
  157. padding: 10upx 0;
  158. box-sizing: border-box;
  159. -moz-box-sizing: border-box;
  160. border-top: solid 1upx #ccc;
  161. background-color: #fff;
  162. box-shadow: 0px 0px 17upx 1upx rgba(206, 206, 206, 0.32);
  163. .uni-tabbar__item {
  164. display: block;
  165. line-height: 40upx;
  166. font-size: 36upx;
  167. text-align: center;
  168. }
  169. .uni-tabbar__icon {
  170. font-size: 36upx;
  171. padding-bottom: 4upx;
  172. &.active {
  173. color: #1ca6ec;
  174. }
  175. }
  176. .uni-tabbar__label {
  177. font-size: 30upx;
  178. &.active {
  179. color: #1ca6ec;
  180. }
  181. }
  182. }
  183. </style>

page/index/index/vue

  1. <template>
  2. <view>
  3. <view class="main">
  4. <adminIndex v-if="activeTab == 'tabAdminIndex'"></adminIndex>
  5. <adminCustom v-if="activeTab == 'tabAdminCustom'"></adminCustom>
  6. <adminDepartment v-if="activeTab == 'tabAdminDepartment'"></adminDepartment>
  7. <adminPersonnel v-if="activeTab == 'tabAdminPersonnel'"></adminPersonnel>
  8. <saleCustom v-if="activeTab == 'tabSaleCustom'"></saleCustom>
  9. <saleadminCustom v-if="activeTab == 'tabSaleAdminCustom'"></saleadminCustom>
  10. <saleadminPerformance v-if="activeTab == 'tabSaleAdminPerformance'"></saleadminPerformance>
  11. <saleadminPersonnel v-if="activeTab == 'tabSaleadminPersonnel'"></saleadminPersonnel>
  12. <evaluateCustom v-if="activeTab == 'tabEvaluateCustom'"></evaluateCustom>
  13. <evaluateadminCustom v-if="activeTab == 'tabEvaluateadminCustom'"></evaluateadminCustom>
  14. <evaluateadminPerformance v-if="activeTab == 'tabEvaluateadminPerformance'"></evaluateadminPerformance>
  15. <evaluateadminPersonnel v-if="activeTab == 'tabEvaluateadminPersonnel'"></evaluateadminPersonnel>
  16. <operationCustom v-if="activeTab == 'tabOperationCustom'"></operationCustom>
  17. <operationadminCustom v-if="activeTab == 'tabOperationadminCustom'"></operationadminCustom>
  18. <operationadminPerformance v-if="activeTab == 'tabOperationadminPerformance'"></operationadminPerformance>
  19. <operationadminPersonnel v-if="activeTab == 'tabOperationadminPersonnel'"></operationadminPersonnel>
  20. <my v-if="activeTab == 'tabMyIndex'"></my>
  21. </view>
  22. <view class="footer">
  23. <myTabbar :tabList="tabbar" v-model:activeTab="activeTab"></myTabbar>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import myTabbar from '@/components/mytabbar.vue'
  29. import adminIndex from '@/pages/admin/index.vue'
  30. import adminCustom from '@/pages/admin/custom.vue'
  31. import adminDepartment from '@/pages/admin/department.vue'
  32. import adminPersonnel from '@/pages/admin/personnel.vue'
  33. import saleCustom from '@/pages/sale/custom.vue'
  34. import saleadminCustom from '@/pages/saleadmin/custom.vue'
  35. import saleadminPerformance from '@/pages/saleadmin/performance.vue'
  36. import saleadminPersonnel from '@/pages/saleadmin/personnel.vue'
  37. import evaluateCustom from '@/pages/evaluate/custom.vue'
  38. import evaluateadminCustom from '@/pages/evaluateadmin/custom.vue'
  39. import evaluateadminPerformance from '@/pages/evaluateadmin/performance.vue'
  40. import evaluateadminPersonnel from '@/pages/evaluateadmin/personnel.vue'
  41. import operationCustom from '@/pages/operation/custom.vue'
  42. import operationadminCustom from '@/pages/operationadmin/custom.vue'
  43. import operationadminPerformance from '@/pages/operationadmin/performance.vue'
  44. import operationadminPersonnel from '@/pages/operationadmin/personnel.vue'
  45. import my from '@/pages/my/index.vue'
  46. export default {
  47. data() {
  48. return {
  49. tabbar: [],
  50. activeTab: '',
  51. }
  52. },
  53. methods: {},
  54. onLoad() {
  55. let _role = localStorage.getItem('token')
  56. console.log(_role)
  57. if (_role == null || _role == '') {
  58. uni.reLaunch({
  59. url: '/pages/login/index'
  60. })
  61. }
  62. if (_role == 'admin') {
  63. this.tabbar = [
  64. 'tabAdminIndex', 'tabAdminCustom', 'tabAdminDepartment', 'tabAdminPersonnel', 'tabMyIndex'
  65. ]
  66. this.activeTab = 'tabAdminIndex'
  67. }
  68. if (_role == 'sale') {
  69. this.tabbar = [
  70. 'tabSaleCustom', 'tabMyIndex'
  71. ]
  72. this.activeTab = 'tabSaleCustom'
  73. }
  74. if (_role == 'saleadmin') {
  75. this.tabbar = [
  76. 'tabSaleAdminCustom', 'tabSaleAdminPerformance', 'tabSaleadminPersonnel', 'tabMyIndex'
  77. ]
  78. this.activeTab = 'tabSaleAdminCustom'
  79. }
  80. if (_role == 'evaluate') {
  81. this.tabbar = [
  82. 'tabEvaluateCustom', 'tabMyIndex'
  83. ]
  84. this.activeTab = 'tabEvaluateCustom'
  85. }
  86. if (_role == 'evaluateadmin') {
  87. this.tabbar = [
  88. 'tabEvaluateadminCustom', 'tabEvaluateadminPerformance', 'tabEvaluateadminPersonnel',
  89. 'tabMyIndex'
  90. ]
  91. this.activeTab = 'tabEvaluateadminCustom'
  92. }
  93. if (_role == 'operation') {
  94. this.tabbar = [
  95. 'tabOperationCustom', 'tabMyIndex'
  96. ]
  97. this.activeTab = 'tabOperationCustom'
  98. }
  99. if (_role == 'operationadmin') {
  100. this.tabbar = [
  101. 'tabOperationadminCustom', 'tabOperationadminPerformance', 'tabOperationadminPersonnel',
  102. 'tabMyIndex'
  103. ]
  104. this.activeTab = 'tabOperationadminCustom'
  105. }
  106. },
  107. components: {
  108. myTabbar,
  109. adminIndex,
  110. adminCustom,
  111. adminDepartment,
  112. adminPersonnel,
  113. saleCustom,
  114. saleadminCustom,
  115. saleadminPerformance,
  116. saleadminPersonnel,
  117. evaluateCustom,
  118. evaluateadminCustom,
  119. evaluateadminPerformance,
  120. evaluateadminPersonnel,
  121. operationCustom,
  122. operationadminCustom,
  123. operationadminPerformance,
  124. operationadminPersonnel,
  125. my
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .main {
  131. height: calc(100vh - 101upx);
  132. overflow-y: scroll;
  133. }
  134. .footer {
  135. height: 101upx;
  136. }
  137. </style>

page/login/index.vue

  1. <template>
  2. <view class="page">
  3. <view class="content">
  4. <view class="title">用户登录</view>
  5. <form class="login-form">
  6. <view class="form-item form-item-inline">
  7. <text class="w-icon-user"></text>
  8. <input v-model="loginData.account" placeholder="请输入密码" />
  9. <text v-if="loginData.account.length > 0" class="w-icon-circle-close"
  10. @click="loginData.account = ''"></text>
  11. </view>
  12. <view class="form-item form-item-inline">
  13. <text class="w-icon-lock"></text>
  14. <input v-model="loginData.password" placeholder="请输入密码" :password="!showpwd" />
  15. <text v-if="showpwd && loginData.password.length > 0" class="w-icon-eye-o" @click="showpwd = !showpwd"></text>
  16. <text v-if="!showpwd && loginData.password.length > 0" class="w-icon-eye" @click="showpwd = !showpwd"></text>
  17. </view>
  18. <button class="submit-btn" @click="doLogin">登 录</button>
  19. <button class="" @click="toHome('admin')">管理员</button>
  20. <button class="" @click="toHome('sale')">销售</button>
  21. <button class="" @click="toHome('saleadmin')">销售管理</button>
  22. <button class="" @click="toHome('evaluate')">测评</button>
  23. <button class="" @click="toHome('evaluateadmin')">测评管理</button>
  24. <button class="" @click="toHome('operation')">运营管理</button>
  25. <button class="" @click="toHome('operationadmin')">运营管理</button>
  26. </form>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import fun from '../../common/fun'
  32. export default {
  33. data() {
  34. return {
  35. loginData: {
  36. account: '',
  37. password: '',
  38. },
  39. showpwd: false,
  40. }
  41. },
  42. methods: {
  43. doLogin() {
  44. fun.toPage('/pages/index/index')
  45. },
  46. toHome(type) {
  47. localStorage.setItem('token', type)
  48. uni.reLaunch({
  49. url: '/pages/index/index'
  50. })
  51. },
  52. }
  53. }
  54. </script>
  55. <style lang="scss">
  56. .content {
  57. position: absolute;
  58. width: calc(100% - 60px);
  59. top: 100px;
  60. left: 50%;
  61. transform: translateX(-50%);
  62. .title {
  63. width: 100%;
  64. font-size: 20px;
  65. text-align: center;
  66. margin-bottom: 30px;
  67. }
  68. .login-form {
  69. width: 100%;
  70. .form-item-inline {
  71. display: inline-flex;
  72. }
  73. .form-item {
  74. border-bottom: solid 1px #ddd;
  75. padding: 8px 3px;
  76. height: 56px;
  77. width: 100%;
  78. box-sizing: border-box;
  79. -moz-box-sizing: border-box;
  80. -webkit-box-sizing: border-box;
  81. input {
  82. height: 40px;
  83. width: 100%;
  84. line-height: 40px;
  85. font-size: 16px;
  86. padding: 0 5px;
  87. }
  88. [class^="w-icon-"],
  89. [class*=" w-icon-"] {
  90. font-size: 18px;
  91. margin-top: 10px;
  92. }
  93. }
  94. .submit-btn {
  95. margin-top: 50px;
  96. background-color: deepskyblue;
  97. color: #fff;
  98. }
  99. }
  100. }
  101. </style>

page.json

  1. {
  2. "easycom": {
  3. "autoscan": true,
  4. "custom": {
  5. // uni-ui 规则如下配置
  6. "^uni-(.*)": "@uni_modules/uni-$1/uni-$1.vue"
  7. }
  8. },
  9. "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
  10. {
  11. "path": "pages/login/index",
  12. "style": {
  13. "navigationStyle": "custom"
  14. }
  15. }
  16. , {
  17. "path": "pages/index/index"
  18. }
  19. , {
  20. "path": "pages/my/index"
  21. }
  22. , {
  23. "path": "pages/admin/index"
  24. }, {
  25. "path": "pages/admin/custom"
  26. }, {
  27. "path": "pages/admin/department"
  28. }, {
  29. "path": "pages/admin/personnel"
  30. }
  31. , {
  32. "path": "pages/sale/custom"
  33. }
  34. , {
  35. "path": "pages/saleadmin/custom"
  36. }, {
  37. "path": "pages/saleadmin/performance"
  38. }, {
  39. "path": "pages/saleadmin/personnel"
  40. }
  41. , {
  42. "path": "pages/evaluate/custom"
  43. }
  44. , {
  45. "path": "pages/evaluateadmin/custom"
  46. }, {
  47. "path": "pages/evaluateadmin/performance"
  48. }, {
  49. "path": "pages/evaluateadmin/personnel"
  50. }
  51. , {
  52. "path": "pages/operation/custom"
  53. }
  54. , {
  55. "path": "pages/operationadmin/custom"
  56. }, {
  57. "path": "pages/operationadmin/performance"
  58. }, {
  59. "path": "pages/operationadmin/personnel"
  60. }
  61. ],
  62. "globalStyle": {
  63. "navigationBarTextStyle": "black",
  64. "navigationBarTitleText": "uni-app",
  65. "navigationBarBackgroundColor": "#F8F8F8",
  66. "backgroundColor": "#F8F8F8"
  67. },
  68. "uniIdRouter": {}
  69. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/555778
推荐阅读