row.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { ComputeColStyle, ComputeRowStyle } from './calc'
  2. Component({
  3. options: {
  4. addGlobalClass: true,
  5. },
  6. externalClasses: ['n-class'],
  7. relations: {
  8. '../col/col': {
  9. type: 'child',
  10. },
  11. },
  12. /**
  13. * 组件的属性列表
  14. */
  15. properties: {
  16. gutter: {
  17. type: Number,
  18. optionalTypes: [Array],
  19. value: 0,
  20. observer(newval) {
  21. let passStyle = this.data.style
  22. if (passStyle.length > 0) {
  23. if (!passStyle.endsWith(';')) passStyle += ';'
  24. }
  25. this.setData({
  26. computedStyles: passStyle + ComputeRowStyle(newval),
  27. })
  28. },
  29. },
  30. style: String,
  31. },
  32. observers: {
  33. gutter() {
  34. this.updateChildren()
  35. },
  36. },
  37. /**
  38. * 组件的初始数据
  39. */
  40. data: {
  41. computedStyles: '',
  42. },
  43. /**
  44. * 组件的生命周期
  45. */
  46. lifetimes: {
  47. ready() {
  48. this.updateChildren()
  49. },
  50. },
  51. /**
  52. * 组件的方法列表
  53. */
  54. methods: {
  55. updateChildren() {
  56. const items = this.getRelationNodes('../col/col')
  57. if (items && items.length > 0) {
  58. items.forEach((item) => {
  59. let passStyle = item.data.style
  60. if (passStyle.length > 0) {
  61. if (!passStyle.endsWith(';')) passStyle += ';'
  62. }
  63. item.setData({
  64. computedStyles: passStyle + ComputeColStyle(this.data.gutter),
  65. })
  66. })
  67. }
  68. },
  69. },
  70. })