From b656b6e031fe3219da7874233dc6881fbd3a2bf4 Mon Sep 17 00:00:00 2001 From: wangjinpeng <17600579508@163.com> Date: Wed, 24 Jul 2024 09:45:08 +0800 Subject: [PATCH] table header sort --- src/components/layout/list/List.vue | 2 +- src/components/layout/list/ListHeader.vue | 68 ++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/components/layout/list/List.vue b/src/components/layout/list/List.vue index 93e6f7d..cfca8f4 100644 --- a/src/components/layout/list/List.vue +++ b/src/components/layout/list/List.vue @@ -98,7 +98,7 @@ onMounted(() => { :class="`iw-list iw-row-select-container relative iw-list--size${props.tableConf.styles.size}`" :style="setTableWidth()" > - + diff --git a/src/components/layout/list/ListHeader.vue b/src/components/layout/list/ListHeader.vue index 3c6aa18..a8c4b5a 100644 --- a/src/components/layout/list/ListHeader.vue +++ b/src/components/layout/list/ListHeader.vue @@ -8,6 +8,12 @@ import ColumnResizeComp from '../../function/ColumnResize.vue' import ColumnFixedComp from './ListColumnFixed.vue' import ColumnWrapComp from './ListColumnWrap.vue' +enum ORDER_ENUM { + POSITIVE_SORT = false, //正序 + INVERT_SORT= true, //倒序 + UNDEFINED = null //不排序 +} + const props = defineProps<{ // 列配置 // Column configuration @@ -74,6 +80,24 @@ const cateColumns = computed(() => { return cateColumns }) +/** + * 组装sort数据到columns(sort: { enabledColumnNames: ['no'], items: [{ columnName: 'no', orderDesc: false }] }) + * Assemble sort data into columns + */ +const columnsWithSort = computed(()=> { + + return props.columnsConf.map(e=> { + const canSort = props.layoutConf.sort.enabledColumnNames.includes(e.name); + if(canSort) { + return { + ...e, + orderDesc: props.layoutConf.sort.items?.find(f=> f.columnName === e.name)?.orderDesc ?? ORDER_ENUM.UNDEFINED + } + } + return e; + }) +}) + /** * 设置新的列宽 * @@ -94,6 +118,44 @@ async function setNewWidth(newWidth: number, columnName?: string) { await eb.modifyLayout(changedLayoutReq) } } + +/** + * 排序事件 sort event + * @param column 列 + */ +function handleSort(column) { + const { orderDesc , name } = column; + const items = props.layoutConf.sort?.items || []; + const currentIndex = items?.findIndex(f=> f.columnName === name) + const currentItem = items?.find(f=> f.columnName === name) + if(currentItem) {//存在修改 exist modify + switch(orderDesc){ + case ORDER_ENUM.POSITIVE_SORT: + currentItem.orderDesc = ORDER_ENUM.INVERT_SORT; + break; + case ORDER_ENUM.INVERT_SORT: + items.splice(currentIndex, 1) + // currentItem.orderDesc = ORDER_ENUM.UNDEFINED; + break; + case ORDER_ENUM.UNDEFINED: + currentItem.orderDesc = ORDER_ENUM.POSITIVE_SORT; + break; + + } + }else {//不存在添加 no exist add + items.push({ + columnName: column.name, + orderDesc: ORDER_ENUM.POSITIVE_SORT, + }) + } + + eb.modifyLayout({ + sort: { + enabledColumnNames: props.layoutConf.sort.enabledColumnNames, + items, + }, + }) +} @@ -144,7 +206,7 @@ async function setNewWidth(newWidth: number, columnName?: string) { showHeaderContextMenu(event, column.name)" > {{ column.title }} + + + +