Skip to content
Merged

Dev #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/flow-approval-presenter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @coding-flow/flow-approval-presenter

## 0.2.17

### Patch Changes

- @coding-flow/flow-types@0.2.17

## 0.2.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-approval-presenter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-approval-presenter",
"version": "0.2.16",
"version": "0.2.17",
"description": "flow-engine approval presenter framework ",
"type": "module",
"sideEffects": [
Expand Down
2 changes: 2 additions & 0 deletions packages/flow-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @coding-flow/flow-core

## 0.2.17

## 0.2.16

## 0.2.15
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-core",
"version": "0.2.16",
"version": "0.2.17",
"description": "flow-engine core lib framework ",
"type": "module",
"sideEffects": [
Expand Down
10 changes: 10 additions & 0 deletions packages/flow-design/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @coding-flow/flow-design

## 0.2.17

### Patch Changes

- 修复动作按钮样式保存不生效:背景色、边框色、圆角、边框大小统一保存到 `display.style`,并兼容历史平铺数据,重新进入设计器后可正确回显(codingapi/flow-engine#244)
- 修复动作按钮图标保存不生效:图标写入 `display.icon` 并在编辑弹窗回显,修改按钮名称时同步 `display.title`(codingapi/flow-engine#244)
- @coding-flow/flow-icons@0.2.17
- @coding-flow/flow-pc-ui@0.2.17
- @coding-flow/flow-types@0.2.17

## 0.2.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-design/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-design",
"version": "0.2.16",
"version": "0.2.17",
"description": "flow-engine design components ",
"type": "module",
"sideEffects": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ interface ActionTableProps {
onChange: (data: any[]) => void;
}

/**
* 编辑动作时回填表单数据。
* <p>
* 按钮图标在后端模型中保存在 display.icon 上,表单字段为顶层 icon,需要回填才能正确回显。
*/
const toFormValues = (action: any) => {
return {
...action,
icon: action.icon || action.display?.icon,
}
}

export const ActionTable: React.FC<ActionTableProps> = (props) => {
const { node } = useNodeRenderContext();
const presenter = new FlowActionListPresenter(props.value, props.onChange);
Expand Down Expand Up @@ -77,7 +89,7 @@ export const ActionTable: React.FC<ActionTableProps> = (props) => {
<a
onClick={() => {
form.resetFields();
form.setFieldsValue(record);
form.setFieldsValue(toFormValues(record));
setVisible(true);
}}
>
Expand Down Expand Up @@ -128,7 +140,7 @@ export const ActionTable: React.FC<ActionTableProps> = (props) => {
createCustomAction().then(res => {
if (res.success) {
const data = res.data;
form.setFieldsValue(data);
form.setFieldsValue(toFormValues(data));
setVisible(true);
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export class FlowActionListPresenter {

const actionIdList = this.data.map(action => action.id);

// 按钮名称、图标在后端模型中只存在于 display 上,表单编辑的是顶层字段,此处同步回 display
const display = {
...action.display,
title: action.title || action.display?.title,
icon: action.icon || action.display?.icon,
};

if (actionIdList.includes(actionId)) {
const data = this.data.map(item => {
if (item.id === actionId) {
Expand All @@ -65,7 +72,7 @@ export class FlowActionListPresenter {
...action,
display: {
...item.display,
...action.display,
...display,
}
}
}
Expand All @@ -75,6 +82,7 @@ export class FlowActionListPresenter {
} else {
this.onChange([...this.data, {
...action,
display,
type: "CUSTOM"
}]);
}
Expand Down
153 changes: 115 additions & 38 deletions packages/flow-design/src/script-components/components/action/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,85 @@ import { EditOutlined } from "@ant-design/icons";
import { DisplayStyle } from "@coding-flow/flow-types";


/**
* 按钮展示数据(对应后端 ActionDisplay),样式保存在 style 的 JSON 字符串中
*/
export interface ActionDisplayValue {
// 标题
title?: string;
// 样式(DisplayStyle 的 JSON 字符串)
style?: string;
// 图标
icon?: string;
// 显示条件脚本key
script?: string;
// 兼容历史数据:样式字段曾经直接挂在 display 上
backgroundColor?: string;
// 兼容历史数据:样式字段曾经直接挂在 display 上
borderColor?: string;
// 兼容历史数据:样式字段曾经直接挂在 display 上
borderRadius?: string;
// 兼容历史数据:样式字段曾经直接挂在 display 上
borderSize?: string;
}

interface ActionStyleProps {
value?: any;
onChange?: (value: any) => void;
value?: ActionDisplayValue;
onChange?: (value: ActionDisplayValue) => void;
}

/**
* 样式数据中的颜色统一不带 # 保存(审批端渲染时补全),此处用于兼容历史数据中的 # 前缀
*/
const toStoreColor = (color?: string): string | undefined => {
if (!color) {
return undefined;
}
return color.startsWith('#') ? color.slice(1) : color;
};

/**
* 颜色选择器回显的颜色值需要带 #
*/
const toPickerColor = (color?: string): string | undefined => {
if (!color) {
return undefined;
}
return color.startsWith('#') ? color : `#${color}`;
};

/**
* 解析动作按钮样式。
* <p>
* 样式统一保存在 display.style 的 JSON 字符串中(后端 ActionDisplay.style),
* 同时兼容历史上把样式字段直接挂在 display 上的数据。
*/
export const parseActionDisplayStyle = (display?: ActionDisplayValue): DisplayStyle => {
if (!display) {
return {};
}
if (typeof display.style === 'string' && display.style) {
try {
const data = JSON.parse(display.style);
if (data && typeof data === 'object') {
return {
...data,
backgroundColor: toStoreColor(data.backgroundColor),
borderColor: toStoreColor(data.borderColor),
} as DisplayStyle;
}
} catch (e) {
// 非 JSON 样式数据,继续按扁平字段解析
}
}
return {
backgroundColor: toStoreColor(display.backgroundColor),
borderColor: toStoreColor(display.borderColor),
borderRadius: display.borderRadius,
borderSize: display.borderSize,
};
};


const ActionScriptContent: React.FC<GroovyScriptContent> = (props) => {
return (
Expand Down Expand Up @@ -78,11 +152,24 @@ const ActionScript: React.FC<GroovyScriptLoaderContent> = (props) => {

export const ActionStyle: React.FC<ActionStyleProps> = (props) => {

const [style, setStyle] = React.useState<DisplayStyle>(props.value || {} as any);
const [display, setDisplay] = React.useState<ActionDisplayValue>(props.value || {});

const style = React.useMemo(() => parseActionDisplayStyle(display), [display]);

React.useEffect(() => {
props.onChange && props.onChange(style);
}, [style]);
const emit = (next: ActionDisplayValue) => {
setDisplay(next);
props.onChange?.(next);
}

const updateStyle = (patch: Partial<DisplayStyle>) => {
emit({
...display,
style: JSON.stringify({
...style,
...patch,
}),
});
}

return (
<div>
Expand All @@ -97,16 +184,11 @@ export const ActionStyle: React.FC<ActionStyleProps> = (props) => {
<span>背景颜色</span>
</Space.Addon>
<ColorPicker
value={style.backgroundColor || ''}
value={toPickerColor(style.backgroundColor)}
onChange={(value) => {
if (value) {
setStyle(prevState => {
return {
...prevState,
backgroundColor: value.toHex()
}
})
}
updateStyle({
backgroundColor: toStoreColor(value.toHex())
});
}}
/>
</Space.Compact>
Expand All @@ -121,16 +203,11 @@ export const ActionStyle: React.FC<ActionStyleProps> = (props) => {
<span>边框颜色</span>
</Space.Addon>
<ColorPicker
value={style.borderColor || ''}
value={toPickerColor(style.borderColor)}
onChange={(value) => {
if (value) {
setStyle(prevState => {
return {
...prevState,
borderColor: value.toHex()
}
})
}
updateStyle({
borderColor: toStoreColor(value.toHex())
});
}}
/>
</Space.Compact>
Expand All @@ -152,12 +229,9 @@ export const ActionStyle: React.FC<ActionStyleProps> = (props) => {
placeholder={"请输入边框圆角"}
value={style.borderRadius}
onChange={(event) => {
setStyle(prevState => {
return {
...prevState,
borderRadius: event.target.value
}
})
updateStyle({
borderRadius: event.target.value
});
}}
/>
</Space.Compact>
Expand All @@ -179,24 +253,27 @@ export const ActionStyle: React.FC<ActionStyleProps> = (props) => {
placeholder={"请输入边框大小"}
value={style.borderSize}
onChange={(event) => {
setStyle(prevState => {
return {
...prevState,
borderSize: event.target.value
}
})
updateStyle({
borderSize: event.target.value
});
}}
/>
</Space.Compact>
</Col>
<Col span={24}>
<GroovyScriptLoader
content={ActionScript}
value={style.script}
value={display?.script}
onChange={(scriptKey) => {
emit({
...display,
script: scriptKey,
});
}}
/>
</Col>
</Row>

</div>
)
}
}
Loading
Loading