index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { use } from '../utils';
  3. import Icon from '../icon';
  4. import Info from '../info';
  5. import { route, routeProps } from '../utils/router';
  6. var _use = use('tabbar-item'),
  7. sfc = _use[0],
  8. bem = _use[1];
  9. export default sfc({
  10. props: _extends({}, routeProps, {
  11. icon: String,
  12. dot: Boolean,
  13. info: [String, Number]
  14. }),
  15. data: function data() {
  16. return {
  17. active: false
  18. };
  19. },
  20. beforeCreate: function beforeCreate() {
  21. this.$parent.items.push(this);
  22. },
  23. destroyed: function destroyed() {
  24. this.$parent.items.splice(this.$parent.items.indexOf(this), 1);
  25. },
  26. methods: {
  27. onClick: function onClick(event) {
  28. this.$parent.onChange(this.$parent.items.indexOf(this));
  29. this.$emit('click', event);
  30. route(this.$router, this);
  31. }
  32. },
  33. render: function render(h) {
  34. var icon = this.icon,
  35. slots = this.slots,
  36. active = this.active;
  37. var style = active ? {
  38. color: this.$parent.activeColor
  39. } : null;
  40. return h("div", {
  41. "class": bem({
  42. active: active
  43. }),
  44. "style": style,
  45. "on": {
  46. "click": this.onClick
  47. }
  48. }, [h("div", {
  49. "class": bem('icon', {
  50. dot: this.dot
  51. })
  52. }, [slots('icon', {
  53. active: active
  54. }) || icon && h(Icon, {
  55. "attrs": {
  56. "name": icon
  57. }
  58. }), h(Info, {
  59. "attrs": {
  60. "info": this.info
  61. }
  62. })]), h("div", {
  63. "class": bem('text')
  64. }, [slots('default', {
  65. active: active
  66. })])]);
  67. }
  68. });