Skip to content

Commit 3cc4733

Browse files
committed
update
1 parent 397c5eb commit 3cc4733

6 files changed

Lines changed: 58 additions & 44 deletions

File tree

apps/app-pc/src/pages/meta.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
{
2-
"binds": [
3-
{
4-
"dataType": "GroovyBindObject",
5-
"name": "$request"
6-
}
7-
],
8-
"description": "run 函数是脚本的主入口,由引擎在每次任务触发时自动调用。\\n\\n参数说明:\\n - request: MyScriptRequest 类型,包含本次请求携带的所有业务字段。\\n\\n返回值:Integer 类型,表示本次执行的结果状态码。\\n - 0 表示成功\\n - 1 表示参数校验失败\\n - 2 表示业务逻辑异常\\n\\n注意事项:\\n 1. 函数内部可以通过 $request 访问全局注入对象,获取上下文环境信息(如租户 ID、用户身份等)。\\n 2. 请勿在函数内执行耗时超过 5 秒的同步操作,否则引擎会触发超时中断并记录告警日志。\\n 3. 所有对 request 字段的访问应提前做非空判断,避免 NullPointerException 导致整个任务失败。\\n 4. 若需要调用外部 HTTP 接口,请使用内置的 httpUtil 工具类,而非直接 new URL 连接,以确保连接池复用与超时管控生效。",
2+
"binds": [],
3+
"description": "这是一个run函数,返回的格式为int类型。",
94
"mainMethod": "run",
105
"requests": [
116
{
127
"dataType": "MyScriptRequest",
13-
"description": "我的测试对象",
148
"name": "request"
159
}
1610
],
1711
"returnType": "Integer",
1812
"types": {
1913
"MyScriptRequest": {
2014
"dataType": "MyScriptRequest",
21-
"description": "我的测试对象",
15+
"empty": false,
2216
"fields": [
2317
{
18+
"dataType": "int",
19+
"description": "总数量",
20+
"name": "count"
21+
},
22+
{
2423
"dataType": "int",
2524
"description": "总数量",
2625
"name": "get('count')"
@@ -41,33 +40,39 @@
4140
"description": "描述信息",
4241
"name": "count"
4342
}
44-
]
43+
],
44+
"returnType": "boolean"
4545
}
4646
]
4747
},
4848
"Integer": {
4949
"dataType": "Integer",
50+
"empty": true,
5051
"fields": [],
5152
"functions": []
5253
},
5354
"boolean": {
5455
"dataType": "boolean",
56+
"empty": true,
5557
"fields": [],
5658
"functions": []
5759
},
5860
"Long": {
5961
"dataType": "Long",
62+
"empty": true,
6063
"fields": [],
6164
"functions": []
6265
},
6366
"String": {
6467
"dataType": "String",
68+
"empty": true,
6569
"fields": [],
6670
"functions": []
6771
},
6872
"MyTest": {
6973
"dataType": "MyTest",
7074
"description": "test",
75+
"empty": false,
7176
"fields": [
7277
{
7378
"dataType": "Long",
@@ -84,6 +89,7 @@
8489
},
8590
"int": {
8691
"dataType": "int",
92+
"empty": true,
8793
"fields": [],
8894
"functions": []
8995
}

packages/script-engine/src/autocomplete/completion-source.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ function buildMemberCompletions(typeInfo: ScriptTypeInfo): Completion[] {
3131

3232
for (const func of typeInfo.functions) {
3333
const sig = formatFunctionSignature(func);
34+
const ret = func.returnType ? ` → ${func.returnType}` : '';
35+
const detail = func.description
36+
? `${sig}${ret}${func.description}`
37+
: `${sig}${ret}`;
3438
options.push({
3539
label: func.name,
3640
type: 'function',
37-
detail: func.description ? `${sig}${func.description}` : sig,
41+
detail,
3842
info: func.description || undefined,
3943
apply: `${func.name}()`,
4044
boost: -1,

packages/script-engine/src/components/function-row.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface FunctionRowProps {
1010
export const FunctionRow: React.FC<FunctionRowProps> = ({ func, colors }) => {
1111
const [hovered, setHovered] = useState(false);
1212
const params = func.parameters.map((p) => `${p.name}: ${p.dataType}`).join(', ');
13-
const sig = `${func.name}(${params})`;
13+
const sig = `${func.name}(${params})${func.returnType ? ` → ${func.returnType}` : ''}`;
1414
return (
1515
<div
1616
style={{
@@ -30,6 +30,11 @@ export const FunctionRow: React.FC<FunctionRowProps> = ({ func, colors }) => {
3030
<span style={{ color: colors.textSecondary, fontSize: 11 }}>
3131
({params})
3232
</span>
33+
{func.returnType && (
34+
<span style={{ color: colors.typeColor, fontSize: 11, marginLeft: 'auto' }}>
35+
{func.returnType}
36+
</span>
37+
)}
3338
</div>
3439
{func.description && (
3540
<div style={{ fontSize: 11, color: colors.textSecondary, marginTop: 2, paddingLeft: 16 }}>

packages/script-engine/src/components/toolbar-button.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import React, { useState } from 'react';
1+
import React from 'react';
2+
import { forwardRef, useState } from 'react';
23
import type { ToolbarButtonProps } from '../types';
34

4-
export const ToolbarButton: React.FC<ToolbarButtonProps> = ({
5+
export const ToolbarButton = forwardRef<HTMLButtonElement, ToolbarButtonProps>(({
56
label,
67
title,
78
backgroundColor,
89
hoverBackgroundColor,
910
textColor,
1011
borderColor,
1112
onClick,
12-
}) => {
13+
active,
14+
}, ref) => {
1315
const [hovered, setHovered] = useState(false);
16+
const bg = active ? hoverBackgroundColor : (hovered ? hoverBackgroundColor : backgroundColor);
1417
return (
1518
<button
19+
ref={ref}
1620
onClick={onClick}
1721
onMouseEnter={() => setHovered(true)}
1822
onMouseLeave={() => setHovered(false)}
1923
style={{
2024
display: 'inline-flex',
2125
alignItems: 'center',
2226
gap: 4,
23-
background: hovered ? hoverBackgroundColor : backgroundColor,
27+
background: bg,
2428
border: `1px solid ${borderColor}`,
2529
color: textColor,
2630
cursor: 'pointer',
@@ -36,4 +40,6 @@ export const ToolbarButton: React.FC<ToolbarButtonProps> = ({
3640
{label}
3741
</button>
3842
);
39-
};
43+
});
44+
45+
ToolbarButton.displayName = 'ToolbarButton';

packages/script-engine/src/components/toolbar.tsx

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,22 @@ export const Toolbar: React.FC<ToolbarProps> = ({
212212

213213
{/* 脚本说明按钮 */}
214214
{descLines.length > 0 && (
215-
<button
215+
<ToolbarButton
216216
ref={descBtnRef}
217-
onClick={() => setShowDesc((v) => !v)}
218-
style={{
219-
display: 'inline-flex',
220-
alignItems: 'center',
221-
gap: 4,
222-
padding: '4px 10px',
223-
borderRadius: 4,
224-
border: `1px solid ${isDark ? '#2d5a27' : '#b7eb8f'}`,
225-
background: showDesc
226-
? (isDark ? '#3a7033' : '#d4ecd3')
227-
: (isDark ? '#2d5a27' : '#e6f4e5'),
228-
color: isDark ? '#98c379' : '#389e0d',
229-
cursor: 'pointer',
230-
fontSize: 12,
231-
lineHeight: 1.4,
232-
whiteSpace: 'nowrap',
233-
transition: 'background 0.15s',
234-
}}
217+
label={
218+
<>
219+
<QuestionIcon color="currentColor" />
220+
脚本说明
221+
</>
222+
}
235223
title={showDesc ? '隐藏脚本说明' : '查看脚本说明'}
236-
>
237-
<QuestionIcon color="currentColor" />
238-
脚本说明
239-
</button>
224+
backgroundColor={isDark ? '#2d5a27' : '#e6f4e5'}
225+
hoverBackgroundColor={isDark ? '#3a7033' : '#d4ecd3'}
226+
textColor={isDark ? '#98c379' : '#389e0d'}
227+
borderColor={isDark ? '#2d5a27' : '#b7eb8f'}
228+
active={showDesc}
229+
onClick={() => setShowDesc((v) => !v)}
230+
/>
240231
)}
241232

242233
{enableThemeToggle && (

packages/script-engine/src/types/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ export interface ToolbarButtonProps {
99
/** 鼠标悬停提示文字(原生 title 属性) */
1010
title: string;
1111
/** 按钮背景色 */
12-
backgroundColor: string;
12+
backgroundColor?: string;
1313
/** 鼠标悬停时的背景色 */
14-
hoverBackgroundColor: string;
14+
hoverBackgroundColor?: string;
1515
/** 文字颜色 */
16-
textColor: string;
16+
textColor?: string;
1717
/** 边框颜色 */
18-
borderColor: string;
18+
borderColor?: string;
1919
/** 点击回调 */
2020
onClick: () => void;
21+
/** 是否处于激活状态(可选,激活时使用 hoverBackgroundColor 作为背景色) */
22+
active?: boolean;
2123
}
2224

2325
/** 工具栏自定义按钮项(用于 toolbar 数组) */

0 commit comments

Comments
 (0)