winbox-ui-next
Version:
We Design Vue 2.0: A Vue.js 3 UI Library
50 lines (49 loc) • 1.42 kB
JavaScript
import { computed } from "vue";
const useSpan = ({
spanMethod,
data,
columns
}) => {
const tableSpan = computed(() => {
const span = {};
if (spanMethod.value) {
data.value.forEach((record, rowIndex) => {
columns.value.forEach((column, columnIndex) => {
var _a, _b;
const { rowspan = 1, colspan = 1 } = (_b = (_a = spanMethod.value) == null ? void 0 : _a.call(spanMethod, {
record: record.raw,
column,
rowIndex,
columnIndex
})) != null ? _b : {};
if (rowspan > 1 || colspan > 1) {
span[`${rowIndex}-${columnIndex}`] = [rowspan, colspan];
}
});
});
}
return span;
});
const removedCells = computed(() => {
const data2 = [];
for (const indexKey of Object.keys(tableSpan.value)) {
const indexArray = indexKey.split("-").map((item) => Number(item));
const span = tableSpan.value[indexKey];
for (let i = 1; i < span[0]; i++) {
data2.push(`${indexArray[0] + i}-${indexArray[1]}`);
for (let j = 1; j < span[1]; j++) {
data2.push(`${indexArray[0] + i}-${indexArray[1] + j}`);
}
}
for (let i = 1; i < span[1]; i++) {
data2.push(`${indexArray[0]}-${indexArray[1] + i}`);
}
}
return data2;
});
return {
tableSpan,
removedCells
};
};
export { useSpan };