Files
auto-solution/modeler/src/views/decision/utils/node.ts

55 lines
1.4 KiB
TypeScript
Raw Normal View History

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';
2026-02-08 20:41:49 +08:00
import type { GraphTaskElement, GraphTaskRect } from '../builder/element';
2026-02-08 17:57:40 +08:00
import { generateKey } from '@/utils/strings';
2026-02-08 15:59:14 +08:00
2026-02-08 20:27:40 +08:00
export const createGraphTaskElementFromTemplate = (
2026-02-08 15:59:14 +08:00
template: NodeTemplate,
2026-02-08 20:41:49 +08:00
rect?: GraphTaskRect,
2026-02-08 20:27:40 +08:00
): GraphTaskElement => {
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),
2026-02-08 20:41:49 +08:00
type: 'task',
2026-02-08 15:59:14 +08:00
template: template.id,
name: template.name,
2026-02-08 20:41:49 +08:00
category: template.type,
2026-02-08 15:59:14 +08:00
description: template.description,
position: {
x: realRect.x ?? 0,
y: realRect.y ?? 0,
},
width: realRect.width,
height: realRect.height,
inputs: null,
outputs: null,
2026-02-08 20:41:49 +08:00
parameters: [],
2026-02-08 15:59:14 +08:00
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
],
2026-02-08 20:27:40 +08:00
} as GraphTaskElement;
2026-02-08 15:59:14 +08:00
};