mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-13 12:23:29 +08:00
Add Scenario Mode with workflow editor - backend and frontend implementation
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
co-authored by
whyour
parent
a4712f2b96
commit
af88062219
@@ -0,0 +1,89 @@
|
||||
import { sequelize } from '.';
|
||||
import { DataTypes, Model } from 'sequelize';
|
||||
|
||||
interface WorkflowNode {
|
||||
id: string;
|
||||
type: 'http' | 'script' | 'condition' | 'delay' | 'loop';
|
||||
label: string;
|
||||
x?: number;
|
||||
y?: number;
|
||||
config: {
|
||||
// HTTP Request node
|
||||
url?: string;
|
||||
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||
headers?: Record<string, string>;
|
||||
body?: string;
|
||||
|
||||
// Script node
|
||||
scriptId?: number;
|
||||
scriptPath?: string;
|
||||
scriptContent?: string;
|
||||
|
||||
// Condition node
|
||||
condition?: string;
|
||||
trueNext?: string;
|
||||
falseNext?: string;
|
||||
|
||||
// Delay node
|
||||
delayMs?: number;
|
||||
|
||||
// Loop node
|
||||
iterations?: number;
|
||||
loopBody?: string[];
|
||||
};
|
||||
next?: string | string[]; // ID(s) of next node(s)
|
||||
}
|
||||
|
||||
interface WorkflowGraph {
|
||||
nodes: WorkflowNode[];
|
||||
startNode?: string;
|
||||
}
|
||||
|
||||
export class Scenario {
|
||||
name?: string;
|
||||
description?: string;
|
||||
id?: number;
|
||||
status?: 0 | 1; // 0: disabled, 1: enabled
|
||||
workflowGraph?: WorkflowGraph;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
|
||||
constructor(options: Scenario) {
|
||||
this.name = options.name;
|
||||
this.description = options.description;
|
||||
this.id = options.id;
|
||||
this.status = options.status || 0;
|
||||
this.workflowGraph = options.workflowGraph;
|
||||
this.createdAt = options.createdAt;
|
||||
this.updatedAt = options.updatedAt;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ScenarioInstance
|
||||
extends Model<Scenario, Scenario>,
|
||||
Scenario {}
|
||||
|
||||
export const ScenarioModel = sequelize.define<ScenarioInstance>(
|
||||
'Scenario',
|
||||
{
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0,
|
||||
},
|
||||
workflowGraph: {
|
||||
type: DataTypes.JSON,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user