diff --git a/src/commonMethods/useGroup.ts b/src/commonMethods/useGroup.ts new file mode 100644 index 0000000..e4957f4 --- /dev/null +++ b/src/commonMethods/useGroup.ts @@ -0,0 +1,24 @@ +/** + * 将数组中具有相同属性值的元素分组 + * @param arr 数组 + * @param prop 属性 + * @returns + */ +export function useGroup(arr: any, prop: string): any { + var groups = {} as any // 创建空对象作为存储结果的容器 + let result = [] as any + + for (var i = 0; i < arr.length; i++) { + var key = arr[i][prop] // 获取当前元素的指定属性值 + + if (!groups[key]) { + groups[key] = [] // 如果该属性值不存在于结果中,则新建一个空数组 + } + + groups[key].push(arr[i]) // 将当前元素添加到对应属性值所对应的数组中 + } + Object.values(groups).forEach((item) => { + result = result.concat(item) + }) + return result // 返回包含了按属性值分组后的数组的数组 +} diff --git a/src/commonMethods/useGroup.ts b/src/commonMethods/useGroup.ts new file mode 100644 index 0000000..e4957f4 --- /dev/null +++ b/src/commonMethods/useGroup.ts @@ -0,0 +1,24 @@ +/** + * 将数组中具有相同属性值的元素分组 + * @param arr 数组 + * @param prop 属性 + * @returns + */ +export function useGroup(arr: any, prop: string): any { + var groups = {} as any // 创建空对象作为存储结果的容器 + let result = [] as any + + for (var i = 0; i < arr.length; i++) { + var key = arr[i][prop] // 获取当前元素的指定属性值 + + if (!groups[key]) { + groups[key] = [] // 如果该属性值不存在于结果中,则新建一个空数组 + } + + groups[key].push(arr[i]) // 将当前元素添加到对应属性值所对应的数组中 + } + Object.values(groups).forEach((item) => { + result = result.concat(item) + }) + return result // 返回包含了按属性值分组后的数组的数组 +} diff --git a/src/components/MultiHeaderTable/index.vue b/src/components/MultiHeaderTable/index.vue index 27e733b..79459b1 100644 --- a/src/components/MultiHeaderTable/index.vue +++ b/src/components/MultiHeaderTable/index.vue @@ -75,6 +75,7 @@ 'handleCurrentChange', 'handleInputNumberChange', 'handleClickHeader', + 'selectChange', ]) const tableList = ref([]) // 处理后的table数据 @@ -187,6 +188,11 @@ function handleClickHeader(column: any, checkDateDetailId: string) { emits('handleClickHeader', column, checkDateDetailId) } + +// select选择器选中值变化 +function selectChange(value: any, row: any) { + emits('selectChange', value, row) +}