2026-02-08 15:59:14 +08:00
|
|
|
/*
|
|
|
|
|
* This file is part of the kernelstudio package.
|
|
|
|
|
*
|
|
|
|
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE file
|
|
|
|
|
* that was distributed with this source code.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-02-08 17:57:40 +08:00
|
|
|
import type { NodeTemplate } from '../types';
|
|
|
|
|
import type { SettingTaskNodeElement, TaskNodeRect } from '../builder/element';
|
|
|
|
|
import { generateKey } from '@/utils/strings';
|
2026-02-08 15:59:14 +08:00
|
|
|
|
|
|
|
|
export const createTaskNodeElementFromTemplate = (
|
|
|
|
|
template: NodeTemplate,
|
|
|
|
|
rect?: TaskNodeRect,
|
|
|
|
|
): SettingTaskNodeElement => {
|
2026-02-08 16:01:21 +08:00
|
|
|
let realRect = { width: 200, height: 100, x: 0, y: 0, ...rect || {} }
|
|
|
|
|
console.info('rect',rect)
|
2026-02-08 15:59:14 +08:00
|
|
|
return {
|
|
|
|
|
id: 0,
|
|
|
|
|
key: generateKey(template.type),
|
|
|
|
|
status: null,
|
|
|
|
|
template: template.id,
|
|
|
|
|
type: template.type,
|
|
|
|
|
name: template.name,
|
|
|
|
|
description: template.description,
|
|
|
|
|
position: {
|
|
|
|
|
x: realRect.x ?? 0,
|
|
|
|
|
y: realRect.y ?? 0,
|
|
|
|
|
},
|
|
|
|
|
width: realRect.width,
|
|
|
|
|
height: realRect.height,
|
2026-02-08 17:57:40 +08:00
|
|
|
// settings: JSON.parse(JSON.stringify(template.parameter_defs ?? [])),
|
2026-02-08 15:59:14 +08:00
|
|
|
inputs: null,
|
|
|
|
|
outputs: null,
|
|
|
|
|
parameters: {},
|
|
|
|
|
variables: [
|
|
|
|
|
{
|
|
|
|
|
key: generateKey('var_'),
|
|
|
|
|
name: '范围',
|
|
|
|
|
value: '1000',
|
|
|
|
|
defaults: '1000',
|
2026-02-08 16:01:21 +08:00
|
|
|
unit: 'KM'
|
2026-02-08 15:59:14 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: generateKey('var_'),
|
|
|
|
|
name: '武器名称',
|
|
|
|
|
value: '地对空导弹',
|
|
|
|
|
defaults: '地对空导弹',
|
2026-02-08 16:01:21 +08:00
|
|
|
unit: '个'
|
|
|
|
|
}
|
2026-02-08 15:59:14 +08:00
|
|
|
],
|
|
|
|
|
} as SettingTaskNodeElement;
|
|
|
|
|
};
|