Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
0d0bf063
authored
Jul 18, 2025
by
Archer
Committed by
GitHub
Jul 18, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: variablesinit (#5247)
parent
9860a7a9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
29 deletions
+30
-29
projects/app/src/components/core/app/formRender/LabelAndForm.tsx
+2
-3
projects/app/src/components/core/app/formRender/utils.ts
+1
-1
projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInputForm.tsx
+20
-15
projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx
+7
-10
No files found.
projects/app/src/components/core/app/formRender/LabelAndForm.tsx
View file @
0d0bf063
...
@@ -2,7 +2,7 @@ import type { BoxProps } from '@chakra-ui/react';
...
@@ -2,7 +2,7 @@ import type { BoxProps } from '@chakra-ui/react';
import
{
Box
,
Flex
}
from
'@chakra-ui/react'
;
import
{
Box
,
Flex
}
from
'@chakra-ui/react'
;
import
FormLabel
from
'@fastgpt/web/components/common/MyBox/FormLabel'
;
import
FormLabel
from
'@fastgpt/web/components/common/MyBox/FormLabel'
;
import
QuestionTip
from
'@fastgpt/web/components/common/MyTooltip/QuestionTip'
;
import
QuestionTip
from
'@fastgpt/web/components/common/MyTooltip/QuestionTip'
;
import
React
,
{
useMemo
}
from
'react'
;
import
React
from
'react'
;
import
type
{
UseFormReturn
}
from
'react-hook-form'
;
import
type
{
UseFormReturn
}
from
'react-hook-form'
;
import
{
Controller
}
from
'react-hook-form'
;
import
{
Controller
}
from
'react-hook-form'
;
import
InputRender
from
'.'
;
import
InputRender
from
'.'
;
...
@@ -46,14 +46,13 @@ const LabelAndFormRender = ({
...
@@ -46,14 +46,13 @@ const LabelAndFormRender = ({
const
{
control
}
=
variablesForm
;
const
{
control
}
=
variablesForm
;
return
(
return
(
<
Box
_notLast=
{
{
mb
:
4
}
}
px=
{
1
}
>
<
Box
_notLast=
{
{
mb
:
4
}
}
>
<
Flex
alignItems=
{
'center'
}
mb=
{
1
}
>
<
Flex
alignItems=
{
'center'
}
mb=
{
1
}
>
<
FormLabel
required=
{
required
}
>
{
label
}
</
FormLabel
>
<
FormLabel
required=
{
required
}
>
{
label
}
</
FormLabel
>
{
placeholder
&&
<
QuestionTip
ml=
{
1
}
label=
{
placeholder
}
/>
}
{
placeholder
&&
<
QuestionTip
ml=
{
1
}
label=
{
placeholder
}
/>
}
</
Flex
>
</
Flex
>
<
Controller
<
Controller
key=
{
formKey
}
control=
{
control
}
control=
{
control
}
name=
{
formKey
}
name=
{
formKey
}
rules=
{
{
rules=
{
{
...
...
projects/app/src/components/core/app/formRender/utils.ts
View file @
0d0bf063
...
@@ -11,7 +11,7 @@ export const variableInputTypeToInputType = (inputType: VariableInputEnum) => {
...
@@ -11,7 +11,7 @@ export const variableInputTypeToInputType = (inputType: VariableInputEnum) => {
if
(
inputType
===
VariableInputEnum
.
textarea
)
return
InputTypeEnum
.
textarea
;
if
(
inputType
===
VariableInputEnum
.
textarea
)
return
InputTypeEnum
.
textarea
;
if
(
inputType
===
VariableInputEnum
.
numberInput
)
return
InputTypeEnum
.
numberInput
;
if
(
inputType
===
VariableInputEnum
.
numberInput
)
return
InputTypeEnum
.
numberInput
;
if
(
inputType
===
VariableInputEnum
.
select
)
return
InputTypeEnum
.
select
;
if
(
inputType
===
VariableInputEnum
.
select
)
return
InputTypeEnum
.
select
;
return
InputTypeEnum
.
textarea
;
return
InputTypeEnum
.
JSONEditor
;
};
};
// 节点输入类型(通常是一个 reference+一个 form input)
// 节点输入类型(通常是一个 reference+一个 form input)
...
...
projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInputForm.tsx
View file @
0d0bf063
...
@@ -37,16 +37,21 @@ const VariableInput = ({
...
@@ -37,16 +37,21 @@ const VariableInput = ({
[
allVariableList
,
showExternalVariables
]
[
allVariableList
,
showExternalVariables
]
);
);
const
{
getValues
,
setValue
}
=
variablesForm
;
const
{
getValues
,
setValue
,
reset
}
=
variablesForm
;
// Init variables and add default values
useEffect
(()
=>
{
useEffect
(()
=>
{
const
values
=
getValues
();
allVariableList
.
forEach
((
item
)
=>
{
allVariableList
.
forEach
((
item
)
=>
{
const
val
=
getValues
(
`variables.
${
item
.
key
}
`
);
const
val
=
getValues
(
`variables.
${
item
.
key
}
`
);
if
(
item
.
defaultValue
!==
undefined
&&
(
val
===
undefined
||
val
===
null
||
val
===
''
))
{
if
(
item
.
defaultValue
!==
undefined
&&
(
val
===
undefined
||
val
===
null
||
val
===
''
))
{
setValue
(
`variables.
${
item
.
key
}
`
,
item
.
defaultValue
)
;
values
.
variables
[
item
.
key
]
=
item
.
defaultValue
;
}
}
});
});
},
[
allVariableList
,
getValues
,
setValue
,
variableList
]);
reset
(
values
);
},
[
allVariableList
,
getValues
,
reset
,
setValue
,
variableList
]);
return
(
return
(
<
Box
py=
{
3
}
>
<
Box
py=
{
3
}
>
...
@@ -90,6 +95,7 @@ const VariableInput = ({
...
@@ -90,6 +95,7 @@ const VariableInput = ({
leftIcon=
{
<
MyIcon
name=
{
'core/chat/chatFill'
}
w=
{
'16px'
}
/>
}
leftIcon=
{
<
MyIcon
name=
{
'core/chat/chatFill'
}
w=
{
'16px'
}
/>
}
size=
{
'sm'
}
size=
{
'sm'
}
maxW=
{
'100px'
}
maxW=
{
'100px'
}
mt=
{
4
}
onClick=
{
variablesForm
.
handleSubmit
(()
=>
{
onClick=
{
variablesForm
.
handleSubmit
(()
=>
{
chatForm
.
setValue
(
'chatStarted'
,
true
);
chatForm
.
setValue
(
'chatStarted'
,
true
);
})
}
})
}
...
@@ -123,18 +129,17 @@ const VariableInput = ({
...
@@ -123,18 +129,17 @@ const VariableInput = ({
/>
/>
))
}
))
}
{
!
chatStarted
&&
(
{
!
chatStarted
&&
(
<
Box
>
<
Button
<
Button
leftIcon=
{
<
MyIcon
name=
{
'core/chat/chatFill'
}
w=
{
'16px'
}
/>
}
leftIcon=
{
<
MyIcon
name=
{
'core/chat/chatFill'
}
w=
{
'16px'
}
/>
}
size=
{
'sm'
}
size=
{
'sm'
}
maxW=
{
'100px'
}
maxW=
{
'100px'
}
mt=
{
4
}
onClick=
{
variablesForm
.
handleSubmit
(()
=>
{
onClick=
{
variablesForm
.
handleSubmit
(()
=>
{
chatForm
.
setValue
(
'chatStarted'
,
true
);
chatForm
.
setValue
(
'chatStarted'
,
true
);
})
}
})
}
>
>
{
t
(
'chat:start_chat'
)
}
{
t
(
'chat:start_chat'
)
}
</
Button
>
</
Button
>
</
Box
>
)
}
)
}
</
Card
>
</
Card
>
</
Box
>
</
Box
>
...
...
projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx
View file @
0d0bf063
...
@@ -29,16 +29,18 @@ const VariablePopover = ({
...
@@ -29,16 +29,18 @@ const VariablePopover = ({
const
hasExternalVariable
=
externalVariableList
.
length
>
0
;
const
hasExternalVariable
=
externalVariableList
.
length
>
0
;
const
hasVariable
=
variableList
.
length
>
0
;
const
hasVariable
=
variableList
.
length
>
0
;
const
{
getValues
,
setValue
}
=
variablesForm
;
const
{
getValues
,
reset
}
=
variablesForm
;
useEffect
(()
=>
{
useEffect
(()
=>
{
const
values
=
getValues
();
variables
.
forEach
((
item
)
=>
{
variables
.
forEach
((
item
)
=>
{
const
val
=
getValues
(
`variables.
${
item
.
key
}
`
);
const
val
=
getValues
(
`variables.
${
item
.
key
}
`
);
if
(
item
.
defaultValue
!==
undefined
&&
(
val
===
undefined
||
val
===
null
||
val
===
''
))
{
if
(
item
.
defaultValue
!==
undefined
&&
(
val
===
undefined
||
val
===
null
||
val
===
''
))
{
setValue
(
`variables.
${
item
.
key
}
`
,
item
.
defaultValue
)
;
values
.
variables
[
item
.
key
]
=
item
.
defaultValue
;
}
}
});
});
},
[
variables
]);
reset
(
values
);
},
[
getValues
,
reset
,
variables
]);
return
(
return
(
<
MyPopover
<
MyPopover
...
@@ -52,7 +54,7 @@ const VariablePopover = ({
...
@@ -52,7 +54,7 @@ const VariablePopover = ({
}
}
>
>
{
({
onClose
})
=>
(
{
({
onClose
})
=>
(
<
Box
p=
{
4
}
>
<
Box
p=
{
4
}
maxH=
{
'60vh'
}
>
{
hasExternalVariable
&&
(
{
hasExternalVariable
&&
(
<
Box
textAlign=
{
'left'
}
>
<
Box
textAlign=
{
'left'
}
>
<
Flex
<
Flex
...
@@ -83,7 +85,7 @@ const VariablePopover = ({
...
@@ -83,7 +85,7 @@ const VariablePopover = ({
)
}
)
}
{
hasExternalVariable
&&
hasVariable
&&
<
MyDivider
h=
{
'1px'
}
/>
}
{
hasExternalVariable
&&
hasVariable
&&
<
MyDivider
h=
{
'1px'
}
/>
}
{
hasVariable
&&
(
{
hasVariable
&&
(
<
Box
textAlign=
{
'left'
}
>
<
Box
>
{
variableList
.
map
((
item
)
=>
(
{
variableList
.
map
((
item
)
=>
(
<
LabelAndFormRender
<
LabelAndFormRender
{
...
item
}
{
...
item
}
...
@@ -97,11 +99,6 @@ const VariablePopover = ({
...
@@ -97,11 +99,6 @@ const VariablePopover = ({
))
}
))
}
</
Box
>
</
Box
>
)
}
)
}
<
Flex
w=
{
'full'
}
justifyContent=
{
'flex-end'
}
>
<
Button
size=
{
'sm'
}
onClick=
{
onClose
}
>
{
t
(
'common:Confirm'
)
}
</
Button
>
</
Flex
>
</
Box
>
</
Box
>
)
}
)
}
</
MyPopover
>
</
MyPopover
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment