@@ -8,6 +8,12 @@ import ColumnResizeComp from '../../function/ColumnResize.vue'
8
8
import ColumnFixedComp from ' ./ListColumnFixed.vue'
9
9
import ColumnWrapComp from ' ./ListColumnWrap.vue'
10
10
11
+ enum ORDER_ENUM {
12
+ POSITIVE_SORT = false , // 正序
13
+ INVERT_SORT = true , // 倒序
14
+ UNDEFINED = null // 不排序
15
+ }
16
+
11
17
const props = defineProps <{
12
18
// 列配置
13
19
// Column configuration
@@ -74,6 +80,24 @@ const cateColumns = computed(() => {
74
80
return cateColumns
75
81
})
76
82
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
+
77
101
/**
78
102
* 设置新的列宽
79
103
*
@@ -94,6 +118,44 @@ async function setNewWidth(newWidth: number, columnName?: string) {
94
118
await eb .modifyLayout (changedLayoutReq )
95
119
}
96
120
}
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
+ }
97
159
</script >
98
160
99
161
<template >
@@ -144,14 +206,18 @@ async function setNewWidth(newWidth: number, columnName?: string) {
144
206
<!-- 数据列 -->
145
207
<!-- Data column -->
146
208
<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}`"
148
210
: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`"
149
211
:data-column-name =" column.name"
150
212
:style =" props.setColumnStyles(colIdx)"
151
213
:title =" column.title"
152
214
@click =" (event: MouseEvent) => showHeaderContextMenu(event, column.name)"
153
215
>
154
216
<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 >
155
221
</div >
156
222
<!-- 操作列 -->
157
223
<!-- Action column -->
0 commit comments