Merge pull request #8759 from 2betop/fix-quickEdit-name-path

fix: 修复 quickEdit inline 模式 name 为带层级时发送的数据不符合预期 Close: #8756
This commit is contained in:
hsm-lv 2023-11-17 09:54:30 +08:00 committed by GitHub
commit ee6fc42450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -127,8 +127,13 @@ export function setVariable(
const parts = convertKeyToPath !== false ? keyToPath(key) : [key];
const last = parts.pop() as string;
const stack: Array<{
host: Record<string, any>;
key: string;
}> = [];
while (parts.length) {
let host = data;
let key = parts.shift() as string;
if (isPlainObject(data[key])) {
data = data[key] = {
@ -143,9 +148,25 @@ export function setVariable(
data[key] = {};
data = data[key];
} else {
// 如果是数字,那么就是数组
if (/^\d+$/.test(key) && stack.length) {
const prev = stack[stack.length - 1];
if (
!Array.isArray(prev.host[prev.key]) &&
!Object.keys(prev.host[prev.key]).length
) {
host = data = prev.host[prev.key] = [];
}
}
data[key] = {};
data = data[key];
}
stack.push({
host,
key
});
}
data[last] = value;

View File

@ -5,7 +5,7 @@
import React from 'react';
import {findDOMNode} from 'react-dom';
import {RendererProps, getRendererByName, noop} from 'amis-core';
import {RendererProps, getRendererByName, noop, setVariable} from 'amis-core';
import hoistNonReactStatic from 'hoist-non-react-statics';
import {ActionObject} from 'amis-core';
import keycode from 'keycode';
@ -353,8 +353,10 @@ export const HocQuickEdit =
handleFormItemChange(value: any) {
const {onQuickChange, quickEdit, name} = this.props;
const data = {};
setVariable(data, name!, value);
onQuickChange(
{[name!]: value},
data,
(quickEdit as QuickEditConfig).saveImmediately,
false,
quickEdit as QuickEditConfig