index.vue 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <uni-shadow-root class="vant-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/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. url: {
  31. type: String,
  32. value: '',
  33. },
  34. linkType: {
  35. type: String,
  36. value: 'redirectTo',
  37. },
  38. iconPrefix: {
  39. type: String,
  40. value: 'van-icon',
  41. },
  42. },
  43. relation: useParent('tabbar'),
  44. data: {
  45. active: false,
  46. activeColor: '',
  47. inactiveColor: '',
  48. },
  49. methods: {
  50. onClick() {
  51. const { parent } = this;
  52. if (parent) {
  53. const index = parent.children.indexOf(this);
  54. const active = this.data.name || index;
  55. if (active !== this.data.active) {
  56. parent.$emit('change', active);
  57. }
  58. }
  59. const { url, linkType } = this.data;
  60. if (url && wx[linkType]) {
  61. return wx[linkType]({ url });
  62. }
  63. this.$emit('click');
  64. },
  65. updateFromParent() {
  66. const { parent } = this;
  67. if (!parent) {
  68. return;
  69. }
  70. const index = parent.children.indexOf(this);
  71. const parentData = parent.data;
  72. const { data } = this;
  73. const active = (data.name || index) === parentData.active;
  74. const patch = {};
  75. if (active !== data.active) {
  76. patch.active = active;
  77. }
  78. if (parentData.activeColor !== data.activeColor) {
  79. patch.activeColor = parentData.activeColor;
  80. }
  81. if (parentData.inactiveColor !== data.inactiveColor) {
  82. patch.inactiveColor = parentData.inactiveColor;
  83. }
  84. if (Object.keys(patch).length > 0) {
  85. this.setData(patch);
  86. }
  87. },
  88. },
  89. });
  90. export default global['__wxComponents']['vant/tabbar-item/index']
  91. </script>
  92. <style platform="mp-weixin">
  93. @import '../common/index.css';.vant-tabbar-item-index{flex:1}.van-tabbar-item{align-items:center;color:var(--tabbar-item-text-color,#646566);display:flex;flex-direction:column;font-size:var(--tabbar-item-font-size,12px);height:100%;justify-content:center;line-height:var(--tabbar-item-line-height,1)}.van-tabbar-item__icon{font-size:var(--tabbar-item-icon-size,22px);margin-bottom:var(--tabbar-item-margin-bottom,4px);position:relative}.van-tabbar-item__icon__inner{display:block;min-width:1em}.van-tabbar-item--active{color:var(--tabbar-item-active-color,#1989fa)}.van-tabbar-item__info{margin-top:2px}
  94. </style>