index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. var relation_1 = require("../common/relation");
  5. (0, component_1.VantComponent)({
  6. props: {
  7. info: null,
  8. name: null,
  9. icon: String,
  10. dot: Boolean,
  11. url: {
  12. type: String,
  13. value: '',
  14. },
  15. linkType: {
  16. type: String,
  17. value: 'redirectTo',
  18. },
  19. iconPrefix: {
  20. type: String,
  21. value: 'van-icon',
  22. },
  23. },
  24. relation: (0, relation_1.useParent)('tabbar'),
  25. data: {
  26. active: false,
  27. activeColor: '',
  28. inactiveColor: '',
  29. },
  30. methods: {
  31. onClick: function () {
  32. var parent = this.parent;
  33. if (parent) {
  34. var index = parent.children.indexOf(this);
  35. var active = this.data.name || index;
  36. if (active !== this.data.active) {
  37. parent.$emit('change', active);
  38. }
  39. }
  40. var _a = this.data, url = _a.url, linkType = _a.linkType;
  41. if (url && wx[linkType]) {
  42. return wx[linkType]({ url: url });
  43. }
  44. this.$emit('click');
  45. },
  46. updateFromParent: function () {
  47. var parent = this.parent;
  48. if (!parent) {
  49. return;
  50. }
  51. var index = parent.children.indexOf(this);
  52. var parentData = parent.data;
  53. var data = this.data;
  54. var active = (data.name || index) === parentData.active;
  55. var 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. if (Object.keys(patch).length > 0) {
  66. this.setData(patch);
  67. }
  68. },
  69. },
  70. });