tdesign-mobile-vue
Version:
tdesign-mobile-vue
101 lines (95 loc) • 3.9 kB
JavaScript
/**
* tdesign v1.15.0
* (c) 2026 TDesign Group
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var Vue = require('vue');
var _common_js_log_log = require('../../_common/js/log/log.js');
var get = require('../../_chunks/dep-5ade6a05.js');
require('../../_chunks/dep-c010d70c.js');
require('../../_chunks/dep-642ebff4.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-43708eba.js');
require('../../_chunks/dep-16ad1a12.js');
require('../../_chunks/dep-527cf8f4.js');
require('../../_chunks/dep-1232d344.js');
require('../../_chunks/dep-4bbf6d4f.js');
require('../../_chunks/dep-9b240313.js');
require('../../_chunks/dep-e224a131.js');
require('../../_chunks/dep-4f58ec50.js');
require('../../_chunks/dep-f6a2d298.js');
require('../../_chunks/dep-800a2ea8.js');
function getCellKey(row, rowKey, colKey, colIndex) {
var rowValue = get.get(row, rowKey);
if (rowValue === void 0) {
_common_js_log_log["default"].error("Table", "rowKey is wrong, can not get unique identifier of row.");
}
return [rowValue, colKey || colIndex].join("_");
}
function getRowKeyFromCell(cellKey) {
var _cellKey$split;
return (_cellKey$split = cellKey.split("_")) === null || _cellKey$split === void 0 ? void 0 : _cellKey$split[0];
}
function useRowspanAndColspan(data, columns, rowKey, rowspanAndColspan) {
var skipSpansMap = Vue.ref(/* @__PURE__ */new Map());
var onTrRowspanOrColspan = function onTrRowspanOrColspan(params, skipSpansValue) {
var rowIndex = params.rowIndex,
colIndex = params.colIndex;
if (!skipSpansValue.rowspan && !skipSpansValue.colspan) return;
var maxRowIndex = rowIndex + (skipSpansValue.rowspan || 1);
var maxColIndex = colIndex + (skipSpansValue.colspan || 1);
for (var i = rowIndex; i < maxRowIndex; i++) {
for (var j = colIndex; j < maxColIndex; j++) {
if (i !== rowIndex || j !== colIndex) {
if (!data.value[i] || !columns.value[j]) return;
var cellKey = getCellKey(data.value[i], rowKey.value, columns.value[j].colKey, j);
var state = skipSpansMap.value.get(cellKey) || {};
state.skipped = true;
skipSpansMap.value.set(cellKey, state);
}
}
}
};
var updateSkipSpansMap = function updateSkipSpansMap(data2, columns2, rowspanAndColspan2) {
var _skipSpansMap$value;
(_skipSpansMap$value = skipSpansMap.value) === null || _skipSpansMap$value === void 0 || _skipSpansMap$value.clear();
if (!data2 || !rowspanAndColspan2) return;
for (var i = 0, len = data2.length; i < len; i++) {
var row = data2[i];
for (var j = 0, colLen = columns2.length; j < colLen; j++) {
var col = columns2[j];
var params = {
row: row,
col: col,
rowIndex: i,
colIndex: j
};
var cellKey = getCellKey(row, rowKey.value, col.colKey, j);
var state = skipSpansMap.value.get(cellKey) || {};
var o = rowspanAndColspan2(params) || {};
if (o.rowspan || o.colspan || state.rowspan || state.colspan) {
o.rowspan && (state.rowspan = o.rowspan);
o.colspan && (state.colspan = o.colspan);
skipSpansMap.value.set(cellKey, state);
}
onTrRowspanOrColspan === null || onTrRowspanOrColspan === void 0 || onTrRowspanOrColspan(params, state);
}
}
};
Vue.watch(function () {
return [data.value, columns.value, rowspanAndColspan];
}, function () {
updateSkipSpansMap(data.value, columns.value, rowspanAndColspan === null || rowspanAndColspan === void 0 ? void 0 : rowspanAndColspan.value);
}, {
immediate: true
});
return {
skipSpansMap: skipSpansMap
};
}
exports["default"] = useRowspanAndColspan;
exports.getCellKey = getCellKey;
exports.getRowKeyFromCell = getRowKeyFromCell;
//# sourceMappingURL=useRowspanAndColspan.js.map