mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-11-30 14:32:09 +08:00
fix(form): 生成表单values时将initValus深拷贝,避免修改到传入的对象
This commit is contained in:
parent
054ed561b6
commit
b536eba81c
@ -16,7 +16,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { toRaw } from 'vue';
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import utc from 'dayjs/plugin/utc';
|
import utc from 'dayjs/plugin/utc';
|
||||||
import { cloneDeep } from 'lodash-es';
|
import { cloneDeep } from 'lodash-es';
|
||||||
@ -121,12 +120,12 @@ const initValueItem = function (
|
|||||||
asyncLoadConfig(value, initValue, item as HtmlField);
|
asyncLoadConfig(value, initValue, item as HtmlField);
|
||||||
|
|
||||||
// 这种情况比较多,提前结束
|
// 这种情况比较多,提前结束
|
||||||
if (name && !items && typeof initValue[name] !== 'undefined') {
|
if (name && !items && typeof initValue?.[name] !== 'undefined') {
|
||||||
if (typeof value[name] === 'undefined') {
|
if (typeof value[name] === 'undefined') {
|
||||||
if (type === 'number') {
|
if (type === 'number') {
|
||||||
value[name] = Number(initValue[name]);
|
value[name] = Number(initValue[name]);
|
||||||
} else {
|
} else {
|
||||||
value[name] = typeof initValue[name] === 'object' ? cloneDeep(initValue[name]) : initValue[name];
|
value[name] = typeof initValue[name] === 'object' ? initValue[name] : initValue[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,13 +280,15 @@ export const initValue = async (
|
|||||||
) => {
|
) => {
|
||||||
if (!Array.isArray(config)) throw new Error('config应该为数组');
|
if (!Array.isArray(config)) throw new Error('config应该为数组');
|
||||||
|
|
||||||
let valuesTmp = createValues(mForm, config, toRaw(initValues), {});
|
const initValuesCopy = cloneDeep(initValues);
|
||||||
|
|
||||||
|
let valuesTmp = createValues(mForm, config, initValuesCopy, {});
|
||||||
|
|
||||||
const [firstForm] = config as [ContainerCommonConfig];
|
const [firstForm] = config as [ContainerCommonConfig];
|
||||||
if (firstForm && typeof firstForm.onInitValue === 'function') {
|
if (firstForm && typeof firstForm.onInitValue === 'function') {
|
||||||
valuesTmp = await firstForm.onInitValue(mForm, {
|
valuesTmp = await firstForm.onInitValue(mForm, {
|
||||||
formValue: valuesTmp,
|
formValue: valuesTmp,
|
||||||
initValue: initValues,
|
initValue: initValuesCopy,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user