Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复:表格右上角自定义列与自定义列排序 #415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 9 additions & 39 deletions arco-design-pro-vite/src/views/list/search-table/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,15 @@
<template #content>
<div id="tableSetting">
<div
v-for="(item, index) in showColumns"
v-for="item in showColumns"
:key="item.dataIndex"
class="setting"
>
<div style="margin-right: 4px; cursor: move">
<icon-drag-arrow />
</div>
<div>
<a-checkbox
v-model="item.checked"
@change="
handleChange($event, item as TableColumnData, index)
"
>
<a-checkbox v-model="item.checked" @change="handleChange">
</a-checkbox>
</div>
<div class="title">
Expand Down Expand Up @@ -417,36 +412,9 @@
size.value = val as SizeProps;
};

const handleChange = (
checked: boolean | (string | boolean | number)[],
column: Column,
index: number
) => {
if (!checked) {
cloneColumns.value = showColumns.value.filter(
(item) => item.dataIndex !== column.dataIndex
);
} else {
cloneColumns.value.splice(index, 0, column);
}
};

const exchangeArray = <T extends Array<any>>(
array: T,
beforeIdx: number,
newIdx: number,
isDeep = false
): T => {
const newArray = isDeep ? cloneDeep(array) : array;
if (beforeIdx > -1 && newIdx > -1) {
// 先替换后面的,然后拿到替换的结果替换前面的
newArray.splice(
beforeIdx,
1,
newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
);
}
return newArray;
const handleChange = () => {
// 重新获取显示字段
cloneColumns.value = showColumns.value.filter((item) => item.checked);
};

const popupVisibleChange = (val: boolean) => {
Expand All @@ -456,8 +424,10 @@
const sortable = new Sortable(el, {
onEnd(e: any) {
const { oldIndex, newIndex } = e;
exchangeArray(cloneColumns.value, oldIndex, newIndex);
exchangeArray(showColumns.value, oldIndex, newIndex);
if (oldIndex === newIndex) return;
const item = showColumns.value.splice(oldIndex, 1)[0]; // 取出旧下标的元素
showColumns.value.splice(newIndex, 0, item); // 插入到新下标的位置
handleChange();
},
});
});
Expand Down