Skip to content

Commit 9e14137

Browse files
authored
Merge pull request #47 from codingapi/dev
Dev
2 parents 177d6b1 + 8d7f9b9 commit 9e14137

31 files changed

Lines changed: 1081 additions & 2307 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import {ScriptType,GroovyVariableMapping} from '@/components/design-editor/typings/script';
2+
import {Button, Input, Space} from 'antd';
3+
import React from "react";
4+
import {GroovyScriptContent} from "@/components/design-editor/node-components/scripts/components/groovy-script-modal";
5+
import {
6+
NodeTitleGroovyConvertor
7+
} from "@/components/design-editor/node-components/scripts/services/convertor/node-title";
8+
import { DeleteOutlined } from "@ant-design/icons";
9+
import {
10+
GroovyScriptConverterContext
11+
} from "@/components/design-editor/node-components/scripts/services/convertor/utils";
12+
13+
const {TextArea} = Input;
14+
15+
interface ScriptEditorProps {
16+
/** 脚本类型 */
17+
type: ScriptType;
18+
/** 当前脚本内容 */
19+
script: string;
20+
/** 变量映射列表 */
21+
variables: GroovyVariableMapping[];
22+
/** 脚本变更回调 */
23+
onChange: (script: string) => void;
24+
/** 是否只读 */
25+
readonly?: boolean;
26+
}
27+
28+
/**
29+
* 高级脚本编辑器组件
30+
* 支持自由编辑 Groovy 脚本
31+
*/
32+
export const ScriptEditor:React.FC<ScriptEditorProps> = (props: ScriptEditorProps)=> {
33+
const {script, onChange, readonly = false, variables} = props;
34+
35+
const handleChange = (value: string) => {
36+
if (!readonly) {
37+
onChange(value);
38+
}
39+
};
40+
41+
return (
42+
<TextArea
43+
value={script}
44+
onChange={(e) => handleChange(e.target.value)}
45+
readOnly={readonly}
46+
style={{ fontFamily: 'Courier New, monospace' }}
47+
placeholder="请输入 Groovy 脚本..."
48+
autoSize={{ minRows: 6, maxRows: 10 }}
49+
/>
50+
);
51+
}
52+
53+
54+
export const AdvancedScriptEditor: React.FC<GroovyScriptContent> = (props) => {
55+
56+
const groovyScriptConvertor = GroovyScriptConverterContext.getInstance().createConverter(props.type, props.content, props.variables);
57+
58+
if(groovyScriptConvertor) {
59+
60+
return (
61+
<div>
62+
自定义脚本
63+
<ScriptEditor
64+
type={props.type}
65+
script={props.content}
66+
variables={props.variables}
67+
onChange={props.onChange}
68+
/>
69+
<Space
70+
style={{
71+
marginTop: 8
72+
}}
73+
>
74+
<Button
75+
icon={<DeleteOutlined/>}
76+
danger={true}
77+
onClick={() => {
78+
props.onChange(groovyScriptConvertor.getDefaultScript());
79+
}}
80+
>
81+
重置配置
82+
</Button>
83+
</Space>
84+
</div>
85+
)
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import React from 'react';
2+
import {Modal} from 'antd';
3+
import {ScriptType,GroovyVariableMapping} from '@/components/design-editor/typings/script';
4+
5+
6+
export interface GroovyScriptModalProps {
7+
open: boolean;
8+
/** 脚本类型 */
9+
scriptType: ScriptType;
10+
/** 当前脚本 */
11+
script: string;
12+
/** 变量映射列表 */
13+
variables: GroovyVariableMapping[];
14+
/** 确认回调 */
15+
onConfirm: (script: string) => void;
16+
/** 取消回调 */
17+
onCancel: () => void;
18+
/** 弹框标题 */
19+
title?: string;
20+
/** 自定义内容组件(可选) */
21+
content:React.ComponentType<GroovyScriptContent>;
22+
}
23+
24+
25+
export interface GroovyScriptContent {
26+
/** 脚本类型 */
27+
type: ScriptType;
28+
/** 当前脚本 */
29+
content: string;
30+
/** 变量映射列表 */
31+
variables: GroovyVariableMapping[];
32+
/** 确认回调 */
33+
onChange: (script: string) => void;
34+
}
35+
36+
interface GroovyScriptContentComponentAction{
37+
handleConfirm: () => void;
38+
}
39+
40+
interface GroovyScriptContentComponentProps extends GroovyScriptModalProps{
41+
actionRef:React.Ref<GroovyScriptContentComponentAction>;
42+
}
43+
44+
const GroovyScriptContentComponent: React.FC<GroovyScriptContentComponentProps> = (props) => {
45+
const [content, setContent] = React.useState(props.script);
46+
const GroovyContent = props.content;
47+
48+
React.useImperativeHandle(props.actionRef,()=>{
49+
return {
50+
handleConfirm:() => {
51+
props.onConfirm(content);
52+
props.onCancel();
53+
}
54+
}
55+
},[content]);
56+
57+
return (
58+
<GroovyContent
59+
type={props.scriptType}
60+
content={content}
61+
variables={props.variables}
62+
onChange={setContent}
63+
/>
64+
)
65+
}
66+
67+
/**
68+
* 通用脚本配置弹框
69+
* 支持普通模式和高级模式切换
70+
*/
71+
export const GroovyScriptModal: React.FC<GroovyScriptModalProps> = (props) => {
72+
73+
const actionRef = React.useRef<GroovyScriptContentComponentAction>(null);
74+
75+
const handleOk = () => {
76+
if (actionRef.current) {
77+
actionRef.current.handleConfirm();
78+
}
79+
}
80+
81+
return (
82+
<Modal
83+
title={props.title}
84+
open={props.open}
85+
onCancel={props.onCancel}
86+
onOk={handleOk}
87+
width={800}
88+
okText="确认"
89+
cancelText="取消"
90+
destroyOnHidden={true}
91+
>
92+
<GroovyScriptContentComponent
93+
{...props}
94+
actionRef={actionRef}
95+
/>
96+
</Modal>
97+
);
98+
};
99+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from "react";
2+
import {GroovyVariableMapping, ScriptType} from "@/components/design-editor/typings/script";
3+
import {
4+
GroovyScriptConverterContext
5+
} from "@/components/design-editor/node-components/scripts/services/convertor/utils";
6+
7+
interface GroovyScriptPreviewProps {
8+
script: string;
9+
variables: GroovyVariableMapping[];
10+
type: ScriptType;
11+
// 多行
12+
multiline?: boolean;
13+
}
14+
15+
export const GroovyScriptPreview: React.FC<GroovyScriptPreviewProps> = (props) => {
16+
const groovyScriptConvertor = GroovyScriptConverterContext.getInstance().createConverter(props.type, props.script, props.variables);
17+
18+
const multiline = props.multiline || false;
19+
20+
const value = groovyScriptConvertor?.toExpression() || '';
21+
22+
return (
23+
<>
24+
{multiline && (
25+
<div
26+
style={{
27+
minHeight: '45px',
28+
padding: '4px 11px',
29+
border: '1px solid #d9d9d9',
30+
borderRadius: '6px 0 0 6px',
31+
backgroundColor: value ? '#fff' : '#fafafa',
32+
color: value ? 'rgba(0,0,0,0.88)' : 'rgba(0,0,0,0.25)',
33+
}}
34+
>
35+
{value}
36+
</div>
37+
)}
38+
39+
{!multiline && (
40+
<div
41+
style={{
42+
flex: 1,
43+
padding: '4px 11px',
44+
backgroundColor: value ? '#fff' : '#fafafa',
45+
border: '1px solid #d9d9d9',
46+
borderRadius: '6px 0 0 6px',
47+
color: value ? 'rgba(0,0,0,0.88)' : 'rgba(0,0,0,0.25)',
48+
whiteSpace: 'nowrap',
49+
overflow: 'hidden',
50+
textOverflow: 'ellipsis',
51+
}}
52+
>
53+
{value}
54+
</div>
55+
)}
56+
</>
57+
58+
)
59+
}

0 commit comments

Comments
 (0)