From 212ce9a599c68721626782681a5d9b2fbd6e7f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E5=84=80=E5=BC=8F?= <854085467@qq.com> Date: Tue, 9 Aug 2022 01:09:53 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(component):=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E5=A4=8D=E6=9D=82=E8=A1=A8=E5=A4=B4=E8=A1=A8=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/src/component/table/index.vue | 51 +++++++++++++++---- .../src/document/zh-CN/components/table.md | 8 +-- 2 files changed, 46 insertions(+), 13 deletions(-) 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) => {