fix(web): workflow bug

This commit is contained in:
zhaoying
2025-12-22 20:01:10 +08:00
parent 9f7bafe7fb
commit cd325fe198
4 changed files with 18 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef }>(({ appId
setChatList([])
}
const handleEditVariables = () => {
variableConfigModalRef.current?.handleOpen()
variableConfigModalRef.current?.handleOpen(variables)
}
const handleSave = (values: StartVariableItem[]) => {
setVariables([...values])
@@ -91,7 +91,7 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef }>(({ appId
}])
setChatList(prev => [...prev, {
role: 'assistant',
content: message,
content: '',
created_at: Date.now(),
}])

View File

@@ -12,12 +12,12 @@ interface VariableEditModalProps {
const VariableConfigModal = forwardRef<VariableEditModalRef, VariableEditModalProps>(({
refresh,
variables
}, ref) => {
const { t } = useTranslation();
const [visible, setVisible] = useState(false);
const [form] = Form.useForm<{variables: StartVariableItem[]}>();
const [loading, setLoading] = useState(false)
const [initialValues, setInitialValues] = useState<StartVariableItem[]>([])
// 封装取消方法,添加关闭弹窗逻辑
const handleClose = () => {
@@ -26,9 +26,10 @@ const VariableConfigModal = forwardRef<VariableEditModalRef, VariableEditModalPr
setLoading(false)
};
const handleOpen = () => {
const handleOpen = (values: StartVariableItem[]) => {
setVisible(true);
form.setFieldsValue({variables: values})
setInitialValues([...values])
};
// 封装保存方法,添加提交逻辑
const handleSave = () => {
@@ -59,18 +60,18 @@ const VariableConfigModal = forwardRef<VariableEditModalRef, VariableEditModalPr
form={form}
layout="horizontal"
scrollToFirstError={{ behavior: 'instant', block: 'end', focus: true }}
initialValues={{ variables: variables }}
>
<Form.List name="variables">
{(fields) => (
<>
{fields.map(({ name }, index) => {
const field = variables[index]
const field = initialValues[index]
return (
<Form.Item
key={name}
name={[name, 'value']}
label={field.type === 'boolean' ? undefined : `${field.name}·${field.description}`}
valuePropName={field.type === 'boolean' ? 'checked' : 'value'}
rules={[
{ required: field.required, message: field.type === 'boolean' ? t('common.pleaseSelect') : t('common.pleaseEnter') },
]}

View File

@@ -138,6 +138,15 @@ export const useWorkflowGraph = ({
})
graphRef.current.addEdges(edgeList.filter(vo => vo !== null))
}
// 初始化完成后,将节点展示在可视区域内
if (nodes.length > 0 || edges.length > 0) {
setTimeout(() => {
if (graphRef.current) {
graphRef.current.centerContent()
}
}, 200)
}
}
const saveState = () => {

View File

@@ -75,7 +75,7 @@ export interface WorkflowConfig {
}
export interface VariableEditModalRef {
handleOpen: (values?: StartVariableItem) => void;
handleOpen: (values: StartVariableItem[]) => void;
}
export interface StartVariableItem {
name: string;