index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. relations: {
  5. '../col/index': {
  6. type: 'child',
  7. observer() {
  8. this.updateStyle()
  9. },
  10. },
  11. },
  12. properties: {
  13. prefixCls: {
  14. type: String,
  15. value: 'wux-row',
  16. },
  17. gutter: {
  18. value: 0,
  19. type: Number,
  20. observer: 'updateStyle',
  21. },
  22. },
  23. data: {
  24. rowStyle: '',
  25. },
  26. computed: {
  27. classes() {
  28. const { prefixCls } = this.data
  29. const wrap = classNames(prefixCls)
  30. return {
  31. wrap,
  32. }
  33. },
  34. },
  35. methods: {
  36. updateStyle(gutter = this.data.gutter) {
  37. const elements = this.getRelationNodes('../col/index')
  38. const rowStyle = gutter > 0 ? `margin-left: ${gutter / -2}px; margin-right: ${gutter / -2}px` : ''
  39. const colStyle = gutter > 0 ? `padding-left: ${gutter / 2}px; padding-right: ${gutter / 2}px` : ''
  40. if (elements.length > 0) {
  41. elements.forEach((element) => {
  42. element.updateStyle(colStyle)
  43. })
  44. }
  45. this.setData({
  46. rowStyle,
  47. })
  48. },
  49. },
  50. })