fix(Layout): gutter calculation (#6197)

* Revert "fix(Layout): outside of the screen after setting gutter (#6143)"

This reverts commit a460425b26.

* fix(Layout): gutter calculation

* test: fix snapshot
This commit is contained in:
neverland
2020-05-02 16:43:52 +08:00
committed by GitHub
parent 4adefe5605
commit 9a4927ac05
6 changed files with 112 additions and 31 deletions
+41
View File
@@ -20,6 +20,47 @@ export default createComponent({
},
},
computed: {
spaces() {
const gutter = Number(this.gutter);
if (!gutter) {
return;
}
const spaces = [];
const groups = [[]];
let totalSpan = 0;
this.children.forEach((item, index) => {
totalSpan += Number(item.span);
if (totalSpan > 24) {
groups.push([index]);
totalSpan -= 24;
} else {
groups[groups.length - 1].push(index);
}
});
groups.forEach((group) => {
const averagePadding = (gutter * (group.length - 1)) / group.length;
group.forEach((item, index) => {
if (index === 0) {
spaces.push({ right: group.length > 1 ? averagePadding : 0 });
} else {
const left = gutter - spaces[item - 1].right;
const right = averagePadding - left;
spaces.push({ left, right });
}
});
});
return spaces;
},
},
methods: {
onClick(event) {
this.$emit('click', event);