tabbar.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view :class="[AppTheme]" class="tabbar" :style="{'padding-bottom':BottomBlackLineHeight+'rpx'}">
  3. <view class="tabbar-item" v-for="(item,index) in tabbars" :key="index" @click="goswurl(item,index)">
  4. <u-icon labelSize="12" :color="currentPage===item.url?primary2:'#82848a'" :label="item.title"
  5. labelPos="bottom" :labelColor="currentPage===item.url?primary2:'#82848a'" size="24"
  6. :name="currentPage===item.url?item.img:item.pic"></u-icon>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import homeApi from '@/api/home/index.js';
  12. export default {
  13. props: ["primary"],
  14. data() {
  15. return {
  16. settingFile: this.$siteinfo,
  17. onetabbars: [
  18. '/pages/index/index',
  19. '/pages/index/adoplist/adoplist',
  20. '/pages/mall/mall',
  21. '/pages/land/land',
  22. '/pages/user/user'
  23. ],
  24. tabbars: [{
  25. img: "home",
  26. pic: "home-fill",
  27. title: "首页",
  28. url: "/pages/index/index",
  29. },
  30. {
  31. img: "account",
  32. pic: "account-fill",
  33. title: "我的",
  34. url: "/pages/user/user",
  35. }
  36. ],
  37. active: 0,
  38. currentPage: '',
  39. primary2: "#56AB2F",
  40. BottomBlackLineHeight: 10, //iphoneX底部一条黑线,有些页面要避开
  41. };
  42. },
  43. methods: {
  44. getMobileInfo() {
  45. let that = this
  46. const mobileInfo = uni.getSystemInfoSync();
  47. let iphoneXArr = ["iPhone X", "iPhone 11", "iPhone 11 Pro Max"];
  48. iphoneXArr.forEach(function(item) {
  49. if (mobileInfo.model.search(item) !== -1) {
  50. that.BottomBlackLineHeight = 40;
  51. return
  52. }
  53. });
  54. },
  55. goswurl(item, swindex) {
  56. let that = this
  57. that.$until.toUrl(item.url);
  58. },
  59. },
  60. created() {
  61. let that = this
  62. if (that.primary != '#ffffff') {
  63. that.primary2 = that.primary
  64. }
  65. uni.hideTabBar({}) //隐藏系统默认tabbar
  66. that.getMobileInfo();
  67. let tlist = uni.getStorageSync("tabbar")
  68. let pages = getCurrentPages(); // 获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面
  69. let page = pages[pages.length - 1];
  70. that.currentPage = '/' + page.route; // 当前的页面路由(小程序可以,H5也可以)
  71. /* 初次进入获取tabbar列表 */
  72. if (tlist && tlist.length > 0) {
  73. that.tabbars = tlist
  74. } else {
  75. homeApi.tabbar().then(res => {
  76. if (res.data.tarbar && res.data.tarbar.length > 0) {
  77. that.tabbars = res.data.tarbar;
  78. uni.setStorageSync('tabbar', res.data.tarbar)
  79. }
  80. });
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss">
  86. page {
  87. width: 100%;
  88. }
  89. .tabbar {
  90. height: 100rpx;
  91. width: 100vw;
  92. padding-top: 10rpx;
  93. background-color: #fff;
  94. border: 1px solid #f2f2f2;
  95. position: fixed;
  96. bottom: 0;
  97. z-index: 999;
  98. display: flex;
  99. text-align: center;
  100. align-items: center;
  101. .tabbar-item {
  102. flex: 1;
  103. font-size: 23rpx;
  104. .item-img {
  105. width: 50rpx;
  106. height: 50rpx;
  107. display: inline-block;
  108. margin-bottom: 10rpx;
  109. .image {
  110. width: 100%;
  111. height: 100%;
  112. }
  113. }
  114. }
  115. }
  116. </style>