index.vue 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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="utils.bem('tabbar-item__icon', { dot })">
  4. <van-icon v-if="icon" :name="icon" customStyle="display: block"></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 v-if="info !== null" :info="info" custom-style="margin-top: 2px"></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. VantComponent({
  24. props: {
  25. info: null,
  26. icon: String,
  27. dot: Boolean,
  28. name: {
  29. type: [String, Number]
  30. }
  31. },
  32. relation: {
  33. name: 'tabbar',
  34. type: 'ancestor'
  35. },
  36. data: {
  37. active: false
  38. },
  39. methods: {
  40. onClick() {
  41. if (this.parent) {
  42. this.parent.onChange(this);
  43. }
  44. this.$emit('click');
  45. },
  46. updateFromParent() {
  47. const { parent } = this;
  48. if (!parent) {
  49. return;
  50. }
  51. const index = parent.children.indexOf(this);
  52. const parentData = parent.data;
  53. const { data } = this;
  54. const active = (data.name || index) === parentData.active;
  55. const patch = {};
  56. if (active !== data.active) {
  57. patch.active = active;
  58. }
  59. if (parentData.activeColor !== data.activeColor) {
  60. patch.activeColor = parentData.activeColor;
  61. }
  62. if (parentData.inactiveColor !== data.inactiveColor) {
  63. patch.inactiveColor = parentData.inactiveColor;
  64. }
  65. return Object.keys(patch).length > 0
  66. ? this.set(patch)
  67. : Promise.resolve();
  68. }
  69. }
  70. });
  71. export default global['__wxComponents']['vant/tabbar-item/index']
  72. </script>
  73. <style platform="mp-weixin">
  74. @import '../common/index.css';.vant-tabbar-item-index{-webkit-flex:1;flex:1}.van-tabbar-item{color:#7d7e80;height:100%;display:-webkit-flex;display:flex;line-height:1;font-size:12px;-webkit-align-items:center;align-items:center;-webkit-flex-direction:column;flex-direction:column;-webkit-justify-content:center;justify-content:center}.van-tabbar-item__icon{font-size:18px;margin-bottom:5px;position:relative}.van-tabbar-item__icon--dot:after{top:0;right:-8px;width:8px;height:8px;content:" ";position:absolute;border-radius:100%;background-color:#f44}.van-tabbar-item__icon image{width:30px;height:18px;display:block}.van-tabbar-item--active{color:#1989fa}
  75. </style>