fix: 修复 inputSubForm 拖拽排序值位置与视图位置不一致问题 (#9508)

This commit is contained in:
liaoxuezhi 2024-01-25 20:21:13 +08:00 committed by GitHub
parent 51e02cd638
commit 3bd878c1b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 124 additions and 98 deletions

View File

@ -227,23 +227,24 @@ export class DateShortCutControl extends React.PureComponent<
}
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
const options = this.state.options.concat();
options[e.oldIndex] = options.splice(
e.newIndex,
1,
options[e.oldIndex]
)[0];
// options[e.oldIndex] = options.splice(
// e.newIndex,
// 1,
// options[e.oldIndex]
// )[0];
options.splice(e.newIndex, 0, options.splice(e.oldIndex, 1)[0]);
this.setState({options}, () => this.onChangeOptions());
}
}

View File

@ -174,13 +174,13 @@ export default class FeatureControl extends React.Component<
}
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -141,13 +141,13 @@ export default class ListItemControl extends React.Component<
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -250,24 +250,19 @@ export default class OptionControl extends React.Component<
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
const options = this.state.options.concat();
options[e.oldIndex] = options.splice(
e.newIndex,
1,
options[e.oldIndex]
)[0];
options.splice(e.newIndex, 0, options.splice(e.oldIndex, 1)[0]);
this.setState({options}, () => this.onChange());
}

View File

@ -304,13 +304,13 @@ export default class TimelineItemControl extends React.Component<
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -177,18 +177,24 @@ export class CRUDColumnControl extends React.Component<
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
const options = this.state.options.concat();
options[e.oldIndex] = options.splice(
e.newIndex,
1,
options[e.oldIndex]
)[0];
// options[e.oldIndex] = options.splice(
// e.newIndex,
// 1,
// options[e.oldIndex]
// )[0];
options.splice(e.newIndex, 0, options.splice(e.oldIndex, 1)[0]);
this.setState({options}, () => this.handleSort());
}

View File

@ -543,13 +543,13 @@ export class EventControl extends React.Component<
}
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
@ -557,22 +557,7 @@ export class EventControl extends React.Component<
const newEvent = onEventConfig[eventKey];
let options = newEvent?.actions.concat();
// 从后往前移
if (e.oldIndex > e.newIndex) {
options = [
...options.slice(0, e.newIndex),
options[e.oldIndex],
...options.slice(e.newIndex, e.oldIndex),
...options.slice(e.oldIndex + 1, options.length)
];
} else if (e.oldIndex < e.newIndex) {
// 从前往后
options = [
...(e.oldIndex === 0 ? [] : options.slice(0, e.oldIndex)),
...options.slice(e.oldIndex + 1, e.newIndex),
options[e.oldIndex],
...options.slice(e.newIndex, options.length)
];
}
options.splice(e.newIndex, 0, options.splice(e.oldIndex, 1)[0]);
onEventConfig[eventKey] = {
...onEventConfig[eventKey],
actions: options

View File

@ -105,13 +105,13 @@ export class ArrayInput extends React.Component<ArrayInputProps> {
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -143,13 +143,13 @@ export class ResultList extends React.Component<
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -257,7 +257,12 @@ export class UserSelect extends React.Component<
}
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -561,7 +561,12 @@ export default class Cards extends React.Component<GridProps, object> {
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -1026,7 +1026,12 @@ export default class ComboControl extends React.Component<ComboProps> {
// 换回来
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -1545,7 +1545,12 @@ export default class ImageControl extends React.Component<
// 换回来
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -316,11 +316,15 @@ export default class SubFormControl extends React.PureComponent<
if (e.newIndex === e.oldIndex) {
return;
}
// 换回来
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -623,7 +623,12 @@ export default class List extends React.Component<ListProps, object> {
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -273,7 +273,12 @@ export default class ColumnToggler extends React.Component<
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

View File

@ -1374,7 +1374,12 @@ export default class Table extends React.Component<TableProps, object> {
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}