diff --git a/package/component/src/component/table/index.vue b/package/component/src/component/table/index.vue index f750a6c4..bc570e9b 100644 --- a/package/component/src/component/table/index.vue +++ b/package/component/src/component/table/index.vue @@ -96,6 +96,11 @@ const tableColumns = computed(() => { const tableHeadColumns = ref([]); const tableBodyColumns = ref([]); +/** + * 获取数组深度 + * + * @param arr 数组 + */ const getLevel = (arr: any[]) => { let maxLevel = 0; (function callBack(arr, level) { @@ -113,6 +118,11 @@ const getLevel = (arr: any[]) => { return maxLevel; }; +/** + * 获取叶节点的数量 + * + * @param json 当前节点 + */ function getLeafCountTree(json: any) { if (!json.children || json.children.length == 0) { json.colspan = 1; @@ -127,6 +137,11 @@ function getLeafCountTree(json: any) { } } +/** + * 计算内容列 + * + * @param columns 原始列 + */ const findFindNode = (columns: any[]) => { columns.forEach((column) => { if (column.children) { @@ -139,11 +154,17 @@ const findFindNode = (columns: any[]) => { findFindNode(tableColumns.value); +/** + * 计算显示列 + * + * @param columns 原始列 + */ const tableColumnKeys = ref([]); const findFindNodes = (columns: any[]) => { columns.forEach((column) => { if (column.children) { + tableColumnKeys.value.push(column.key); findFindNodes(column.children); } else { if (!column.hide) { @@ -156,27 +177,37 @@ const findFindNodes = (columns: any[]) => { findFindNodes(tableColumns.value); /** - * 处理为复杂表头, 待完成 - * + * 计算数组差异 + * + * @param arr1 数组 + * @param arr2 数组 + */ +function diff(arr1: any[], arr2: any[]) { + var newArr = []; + arr1 = Array.from(new Set(arr1)); // 去重 + arr2 = Array.from(new Set(arr2)); // 去重 + newArr =arr1.concat(arr2); + return newArr.filter(x=>!(arr1.includes(x) && arr2.includes(x))) +} + +/** + * 计算标题列 + * * @param level 层级, 用于决定会被 push 到的目标数组 */ const findFinalNode = (level: number, columns: any[]) => { columns.forEach((column) => { if (column.children) { - // 设置 colspan const colSpan = getLeafCountTree(column); column.colspan = colSpan; - column.rowspan = 1; if (!tableHeadColumns.value[level]) { tableHeadColumns.value[level] = []; } tableHeadColumns.value[level].push(column); findFinalNode(level + 1, column.children); } else { - // 设置 rowspan const rowSpan = getLevel(columns); column.rowspan = rowSpan; - column.colspan = 1; if (!tableHeadColumns.value[level]) { tableHeadColumns.value[level] = []; } @@ -536,9 +567,10 @@ const renderTotalRowCell = (column: any) => {