index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { createNamespace } from '../utils';
  2. import { ParentMixin } from '../mixins/relation';
  3. var _createNamespace = createNamespace('row'),
  4. createComponent = _createNamespace[0],
  5. bem = _createNamespace[1];
  6. export default createComponent({
  7. mixins: [ParentMixin('vanRow')],
  8. props: {
  9. type: String,
  10. align: String,
  11. justify: String,
  12. tag: {
  13. type: String,
  14. default: 'div'
  15. },
  16. gutter: {
  17. type: [Number, String],
  18. default: 0
  19. }
  20. },
  21. computed: {
  22. spaces: function spaces() {
  23. var gutter = Number(this.gutter);
  24. if (!gutter) {
  25. return;
  26. }
  27. var spaces = [];
  28. var groups = [[]];
  29. var totalSpan = 0;
  30. this.children.forEach(function (item, index) {
  31. totalSpan += Number(item.span);
  32. if (totalSpan > 24) {
  33. groups.push([index]);
  34. totalSpan -= 24;
  35. } else {
  36. groups[groups.length - 1].push(index);
  37. }
  38. });
  39. groups.forEach(function (group) {
  40. var averagePadding = gutter * (group.length - 1) / group.length;
  41. group.forEach(function (item, index) {
  42. if (index === 0) {
  43. spaces.push({
  44. right: averagePadding
  45. });
  46. } else {
  47. var left = gutter - spaces[item - 1].right;
  48. var right = averagePadding - left;
  49. spaces.push({
  50. left: left,
  51. right: right
  52. });
  53. }
  54. });
  55. });
  56. return spaces;
  57. }
  58. },
  59. methods: {
  60. onClick: function onClick(event) {
  61. this.$emit('click', event);
  62. }
  63. },
  64. render: function render() {
  65. var _bem;
  66. var h = arguments[0];
  67. var align = this.align,
  68. justify = this.justify;
  69. var flex = this.type === 'flex';
  70. return h(this.tag, {
  71. "class": bem((_bem = {
  72. flex: flex
  73. }, _bem["align-" + align] = flex && align, _bem["justify-" + justify] = flex && justify, _bem)),
  74. "on": {
  75. "click": this.onClick
  76. }
  77. }, [this.slots()]);
  78. }
  79. });