# 设置变量节点

变量赋值与声明

# 数据结构定义

# 范例

{
  id: {random(6)},
  type: 'variable',
  data: {
    title: `变量赋值与声明`,
    assign: [
      {
        operator: 'declare',     // 操作: assign 赋值,operator 声明,
        left: '',                
        right: {
          type: 'constant',
          content: 0,
        },
      },
    ],
  },
}

# 类型

export interface VariableNodeJSON extends FlowNodeJSON {
  data: {
    title: string;
    assign: AssignValueType[];
    outputs: IJsonSchema<'object'>;
  };
}

type AssignValueType = {
    operator: 'assign';
    left?: IFlowRefValue;
    right?: IFlowValue;
} | {
    operator: 'declare';
    left?: string;
    right?: IFlowValue;
};

interface IFlowRefValue {
    type: 'ref';
    content?: string[];
    extra?: IFlowValueExtra;
}

interface IFlowConstantValue {
    type: 'constant';
    content?: string | number | boolean;
    schema?: IJsonSchema;
    extra?: IFlowValueExtra;
}
interface IFlowRefValue {
    type: 'ref';
    content?: string[];
    extra?: IFlowValueExtra;
}
interface IFlowExpressionValue {
    type: 'expression';
    content?: string;
    extra?: IFlowValueExtra;
}
interface IFlowTemplateValue {
    type: 'template';
    content?: string;
    extra?: IFlowValueExtra;
}
interface IFlowValueExtra {
    index?: number;
}
type IFlowValue = IFlowConstantValue | IFlowRefValue | IFlowExpressionValue | IFlowTemplateValue;