123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- export function handleTableSpan(mergeKeys, tableData) {
- const spanObj = {}
- if (mergeKeys instanceof Array && tableData instanceof Array && mergeKeys.length && tableData.length) {
- mergeKeys.forEach(key => {
- spanObj[key] = []
- let position = 0
- tableData.forEach((item, index) => {
- if (index === 0) {
- spanObj[key].push(1)
- position = 0
- } else {
- // 如果要合并的key 值是引用数据类型,我们要先把 数组或者 对象转成json 格式然后对比
- if (tableData[index][key] instanceof Array || tableData[index][key] instanceof Object) {
- if (JSON.stringify(tableData[index][key]) === JSON.stringify(tableData[index - 1][key])) {
- spanObj[key][position] += 1
- spanObj[key].push(0)
- } else {
- spanObj[key].push(1)
- position = index
- }
- } else {
- if (tableData[index][key] === tableData[index - 1][key]) {
- spanObj[key][position] += 1
- spanObj[key].push(0)
- } else {
- spanObj[key].push(1)
- position = index
- }
- }
- }
- })
- })
- return spanObj
- }
- }
- export function handleObjectSpanMethod(tableObj, mergeKeys, rowspanObj, notEmpty) {
- if (mergeKeys instanceof Array && rowspanObj instanceof Object) {
- const { row, column, rowIndex, columnIndex } = tableObj
- for (let i = 0; i < mergeKeys.length; i++) {
- let term
- if (notEmpty) {
- term = column.property === mergeKeys[i] && row[mergeKeys[i]] !== '/'
- } else {
- term = column.property === mergeKeys[i]
- }
- if (term) {
- const _row = rowspanObj[mergeKeys[i]][rowIndex]
- const _col = _row > 0 ? 1 : 0
- return {
- rowspan: _row,
- colspan: _col
- }
- }
- }
- }
- }
|