|
@@ -6,7 +6,7 @@
|
|
<Popover
|
|
<Popover
|
|
placement="bottomLeft"
|
|
placement="bottomLeft"
|
|
trigger="click"
|
|
trigger="click"
|
|
- @visibleChange="handleVisibleChange"
|
|
|
|
|
|
+ @visible-change="handleVisibleChange"
|
|
:overlayClassName="`${prefixCls}__cloumn-list`"
|
|
:overlayClassName="`${prefixCls}__cloumn-list`"
|
|
:getPopupContainer="getPopupContainer"
|
|
:getPopupContainer="getPopupContainer"
|
|
>
|
|
>
|
|
@@ -43,7 +43,7 @@
|
|
<CheckboxGroup v-model:value="checkedList" @change="onChange" ref="columnListRef">
|
|
<CheckboxGroup v-model:value="checkedList" @change="onChange" ref="columnListRef">
|
|
<template v-for="item in plainOptions" :key="item.value">
|
|
<template v-for="item in plainOptions" :key="item.value">
|
|
<div :class="`${prefixCls}__check-item`" v-if="!('ifShow' in item && !item.ifShow)">
|
|
<div :class="`${prefixCls}__check-item`" v-if="!('ifShow' in item && !item.ifShow)">
|
|
- <DragOutlined class="table-coulmn-drag-icon" />
|
|
|
|
|
|
+ <DragOutlined class="table-column-drag-icon" />
|
|
<Checkbox :value="item.value">
|
|
<Checkbox :value="item.value">
|
|
{{ item.label }}
|
|
{{ item.label }}
|
|
</Checkbox>
|
|
</Checkbox>
|
|
@@ -111,19 +111,23 @@
|
|
computed,
|
|
computed,
|
|
} from 'vue';
|
|
} from 'vue';
|
|
import { Tooltip, Popover, Checkbox, Divider } from 'ant-design-vue';
|
|
import { Tooltip, Popover, Checkbox, Divider } from 'ant-design-vue';
|
|
|
|
+ import type { CheckboxChangeEvent } from 'ant-design-vue/lib/checkbox/interface';
|
|
import { SettingOutlined, DragOutlined } from '@ant-design/icons-vue';
|
|
import { SettingOutlined, DragOutlined } from '@ant-design/icons-vue';
|
|
- import { Icon } from '/@/components/Icon';
|
|
|
|
|
|
+ import Icon from '/@/components/Icon/src/Icon.vue';
|
|
import { ScrollContainer } from '/@/components/Container';
|
|
import { ScrollContainer } from '/@/components/Container';
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
import { useTableContext } from '../../hooks/useTableContext';
|
|
import { useTableContext } from '../../hooks/useTableContext';
|
|
import { useDesign } from '/@/hooks/web/useDesign';
|
|
import { useDesign } from '/@/hooks/web/useDesign';
|
|
- import { useSortable } from '/@/hooks/web/useSortable';
|
|
|
|
|
|
+ // import { useSortable } from '/@/hooks/web/useSortable';
|
|
import { isFunction, isNullAndUnDef } from '/@/utils/is';
|
|
import { isFunction, isNullAndUnDef } from '/@/utils/is';
|
|
import { getPopupContainer as getParentContainer } from '/@/utils';
|
|
import { getPopupContainer as getParentContainer } from '/@/utils';
|
|
- import { omit } from 'lodash-es';
|
|
|
|
|
|
+ import { cloneDeep, omit } from 'lodash-es';
|
|
|
|
+ import Sortablejs from 'sortablejs';
|
|
|
|
+ import type Sortable from 'sortablejs';
|
|
|
|
|
|
interface State {
|
|
interface State {
|
|
checkAll: boolean;
|
|
checkAll: boolean;
|
|
|
|
+ isInit?: boolean;
|
|
checkedList: string[];
|
|
checkedList: string[];
|
|
defaultCheckList: string[];
|
|
defaultCheckList: string[];
|
|
}
|
|
}
|
|
@@ -157,11 +161,11 @@
|
|
let inited = false;
|
|
let inited = false;
|
|
|
|
|
|
const cachePlainOptions = ref<Options[]>([]);
|
|
const cachePlainOptions = ref<Options[]>([]);
|
|
- const plainOptions = ref<Options[]>([]);
|
|
|
|
|
|
+ const plainOptions = ref<Options[] | any>([]);
|
|
|
|
|
|
const plainSortOptions = ref<Options[]>([]);
|
|
const plainSortOptions = ref<Options[]>([]);
|
|
|
|
|
|
- const columnListRef = ref<ComponentRef>(null);
|
|
|
|
|
|
+ const columnListRef = ref(null);
|
|
|
|
|
|
const state = reactive<State>({
|
|
const state = reactive<State>({
|
|
checkAll: true,
|
|
checkAll: true,
|
|
@@ -180,9 +184,11 @@
|
|
|
|
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
const columns = table.getColumns();
|
|
const columns = table.getColumns();
|
|
- if (columns.length) {
|
|
|
|
- init();
|
|
|
|
- }
|
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ if (columns.length && !state.isInit) {
|
|
|
|
+ init();
|
|
|
|
+ }
|
|
|
|
+ }, 0);
|
|
});
|
|
});
|
|
|
|
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
@@ -193,7 +199,7 @@
|
|
|
|
|
|
function getColumns() {
|
|
function getColumns() {
|
|
const ret: Options[] = [];
|
|
const ret: Options[] = [];
|
|
- table.getColumns({ ignoreIndex: true, ignoreAction: false }).forEach((item) => {
|
|
|
|
|
|
+ table.getColumns({ ignoreIndex: true, ignoreAction: true }).forEach((item) => {
|
|
ret.push({
|
|
ret.push({
|
|
label: (item.title as string) || (item.customTitle as string),
|
|
label: (item.title as string) || (item.customTitle as string),
|
|
value: (item.dataIndex || item.title) as string,
|
|
value: (item.dataIndex || item.title) as string,
|
|
@@ -207,7 +213,7 @@
|
|
const columns = getColumns();
|
|
const columns = getColumns();
|
|
|
|
|
|
const checkList = table
|
|
const checkList = table
|
|
- .getColumns({ ignoreAction: true })
|
|
|
|
|
|
+ .getColumns({ ignoreAction: true, ignoreIndex: true })
|
|
.map((item) => {
|
|
.map((item) => {
|
|
if (item.defaultHidden) {
|
|
if (item.defaultHidden) {
|
|
return '';
|
|
return '';
|
|
@@ -233,11 +239,12 @@
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ state.isInit = true;
|
|
state.checkedList = checkList;
|
|
state.checkedList = checkList;
|
|
}
|
|
}
|
|
|
|
|
|
// checkAll change
|
|
// checkAll change
|
|
- function onCheckAllChange(e: ChangeEvent) {
|
|
|
|
|
|
+ function onCheckAllChange(e: CheckboxChangeEvent) {
|
|
const checkList = plainOptions.value.map((item) => item.value);
|
|
const checkList = plainOptions.value.map((item) => item.value);
|
|
if (e.target.checked) {
|
|
if (e.target.checked) {
|
|
state.checkedList = checkList;
|
|
state.checkedList = checkList;
|
|
@@ -250,16 +257,15 @@
|
|
|
|
|
|
const indeterminate = computed(() => {
|
|
const indeterminate = computed(() => {
|
|
const len = plainOptions.value.length;
|
|
const len = plainOptions.value.length;
|
|
- let checkdedLen = state.checkedList.length;
|
|
|
|
- unref(checkIndex) && checkdedLen--;
|
|
|
|
- return checkdedLen > 0 && checkdedLen < len;
|
|
|
|
|
|
+ let checkedLen = state.checkedList.length;
|
|
|
|
+ // unref(checkIndex) && checkedLen--;
|
|
|
|
+ return checkedLen > 0 && checkedLen < len;
|
|
});
|
|
});
|
|
|
|
|
|
// Trigger when check/uncheck a column
|
|
// Trigger when check/uncheck a column
|
|
function onChange(checkedList: string[]) {
|
|
function onChange(checkedList: string[]) {
|
|
- const len = plainOptions.value.length;
|
|
|
|
|
|
+ const len = plainSortOptions.value.length;
|
|
state.checkAll = checkedList.length === len;
|
|
state.checkAll = checkedList.length === len;
|
|
-
|
|
|
|
const sortList = unref(plainSortOptions).map((item) => item.value);
|
|
const sortList = unref(plainSortOptions).map((item) => item.value);
|
|
checkedList.sort((prev, next) => {
|
|
checkedList.sort((prev, next) => {
|
|
return sortList.indexOf(prev) - sortList.indexOf(next);
|
|
return sortList.indexOf(prev) - sortList.indexOf(next);
|
|
@@ -267,6 +273,8 @@
|
|
setColumns(checkedList);
|
|
setColumns(checkedList);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ let sortable: Sortable;
|
|
|
|
+ let sortableOrder: string[] = [];
|
|
// reset columns
|
|
// reset columns
|
|
function reset() {
|
|
function reset() {
|
|
state.checkedList = [...state.defaultCheckList];
|
|
state.checkedList = [...state.defaultCheckList];
|
|
@@ -274,6 +282,7 @@
|
|
plainOptions.value = unref(cachePlainOptions);
|
|
plainOptions.value = unref(cachePlainOptions);
|
|
plainSortOptions.value = unref(cachePlainOptions);
|
|
plainSortOptions.value = unref(cachePlainOptions);
|
|
setColumns(table.getCacheColumns());
|
|
setColumns(table.getCacheColumns());
|
|
|
|
+ sortable.sort(sortableOrder);
|
|
}
|
|
}
|
|
|
|
|
|
// Open the pop-up window for drag and drop initialization
|
|
// Open the pop-up window for drag and drop initialization
|
|
@@ -282,18 +291,21 @@
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
const columnListEl = unref(columnListRef);
|
|
const columnListEl = unref(columnListRef);
|
|
if (!columnListEl) return;
|
|
if (!columnListEl) return;
|
|
- const el = columnListEl.$el as any;
|
|
|
|
|
|
+ const el = (columnListEl as any).$el;
|
|
if (!el) return;
|
|
if (!el) return;
|
|
// Drag and drop sort
|
|
// Drag and drop sort
|
|
- const { initSortable } = useSortable(el, {
|
|
|
|
- handle: '.table-coulmn-drag-icon ',
|
|
|
|
|
|
+ sortable = Sortablejs.create(unref(el), {
|
|
|
|
+ animation: 500,
|
|
|
|
+ delay: 400,
|
|
|
|
+ delayOnTouchOnly: true,
|
|
|
|
+ handle: '.table-column-drag-icon ',
|
|
onEnd: (evt) => {
|
|
onEnd: (evt) => {
|
|
const { oldIndex, newIndex } = evt;
|
|
const { oldIndex, newIndex } = evt;
|
|
if (isNullAndUnDef(oldIndex) || isNullAndUnDef(newIndex) || oldIndex === newIndex) {
|
|
if (isNullAndUnDef(oldIndex) || isNullAndUnDef(newIndex) || oldIndex === newIndex) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// Sort column
|
|
// Sort column
|
|
- const columns = getColumns();
|
|
|
|
|
|
+ const columns = cloneDeep(plainSortOptions.value);
|
|
|
|
|
|
if (oldIndex > newIndex) {
|
|
if (oldIndex > newIndex) {
|
|
columns.splice(newIndex, 0, columns[oldIndex]);
|
|
columns.splice(newIndex, 0, columns[oldIndex]);
|
|
@@ -304,24 +316,29 @@
|
|
}
|
|
}
|
|
|
|
|
|
plainSortOptions.value = columns;
|
|
plainSortOptions.value = columns;
|
|
- plainOptions.value = columns;
|
|
|
|
- setColumns(columns);
|
|
|
|
|
|
+
|
|
|
|
+ setColumns(
|
|
|
|
+ columns
|
|
|
|
+ .map((col: Options) => col.value)
|
|
|
|
+ .filter((value: string) => state.checkedList.includes(value)),
|
|
|
|
+ );
|
|
},
|
|
},
|
|
});
|
|
});
|
|
- initSortable();
|
|
|
|
|
|
+ // 记录原始order 序列
|
|
|
|
+ sortableOrder = sortable.toArray();
|
|
inited = true;
|
|
inited = true;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
// Control whether the serial number column is displayed
|
|
// Control whether the serial number column is displayed
|
|
- function handleIndexCheckChange(e: ChangeEvent) {
|
|
|
|
|
|
+ function handleIndexCheckChange(e: CheckboxChangeEvent) {
|
|
table.setProps({
|
|
table.setProps({
|
|
showIndexColumn: e.target.checked,
|
|
showIndexColumn: e.target.checked,
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
// Control whether the check box is displayed
|
|
// Control whether the check box is displayed
|
|
- function handleSelectCheckChange(e: ChangeEvent) {
|
|
|
|
|
|
+ function handleSelectCheckChange(e: CheckboxChangeEvent) {
|
|
table.setProps({
|
|
table.setProps({
|
|
rowSelection: e.target.checked ? defaultRowSelection : undefined,
|
|
rowSelection: e.target.checked ? defaultRowSelection : undefined,
|
|
});
|
|
});
|
|
@@ -330,7 +347,9 @@
|
|
function handleColumnFixed(item: BasicColumn, fixed?: 'left' | 'right') {
|
|
function handleColumnFixed(item: BasicColumn, fixed?: 'left' | 'right') {
|
|
if (!state.checkedList.includes(item.dataIndex as string)) return;
|
|
if (!state.checkedList.includes(item.dataIndex as string)) return;
|
|
|
|
|
|
- const columns = getColumns() as BasicColumn[];
|
|
|
|
|
|
+ const columns = getColumns().filter((c: BasicColumn) =>
|
|
|
|
+ state.checkedList.includes(c.dataIndex as string),
|
|
|
|
+ ) as BasicColumn[];
|
|
const isFixed = item.fixed === fixed ? false : fixed;
|
|
const isFixed = item.fixed === fixed ? false : fixed;
|
|
const index = columns.findIndex((col) => col.dataIndex === item.dataIndex);
|
|
const index = columns.findIndex((col) => col.dataIndex === item.dataIndex);
|
|
if (index !== -1) {
|
|
if (index !== -1) {
|
|
@@ -341,13 +360,13 @@
|
|
if (isFixed && !item.width) {
|
|
if (isFixed && !item.width) {
|
|
item.width = 100;
|
|
item.width = 100;
|
|
}
|
|
}
|
|
- table.setCacheColumnsByField?.(item.dataIndex, { fixed: isFixed });
|
|
|
|
|
|
+ table.setCacheColumnsByField?.(item.dataIndex as string, { fixed: isFixed });
|
|
setColumns(columns);
|
|
setColumns(columns);
|
|
}
|
|
}
|
|
|
|
|
|
function setColumns(columns: BasicColumn[] | string[]) {
|
|
function setColumns(columns: BasicColumn[] | string[]) {
|
|
table.setColumns(columns);
|
|
table.setColumns(columns);
|
|
- const data: ColumnChangeParam[] = unref(plainOptions).map((col) => {
|
|
|
|
|
|
+ const data: ColumnChangeParam[] = unref(plainSortOptions).map((col) => {
|
|
const visible =
|
|
const visible =
|
|
columns.findIndex(
|
|
columns.findIndex(
|
|
(c: BasicColumn | string) =>
|
|
(c: BasicColumn | string) =>
|
|
@@ -390,15 +409,15 @@
|
|
<style lang="less">
|
|
<style lang="less">
|
|
@prefix-cls: ~'@{namespace}-basic-column-setting';
|
|
@prefix-cls: ~'@{namespace}-basic-column-setting';
|
|
|
|
|
|
- .table-coulmn-drag-icon {
|
|
|
|
|
|
+ .table-column-drag-icon {
|
|
margin: 0 5px;
|
|
margin: 0 5px;
|
|
cursor: move;
|
|
cursor: move;
|
|
}
|
|
}
|
|
|
|
|
|
.@{prefix-cls} {
|
|
.@{prefix-cls} {
|
|
&__popover-title {
|
|
&__popover-title {
|
|
- position: relative;
|
|
|
|
display: flex;
|
|
display: flex;
|
|
|
|
+ position: relative;
|
|
align-items: center;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
}
|
|
}
|
|
@@ -462,4 +481,4 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-</style>
|
|
|
|
|
|
+</style>
|