index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _utils = require("../utils");
  5. var _constant = require("../utils/constant");
  6. var _interceptor = require("../utils/interceptor");
  7. var _relation = require("../mixins/relation");
  8. var _createNamespace = (0, _utils.createNamespace)('tabbar'),
  9. createComponent = _createNamespace[0],
  10. bem = _createNamespace[1];
  11. var _default = createComponent({
  12. mixins: [(0, _relation.ParentMixin)('vanTabbar')],
  13. props: {
  14. route: Boolean,
  15. zIndex: [Number, String],
  16. placeholder: Boolean,
  17. activeColor: String,
  18. beforeChange: Function,
  19. inactiveColor: String,
  20. value: {
  21. type: [Number, String],
  22. default: 0
  23. },
  24. border: {
  25. type: Boolean,
  26. default: true
  27. },
  28. fixed: {
  29. type: Boolean,
  30. default: true
  31. },
  32. safeAreaInsetBottom: {
  33. type: Boolean,
  34. default: null
  35. }
  36. },
  37. data: function data() {
  38. return {
  39. height: null
  40. };
  41. },
  42. computed: {
  43. fit: function fit() {
  44. if (this.safeAreaInsetBottom !== null) {
  45. return this.safeAreaInsetBottom;
  46. } // enable safe-area-inset-bottom by default when fixed
  47. return this.fixed;
  48. }
  49. },
  50. watch: {
  51. value: 'setActiveItem',
  52. children: 'setActiveItem'
  53. },
  54. mounted: function mounted() {
  55. if (this.placeholder && this.fixed) {
  56. this.height = this.$refs.tabbar.getBoundingClientRect().height;
  57. }
  58. },
  59. methods: {
  60. setActiveItem: function setActiveItem() {
  61. var _this = this;
  62. this.children.forEach(function (item, index) {
  63. item.active = (item.name || index) === _this.value;
  64. });
  65. },
  66. onChange: function onChange(active) {
  67. var _this2 = this;
  68. if (active !== this.value) {
  69. (0, _interceptor.callInterceptor)({
  70. interceptor: this.beforeChange,
  71. args: [active],
  72. done: function done() {
  73. _this2.$emit('input', active);
  74. _this2.$emit('change', active);
  75. }
  76. });
  77. }
  78. },
  79. genTabbar: function genTabbar() {
  80. var _ref;
  81. var h = this.$createElement;
  82. return h("div", {
  83. "ref": "tabbar",
  84. "style": {
  85. zIndex: this.zIndex
  86. },
  87. "class": [(_ref = {}, _ref[_constant.BORDER_TOP_BOTTOM] = this.border, _ref), bem({
  88. unfit: !this.fit,
  89. fixed: this.fixed
  90. })]
  91. }, [this.slots()]);
  92. }
  93. },
  94. render: function render() {
  95. var h = arguments[0];
  96. if (this.placeholder && this.fixed) {
  97. return h("div", {
  98. "class": bem('placeholder'),
  99. "style": {
  100. height: this.height + "px"
  101. }
  102. }, [this.genTabbar()]);
  103. }
  104. return this.genTabbar();
  105. }
  106. });
  107. exports.default = _default;