index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Component({
  2. externalClasses: ['i-class'],
  3. relations: {
  4. '../tab-bar-item/index': {
  5. type: 'child',
  6. linked () {
  7. this.changeCurrent();
  8. },
  9. linkChanged () {
  10. this.changeCurrent();
  11. },
  12. unlinked () {
  13. this.changeCurrent();
  14. }
  15. }
  16. },
  17. properties: {
  18. current: {
  19. type: String,
  20. value: '',
  21. observer: 'changeCurrent'
  22. },
  23. color: {
  24. type: String,
  25. value: ''
  26. },
  27. fixed: {
  28. type: Boolean,
  29. value: false
  30. }
  31. },
  32. data: {
  33. list: []
  34. },
  35. methods: {
  36. changeCurrent (val = this.data.current) {
  37. let items = this.getRelationNodes('../tab-bar-item/index');
  38. const len = items.length;
  39. if (len > 0) {
  40. const list = [];
  41. items.forEach(item => {
  42. item.changeCurrent(item.data.key === val);
  43. item.changeCurrentColor(this.data.color);
  44. list.push({
  45. key: item.data.key
  46. });
  47. });
  48. this.setData({
  49. list: list
  50. });
  51. }
  52. },
  53. emitEvent (key) {
  54. this.triggerEvent('change', { key });
  55. },
  56. handleClickItem (e) {
  57. const key = e.currentTarget.dataset.key;
  58. this.emitEvent(key);
  59. }
  60. }
  61. });