179 lines
3.5 KiB
TypeScript
179 lines
3.5 KiB
TypeScript
|
|
/*
|
||
|
|
* This file is part of the kernelstudio package.
|
||
|
|
*
|
||
|
|
* (c) 2014-2025 zlin <admin@kernelstudio.com>
|
||
|
|
*
|
||
|
|
* For the full copyright and license information, please view the LICENSE file
|
||
|
|
* that was distributed with this source code.
|
||
|
|
*/
|
||
|
|
import {MockMethod} from 'vite-plugin-mock';
|
||
|
|
import {createResponse} from './core';
|
||
|
|
|
||
|
|
const statusOption = {
|
||
|
|
type: 'select',
|
||
|
|
defaults: 0,
|
||
|
|
name: 'status',
|
||
|
|
tips: '状态',
|
||
|
|
options: [
|
||
|
|
{
|
||
|
|
name: '默认',
|
||
|
|
value: 'default',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: '运行中',
|
||
|
|
value: 'running',
|
||
|
|
color: 'blue',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: '已完成',
|
||
|
|
value: 'finished',
|
||
|
|
color: 'teal'
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: '错误',
|
||
|
|
value: 'error',
|
||
|
|
color: 'red',
|
||
|
|
},
|
||
|
|
]
|
||
|
|
}
|
||
|
|
|
||
|
|
const behaviors = [
|
||
|
|
{
|
||
|
|
id: 'behavior_001',
|
||
|
|
name: '行为树1',
|
||
|
|
desc: '行为树1说明',
|
||
|
|
status: null,
|
||
|
|
options: {},
|
||
|
|
// data: [
|
||
|
|
// {
|
||
|
|
// id: '5a0c4b08-0b02-44f3-8918-79c6f9ab22fa',
|
||
|
|
// type: 'startEvent',
|
||
|
|
// name: '开始',
|
||
|
|
// description: '',
|
||
|
|
// width: 160,
|
||
|
|
// height: 40,
|
||
|
|
// position: {
|
||
|
|
// x: 460,
|
||
|
|
// y: 120,
|
||
|
|
// },
|
||
|
|
// data: {
|
||
|
|
// status: 'default',
|
||
|
|
// }
|
||
|
|
// },
|
||
|
|
// {
|
||
|
|
// id: 'ec8741db-9580-44ab-8a58-8c731bf1faad',
|
||
|
|
// type: 'sequenceFlow',
|
||
|
|
// name: null,
|
||
|
|
// description: null,
|
||
|
|
// source: '5a0c4b08-0b02-44f3-8918-79c6f9ab22fa',
|
||
|
|
// target: '7422aefc-7781-457a-b910-783f73ac0ac5',
|
||
|
|
// data: {
|
||
|
|
// status: 'default',
|
||
|
|
// }
|
||
|
|
// },
|
||
|
|
// {
|
||
|
|
// id: '7422aefc-7781-457a-b910-783f73ac0ac5',
|
||
|
|
// type: 'task',
|
||
|
|
// name: '任务',
|
||
|
|
// description: '',
|
||
|
|
// width: 160,
|
||
|
|
// height: 40,
|
||
|
|
// position: {
|
||
|
|
// x: 460,
|
||
|
|
// y: 120,
|
||
|
|
// },
|
||
|
|
// data: {
|
||
|
|
// status: 'default',
|
||
|
|
// }
|
||
|
|
// },
|
||
|
|
// ]
|
||
|
|
}
|
||
|
|
]
|
||
|
|
|
||
|
|
|
||
|
|
const definitions = [
|
||
|
|
{
|
||
|
|
type: 'sequenceFlow',
|
||
|
|
label: null,
|
||
|
|
options: [
|
||
|
|
{
|
||
|
|
type: 'input',
|
||
|
|
defaults: null,
|
||
|
|
name: 'label',
|
||
|
|
}
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
type: 'startEvent',
|
||
|
|
label: '开始',
|
||
|
|
desc: '行为树的开始节点,每个行为树仅允许一个开始节点',
|
||
|
|
options: [
|
||
|
|
statusOption
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
type: 'task',
|
||
|
|
label: '任务节点',
|
||
|
|
desc: '执行特定任务',
|
||
|
|
options: [
|
||
|
|
statusOption,
|
||
|
|
{
|
||
|
|
type: 'number',
|
||
|
|
defaults: 0,
|
||
|
|
name: 'counter',
|
||
|
|
tips: '统计数量'
|
||
|
|
}
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
type: 'parallelGateway',
|
||
|
|
label: '并行网关',
|
||
|
|
desc: '并行执行子节点',
|
||
|
|
options: [
|
||
|
|
statusOption,
|
||
|
|
{
|
||
|
|
type: 'number',
|
||
|
|
defaults: 0,
|
||
|
|
name: 'counter',
|
||
|
|
tips: '统计数量'
|
||
|
|
}
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
type: 'exclusiveGateway',
|
||
|
|
label: '排他网关',
|
||
|
|
desc: '选择满足条件的一个子节点执行',
|
||
|
|
options: [
|
||
|
|
statusOption,
|
||
|
|
{
|
||
|
|
type: 'number',
|
||
|
|
defaults: 0,
|
||
|
|
name: 'counter',
|
||
|
|
tips: '统计数量'
|
||
|
|
}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
]
|
||
|
|
|
||
|
|
export default [
|
||
|
|
{
|
||
|
|
url: '/api/behavior/trees',
|
||
|
|
method: 'get',
|
||
|
|
response: () => {
|
||
|
|
return createResponse(behaviors)
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
url: '/api/behavior/trees',
|
||
|
|
method: 'post',
|
||
|
|
response: ({body}) => {
|
||
|
|
let value = behaviors.filter((b) => b.id == body?.id)
|
||
|
|
if (value && value.length > 0) {
|
||
|
|
value[0] = Object.assign(value[0], body)
|
||
|
|
} else {
|
||
|
|
behaviors.push(body)
|
||
|
|
}
|
||
|
|
return createResponse(behaviors)
|
||
|
|
},
|
||
|
|
},
|
||
|
|
] as MockMethod[];
|