winbox-ui-next
Version:
We Design Vue 2.0: A Vue.js 3 UI Library
53 lines (52 loc) • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports[Symbol.toStringTag] = "Module";
var vue = require("vue");
const useSpan = ({
spanMethod,
data,
columns
}) => {
const tableSpan = vue.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 = vue.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
};
};
exports.useSpan = useSpan;