index.vue 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <uni-shadow-root class="vant-dist-tabbar-item-index"><view :class="(utils.bem('tabbar-item', { active }))+' custom-class'" :style="'color: '+(active ? activeColor : inactiveColor)" @click="onClick">
  3. <view class="van-tabbar-item__icon">
  4. <van-icon v-if="icon" :name="icon" :class-prefix="iconPrefix" custom-class="van-tabbar-item__icon__inner"></van-icon>
  5. <block v-else>
  6. <slot v-if="active" name="icon-active"></slot>
  7. <slot v-else name="icon"></slot>
  8. </block>
  9. <van-info :dot="dot" :info="info" custom-class="van-tabbar-item__info"></van-info>
  10. </view>
  11. <view class="van-tabbar-item__text">
  12. <slot></slot>
  13. </view>
  14. </view></uni-shadow-root>
  15. </template>
  16. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  17. <script>
  18. import VanIcon from '../icon/index.vue'
  19. import VanInfo from '../info/index.vue'
  20. global['__wxVueOptions'] = {components:{'van-icon': VanIcon,'van-info': VanInfo}}
  21. global['__wxRoute'] = 'vant/dist/tabbar-item/index'
  22. import { VantComponent } from '../common/component';
  23. import { useParent } from '../common/relation';
  24. VantComponent({
  25. props: {
  26. info: null,
  27. name: null,
  28. icon: String,
  29. dot: Boolean,
  30. iconPrefix: {
  31. type: String,
  32. value: 'van-icon',
  33. },
  34. },
  35. relation: useParent('tabbar'),
  36. data: {
  37. active: false,
  38. activeColor: '',
  39. inactiveColor: '',
  40. },
  41. methods: {
  42. onClick() {
  43. const { parent } = this;
  44. if (parent) {
  45. const index = parent.children.indexOf(this);
  46. const active = this.data.name || index;
  47. if (active !== this.data.active) {
  48. parent.$emit('change', active);
  49. }
  50. }
  51. this.$emit('click');
  52. },
  53. updateFromParent() {
  54. const { parent } = this;
  55. if (!parent) {
  56. return;
  57. }
  58. const index = parent.children.indexOf(this);
  59. const parentData = parent.data;
  60. const { data } = this;
  61. const active = (data.name || index) === parentData.active;
  62. const patch = {};
  63. if (active !== data.active) {
  64. patch.active = active;
  65. }
  66. if (parentData.activeColor !== data.activeColor) {
  67. patch.activeColor = parentData.activeColor;
  68. }
  69. if (parentData.inactiveColor !== data.inactiveColor) {
  70. patch.inactiveColor = parentData.inactiveColor;
  71. }
  72. if (Object.keys(patch).length > 0) {
  73. this.setData(patch);
  74. }
  75. },
  76. },
  77. });
  78. export default global['__wxComponents']['vant/dist/tabbar-item/index']
  79. </script>
  80. <style platform="mp-weixin">
  81. @import '../common/index.css';.vant-dist-tabbar-item-index{flex:1}.van-tabbar-item{display:flex;flex-direction:column;align-items:center;justify-content:center;height:100%;color:#646566;color:var(--tabbar-item-text-color,#646566);font-size:12px;font-size:var(--tabbar-item-font-size,12px);line-height:1;line-height:var(--tabbar-item-line-height,1)}.van-tabbar-item__icon{position:relative;margin-bottom:4px;margin-bottom:var(--tabbar-item-margin-bottom,4px);font-size:22px;font-size:var(--tabbar-item-icon-size,22px)}.van-tabbar-item__icon__inner{display:block;min-width:1em}.van-tabbar-item--active{color:#1989fa;color:var(--tabbar-item-active-color,#1989fa)}.van-tabbar-item__info{margin-top:2px}
  82. </style>