index.vue 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <uni-shadow-root class="vant-dist-tabbar-index"><view :class="(border ? 'van-hairline--top-bottom' : '')+' '+(utils.bem('tabbar', { fixed, safe: safeAreaInsetBottom }))+' custom-class'" :style="zIndex ? 'z-index: ' + zIndex : ''">
  3. <slot></slot>
  4. </view>
  5. <view v-if="fixed && placeholder" :style="'height: '+(height)+'px;'"></view></uni-shadow-root>
  6. </template>
  7. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  8. <script>
  9. global['__wxRoute'] = 'vant/dist/tabbar/index'
  10. import { VantComponent } from '../common/component';
  11. import { useChildren } from '../common/relation';
  12. import { getRect } from '../common/utils';
  13. VantComponent({
  14. relation: useChildren('tabbar-item', function () {
  15. this.updateChildren();
  16. }),
  17. props: {
  18. active: {
  19. type: null,
  20. observer: 'updateChildren',
  21. },
  22. activeColor: {
  23. type: String,
  24. observer: 'updateChildren',
  25. },
  26. inactiveColor: {
  27. type: String,
  28. observer: 'updateChildren',
  29. },
  30. fixed: {
  31. type: Boolean,
  32. value: true,
  33. observer: 'setHeight',
  34. },
  35. placeholder: {
  36. type: Boolean,
  37. observer: 'setHeight',
  38. },
  39. border: {
  40. type: Boolean,
  41. value: true,
  42. },
  43. zIndex: {
  44. type: Number,
  45. value: 1,
  46. },
  47. safeAreaInsetBottom: {
  48. type: Boolean,
  49. value: true,
  50. },
  51. },
  52. data: {
  53. height: 50,
  54. },
  55. methods: {
  56. updateChildren() {
  57. const { children } = this;
  58. if (!Array.isArray(children) || !children.length) {
  59. return;
  60. }
  61. children.forEach((child) => child.updateFromParent());
  62. },
  63. setHeight() {
  64. if (!this.data.fixed || !this.data.placeholder) {
  65. return;
  66. }
  67. wx.nextTick(() => {
  68. getRect(this, '.van-tabbar').then((res) => {
  69. this.setData({ height: res.height });
  70. });
  71. });
  72. },
  73. },
  74. });
  75. export default global['__wxComponents']['vant/dist/tabbar/index']
  76. </script>
  77. <style platform="mp-weixin">
  78. @import '../common/index.css';.van-tabbar{display:flex;box-sizing:initial;width:100%;height:50px;height:var(--tabbar-height,50px);background-color:#fff;background-color:var(--tabbar-background-color,#fff)}.van-tabbar--fixed{position:fixed;bottom:0;left:0}.van-tabbar--safe{padding-bottom:env(safe-area-inset-bottom)}
  79. </style>