2025-07-06 21:27:44 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 将值复制到目标对象,且以目标对象属性为准,例:target: {a:1} source:{a:2,b:3} 结果为:{a:2}
|
|
|
|
|
|
* @param target 目标对象
|
|
|
|
|
|
* @param source 源对象
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const copyValueToTarget = (target: any, source: any) => {
|
|
|
|
|
|
const newObj = Object.assign({}, target, source);
|
|
|
|
|
|
// 删除多余属性
|
|
|
|
|
|
Object.keys(newObj).forEach((key) => {
|
|
|
|
|
|
// 如果不是target中的属性则删除
|
2025-08-31 21:17:11 +08:00
|
|
|
|
if (!Object.keys(target).includes(key)) {
|
2025-07-06 21:27:44 +08:00
|
|
|
|
delete newObj[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
// 更新目标对象值
|
|
|
|
|
|
Object.assign(target, newObj);
|
|
|
|
|
|
};
|