Skip to content

Commit c7a26a1

Browse files
committed
2 parents ff92676 + b656b6e commit c7a26a1

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/components/layout/list/List.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ onMounted(() => {
9898
:class="`iw-list iw-row-select-container relative iw-list--size${props.tableConf.styles.size}`"
9999
:style="setTableWidth()"
100100
>
101-
<HeaderComp :columns-conf="props.columnsConf" :layout-conf="props.layoutConf" :table-conf="props.tableConf" :set-column-styles="setColumnStyles" />
101+
<HeaderComp :columns-conf="props.columnsConf" :layout-conf="props.layoutConf" :table-conf="props.tableConf" :set-column-styles="setColumnStyles" :sort="layoutConf.sort" />
102102
<!-- 不分组模式 -->
103103
<!-- Non-grouping mode -->
104104
<template v-if="props.layoutConf.data && !Array.isArray(props.layoutConf.data)">

src/components/layout/list/ListHeader.vue

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import ColumnResizeComp from '../../function/ColumnResize.vue'
88
import ColumnFixedComp from './ListColumnFixed.vue'
99
import ColumnWrapComp from './ListColumnWrap.vue'
1010
11+
enum ORDER_ENUM {
12+
POSITIVE_SORT = false, //正序
13+
INVERT_SORT= true, //倒序
14+
UNDEFINED = null //不排序
15+
}
16+
1117
const props = defineProps<{
1218
// 列配置
1319
// Column configuration
@@ -74,6 +80,24 @@ const cateColumns = computed(() => {
7480
return cateColumns
7581
})
7682
83+
/**
84+
* 组装sort数据到columns(sort: { enabledColumnNames: ['no'], items: [{ columnName: 'no', orderDesc: false }] })
85+
* Assemble sort data into columns
86+
*/
87+
const columnsWithSort = computed(()=> {
88+
89+
return props.columnsConf.map(e=> {
90+
const canSort = props.layoutConf.sort.enabledColumnNames.includes(e.name);
91+
if(canSort) {
92+
return {
93+
...e,
94+
orderDesc: props.layoutConf.sort.items?.find(f=> f.columnName === e.name)?.orderDesc ?? ORDER_ENUM.UNDEFINED
95+
}
96+
}
97+
return e;
98+
})
99+
})
100+
77101
/**
78102
* 设置新的列宽
79103
*
@@ -94,6 +118,44 @@ async function setNewWidth(newWidth: number, columnName?: string) {
94118
await eb.modifyLayout(changedLayoutReq)
95119
}
96120
}
121+
122+
/**
123+
* 排序事件 sort event
124+
* @param column
125+
*/
126+
function handleSort(column) {
127+
const { orderDesc , name } = column;
128+
const items = props.layoutConf.sort?.items || [];
129+
const currentIndex = items?.findIndex(f=> f.columnName === name)
130+
const currentItem = items?.find(f=> f.columnName === name)
131+
if(currentItem) {//存在修改 exist modify
132+
switch(orderDesc){
133+
case ORDER_ENUM.POSITIVE_SORT:
134+
currentItem.orderDesc = ORDER_ENUM.INVERT_SORT;
135+
break;
136+
case ORDER_ENUM.INVERT_SORT:
137+
items.splice(currentIndex, 1)
138+
// currentItem.orderDesc = ORDER_ENUM.UNDEFINED;
139+
break;
140+
case ORDER_ENUM.UNDEFINED:
141+
currentItem.orderDesc = ORDER_ENUM.POSITIVE_SORT;
142+
break;
143+
144+
}
145+
}else {//不存在添加 no exist add
146+
items.push({
147+
columnName: column.name,
148+
orderDesc: ORDER_ENUM.POSITIVE_SORT,
149+
})
150+
}
151+
152+
eb.modifyLayout({
153+
sort: {
154+
enabledColumnNames: props.layoutConf.sort.enabledColumnNames,
155+
items,
156+
},
157+
})
158+
}
97159
</script>
98160

99161
<template>
@@ -144,14 +206,18 @@ async function setNewWidth(newWidth: number, columnName?: string) {
144206
<!-- 数据列 -->
145207
<!-- Data column -->
146208
<div
147-
v-for="(column, colIdx) in columnsConf" :key="`${props.layoutConf.id}-${column.name}`"
209+
v-for="(column, colIdx) in columnsWithSort" :key="`${props.layoutConf.id}-${column.name}`"
148210
:class="`${props.tableConf.styles.cellClass} iw-list-cell iw-resize-item flex items-center bg-base-200 ${(colIdx !== 0 || props.layoutConf.showSelectColumn) && 'border-l border-l-base-300'} whitespace-nowrap overflow-hidden text-ellipsis flex-nowrap hover:cursor-pointer`"
149211
:data-column-name="column.name"
150212
:style="props.setColumnStyles(colIdx)"
151213
:title="column.title"
152214
@click="(event: MouseEvent) => showHeaderContextMenu(event, column.name)"
153215
>
154216
<i :class="`${column.icon} mr-1`" /> {{ column.title }}
217+
<div v-if="column.hasOwnProperty('orderDesc')" class="sort-box flex flex-col items-center justify-center ml-2" @click.stop="handleSort(column)">
218+
<i class="sort-icon octicon-chevron-up-12" :class="`${column.orderDesc === false ? 'text-primary' : ''}`" />
219+
<i class="sort-icon octicon-chevron-down-12 mt-[-12px]" :class="column.orderDesc ? 'text-primary' : ''" />
220+
</div>
155221
</div>
156222
<!-- 操作列 -->
157223
<!-- Action column -->

0 commit comments

Comments
 (0)