Skip to content

Commit 989924d

Browse files
committed
update custom
1 parent 4340555 commit 989924d

44 files changed

Lines changed: 591 additions & 337 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/packages/flow-pc/flow-pc-design/src/components/script/utils/format.ts renamed to frontend/packages/flow-core/src/groovy.ts

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/** 自定义脚本标记 */
2+
export const CUSTOM_SCRIPT = '@CUSTOM_SCRIPT';
3+
4+
/** 脚本标题标记 */
5+
export const SCRIPT_TITLE = '@SCRIPT_TITLE';
6+
7+
8+
/** 脚本元数据标记 */
9+
export const SCRIPT_META = '@SCRIPT_META';
10+
11+
112
/**
213
* Groovy脚本格式化器
314
*/
@@ -318,3 +329,131 @@ export interface FormatOptions {
318329
maxLineLength?: number; // 最大行长度
319330
preserveEmptyLines?: boolean; // 保留空行
320331
}
332+
333+
334+
335+
/**
336+
* Groovy脚本转换器工具类,提供一些通用的脚本处理方法
337+
*/
338+
export class GroovyScriptConvertorUtil {
339+
340+
/**
341+
* 判断脚本是否包含自定义注释标记
342+
* @param script
343+
*/
344+
public static isCustomScript(script: string): boolean {
345+
return script.includes(CUSTOM_SCRIPT);
346+
}
347+
348+
349+
/**
350+
* 格式化脚本内容,去除多余空白等
351+
* @param script
352+
*/
353+
public static formatScript(script: string): string {
354+
// 这里可以添加一些格式化逻辑,比如统一换行、缩进等
355+
return GroovyFormatter.formatScript(script);
356+
}
357+
358+
359+
/**
360+
* 将普通脚本转换为包含自定义注释标记的脚本
361+
* @param script
362+
*/
363+
public static toCustomScript(script: string): string {
364+
if (GroovyScriptConvertorUtil.isCustomScript(script)) {
365+
return GroovyFormatter.formatScript(script);
366+
}
367+
return GroovyFormatter.formatScript(`// ${CUSTOM_SCRIPT}\n${script}`);
368+
}
369+
370+
371+
/**
372+
* 获取脚本中的标题注释内容
373+
* @param script
374+
*/
375+
public static getScriptTitle(script: string): string {
376+
const titleMatch = script.match(new RegExp(`//\\s*${SCRIPT_TITLE}\\s*(.+)`));
377+
if (titleMatch) {
378+
return titleMatch[1].trim();
379+
}
380+
return '';
381+
}
382+
383+
/**
384+
* 更新脚本中的标题注释内容,如果不存在则添加
385+
* @param script
386+
* @param title
387+
*/
388+
public static updateScriptTitle(script: string, title: string): string {
389+
const titleComment = `// ${SCRIPT_TITLE} ${title}`;
390+
if (GroovyScriptConvertorUtil.getScriptTitle(script)) {
391+
return script.replace(new RegExp(`//\\s*${SCRIPT_TITLE}\\s*.+`), titleComment);
392+
} else {
393+
return `${titleComment}\n${script}`;
394+
}
395+
}
396+
397+
398+
/**
399+
* 获取脚本中的元数据
400+
* @param script
401+
*/
402+
public static getScriptMeta(script: string): string {
403+
const titleMatch = script.match(new RegExp(`//\\s*${SCRIPT_META}\\s*(.+)`));
404+
if (titleMatch) {
405+
return titleMatch[1].trim();
406+
}
407+
return '';
408+
}
409+
410+
411+
/**
412+
* 更新脚本中的元数据内容,如果不存在则添加
413+
* @param script
414+
* @param meta
415+
*/
416+
public static updateScriptMeta(script: string, meta: string): string {
417+
const metaComment = `// ${SCRIPT_META} ${meta}`;
418+
if (GroovyScriptConvertorUtil.getScriptTitle(script)) {
419+
return script.replace(new RegExp(`//\\s*${SCRIPT_META}\\s*.+`), metaComment);
420+
} else {
421+
return `${metaComment}\n${script}`;
422+
}
423+
}
424+
425+
426+
/**
427+
* 清除脚本中的注释
428+
* @param script
429+
*/
430+
public static clearComments(script: string): string {
431+
return script.replace(/\/\/.*$/gm, '').trim();
432+
}
433+
434+
/**
435+
* 提取脚本中的return表达式
436+
* @param script
437+
*/
438+
public static getReturnScript(script: string): string {
439+
try {
440+
let result = GroovyScriptConvertorUtil.clearComments(script);
441+
const funcMatch = result.match(/def\s+run\s*\([^)]*\)\s*\{([\s\S]*)\}/);
442+
if (funcMatch) {
443+
result = funcMatch[1];
444+
}
445+
const returnMatch = result.match(/return\s+(.+?);?\s*$/m);
446+
if (returnMatch) {
447+
result = returnMatch[1].trim();
448+
} else {
449+
// 如果没有找到return语句,可能整个脚本就是表达式
450+
result = result.trim();
451+
}
452+
453+
return result;
454+
} catch (e) {
455+
return '';
456+
}
457+
}
458+
459+
}

frontend/packages/flow-core/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ export * from "./http";
44
export * from "./presenter";
55
export * from "./hooks.ts";
66
export * from "./object.ts";
7-
export * from "./table.ts";
7+
export * from "./table.ts";
8+
export * from "./view-plugin.ts";
9+
export * from "./groovy.ts";

frontend/packages/flow-types/src/plugins/view-bind-plugin.tsx renamed to frontend/packages/flow-core/src/view-plugin.ts

File renamed without changes.

frontend/packages/flow-pc/flow-pc-approval/src/components/flow-approval/components/action/custom.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const CustomAction: React.FC<FlowActionProps> = (props) => {
1616

1717
return (
1818
<Button
19-
danger={action.type === 'REJECT'}
2019
onClick={() => {
2120
actionPresenter.action(action.id).then((res) => {
2221
if (res.success) {

frontend/packages/flow-pc/flow-pc-approval/src/components/flow-approval/components/form-view-component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
3-
import {ViewBindPlugin} from "@flow-engine/flow-types";
3+
import {ViewBindPlugin} from "@flow-engine/flow-core";
44
import {Form as AntdForm} from "antd";
55
import {FlowFormView} from "@flow-engine/flow-pc-form";
66

frontend/packages/flow-pc/flow-pc-approval/src/components/flow-approval/plugins/view/add-audit-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {AddAuditViewPlugin, VIEW_KEY} from "../add-audit-type";
3-
import {ViewBindPlugin} from "@flow-engine/flow-types";
3+
import {ViewBindPlugin} from "@flow-engine/flow-core";
44
import {Select} from "antd";
55
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
66

frontend/packages/flow-pc/flow-pc-approval/src/components/flow-approval/plugins/view/delegate-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {DelegateViewPlugin, VIEW_KEY} from "../delegate-type";
3-
import {ViewBindPlugin} from "@flow-engine/flow-types";
3+
import {ViewBindPlugin} from "@flow-engine/flow-core";
44
import {Select} from "antd";
55
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
66

frontend/packages/flow-pc/flow-pc-approval/src/components/flow-approval/plugins/view/return-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {ReturnViewPlugin, VIEW_KEY} from "../return-type";
3-
import {ViewBindPlugin} from "@flow-engine/flow-types";
3+
import {ViewBindPlugin} from "@flow-engine/flow-core";
44
import {Select} from "antd";
55
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
66

frontend/packages/flow-pc/flow-pc-approval/src/components/flow-approval/plugins/view/sign-key-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {SignKeyViewPlugin, VIEW_KEY} from "../sign-key-type";
3-
import {ViewBindPlugin} from "@flow-engine/flow-types";
3+
import {ViewBindPlugin} from "@flow-engine/flow-core";
44
import {Input} from "antd";
55

66
const {TextArea} = Input;

frontend/packages/flow-pc/flow-pc-approval/src/components/flow-approval/plugins/view/transfer-view.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import {TransferViewPlugin, VIEW_KEY} from "../transfer-type";
3-
import {ViewBindPlugin} from "@flow-engine/flow-types";
3+
import {ViewBindPlugin} from "@flow-engine/flow-core";
44
import {Select} from "antd";
55
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
66

0 commit comments

Comments
 (0)