chore: 添加功能方法

This commit is contained in:
2betop 2024-10-10 11:51:28 +08:00
parent b527309af2
commit 0ae0fc8c6e

View File

@ -1910,6 +1910,50 @@ export function getModals(schema: any) {
}
return modals;
}
/**
* splice
* @param target
* @param path
* @param numberToDelete
* @param items
* @returns
*/
export function deepSplice(
target: any,
path: string,
numberToDelete: number,
...items: any[]
) {
const paths = path.split('.');
const last = paths.pop()!;
let host = target;
const stack: Array<{
host: any;
key: string | number | undefined;
}> = [];
for (let i = 0; i < paths.length; i++) {
stack.unshift({
key: paths[i]!,
host: host
});
host = host[paths[i]];
}
if (!Array.isArray(host)) {
throw new Error('deepSplice: target is not an array');
}
host = host.concat();
host.splice.apply(host, [last, numberToDelete].concat(items));
return stack.reduce((prefix, {host, key}) => {
host = Array.isArray(host) ? host.concat() : {...host};
host[key!] = prefix;
return host;
}, host);
}
export const RAW_TYPE_MAP: {
[k in SchemaType | 'user-select' | 'department-select']?:
| 'string'