index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. Component({
  2. options: {
  3. multipleSlots: true // 在组件定义时的选项中启用多slot支持
  4. },
  5. relations: {
  6. '../grid-item/index': {
  7. type: 'child',
  8. linked(target) {
  9. this.initGrids();
  10. },
  11. unlinked(target) {
  12. this.initGrids();
  13. }
  14. },
  15. },
  16. externalClasses: ['l-class', 'l-class-grid'],
  17. properties: {
  18. rowNum: {
  19. type: String,
  20. value: 3,
  21. },
  22. showBorder: Boolean,
  23. showColBorder: Boolean,
  24. showRowBorder: Boolean,
  25. },
  26. data: {
  27. gridItems: [],
  28. childNum: 0,
  29. currentIndex:null,
  30. },
  31. ready() {
  32. this.initGrids();
  33. },
  34. lifetimes: {
  35. show() {
  36. },
  37. },
  38. methods: {
  39. initGrids() {
  40. let items = this.getRelationNodes('../grid-item/index');
  41. if (this.data.childNum === items.length) return;
  42. const gridItems = items.map((item) => {
  43. return {
  44. key: item.data.key
  45. }
  46. });
  47. this.setData({
  48. gridItems: gridItems,
  49. childNum: items.length
  50. })
  51. },
  52. tapGridItem(e) {
  53. const {
  54. index
  55. } = e.currentTarget.dataset;
  56. this.setData({
  57. currentIndex:index
  58. });
  59. let items = this.getRelationNodes('../grid-item/index');
  60. items[index].tapGridItem({
  61. index: index
  62. });
  63. },
  64. tapGrid(e) {
  65. this.triggerEvent('lintap', {
  66. index:this.data.currentIndex
  67. })
  68. }
  69. }
  70. });