Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
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
Commit
16b32cc6
authored
Dec 13, 2024
by
HynoR
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 优化模型设置可视化编辑器,增强输入验证和提示信息
parent
b0c595d1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
web/src/pages/Setting/Operation/ModelSettingsVisualEditor.js
+21
-5
No files found.
web/src/pages/Setting/Operation/ModelSettingsVisualEditor.js
View file @
16b32cc6
// ModelSettingsVisualEditor.js
// ModelSettingsVisualEditor.js
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Table
,
Button
,
Input
,
Modal
,
Form
,
Space
}
from
'@douyinfe/semi-ui'
;
import
{
Table
,
Button
,
Input
,
Modal
,
Form
,
Space
}
from
'@douyinfe/semi-ui'
;
import
{
IconDelete
,
IconPlus
,
IconSearch
,
IconSave
}
from
'@douyinfe/semi-icons'
;
import
{
IconDelete
,
IconPlus
,
IconSearch
,
IconSave
}
from
'@douyinfe/semi-icons'
;
import
{
showError
,
showSuccess
}
from
'../../../helpers'
;
import
{
showError
,
showSuccess
}
from
'../../../helpers'
;
import
{
API
}
from
'../../../helpers'
;
import
{
API
}
from
'../../../helpers'
;
export
default
function
ModelSettingsVisualEditor
(
props
)
{
export
default
function
ModelSettingsVisualEditor
(
props
)
{
...
@@ -67,9 +67,13 @@ export default function ModelSettingsVisualEditor(props) {
...
@@ -67,9 +67,13 @@ export default function ModelSettingsVisualEditor(props) {
// 数据转换
// 数据转换
models
.
forEach
(
model
=>
{
models
.
forEach
(
model
=>
{
currentConvertModelName
=
model
.
name
;
currentConvertModelName
=
model
.
name
;
if
(
model
.
price
!==
''
)
output
.
ModelPrice
[
model
.
name
]
=
parseFloat
(
model
.
price
);
if
(
model
.
price
!==
''
)
{
// 如果价格不为空,则转换为浮点数,忽略倍率参数
output
.
ModelPrice
[
model
.
name
]
=
parseFloat
(
model
.
price
)
}
else
{
if
(
model
.
ratio
!==
''
)
output
.
ModelRatio
[
model
.
name
]
=
parseFloat
(
model
.
ratio
);
if
(
model
.
ratio
!==
''
)
output
.
ModelRatio
[
model
.
name
]
=
parseFloat
(
model
.
ratio
);
if
(
model
.
completionRatio
!=
''
)
output
.
CompletionRatio
[
model
.
name
]
=
parseFloat
(
model
.
completionRatio
);
if
(
model
.
completionRatio
!=
''
)
output
.
CompletionRatio
[
model
.
name
]
=
parseFloat
(
model
.
completionRatio
);
}
});
});
// 准备API请求数组
// 准备API请求数组
...
@@ -130,6 +134,7 @@ export default function ModelSettingsVisualEditor(props) {
...
@@ -130,6 +134,7 @@ export default function ModelSettingsVisualEditor(props) {
<
Input
<
Input
value
=
{
text
}
value
=
{
text
}
placeholder
=
"按量计价"
placeholder
=
"按量计价"
disabled
=
{
record
.
ratio
!==
''
}
onChange
=
{
value
=>
updateModel
(
record
.
name
,
'price'
,
value
)}
onChange
=
{
value
=>
updateModel
(
record
.
name
,
'price'
,
value
)}
/
>
/
>
)
)
...
@@ -141,7 +146,9 @@ export default function ModelSettingsVisualEditor(props) {
...
@@ -141,7 +146,9 @@ export default function ModelSettingsVisualEditor(props) {
render
:
(
text
,
record
)
=>
(
render
:
(
text
,
record
)
=>
(
<
Input
<
Input
value
=
{
text
}
value
=
{
text
}
placeholder
=
"默认倍率"
placeholder
=
{
record
.
price
!==
''
?
'固定价格'
:
'默认补全倍率'
}
disabled
=
{
record
.
price
!==
''
}
onChange
=
{
value
=>
updateModel
(
record
.
name
,
'ratio'
,
value
)}
onChange
=
{
value
=>
updateModel
(
record
.
name
,
'ratio'
,
value
)}
/
>
/
>
)
)
...
@@ -153,7 +160,8 @@ export default function ModelSettingsVisualEditor(props) {
...
@@ -153,7 +160,8 @@ export default function ModelSettingsVisualEditor(props) {
render
:
(
text
,
record
)
=>
(
render
:
(
text
,
record
)
=>
(
<
Input
<
Input
value
=
{
text
}
value
=
{
text
}
placeholder
=
"默认补全值"
placeholder
=
{
record
.
price
!==
''
?
'固定价格'
:
'默认补全倍率'
}
disabled
=
{
record
.
price
!==
''
}
onChange
=
{
value
=>
updateModel
(
record
.
name
,
'completionRatio'
,
value
)}
onChange
=
{
value
=>
updateModel
(
record
.
name
,
'completionRatio'
,
value
)}
/
>
/
>
)
)
...
@@ -172,6 +180,10 @@ export default function ModelSettingsVisualEditor(props) {
...
@@ -172,6 +180,10 @@ export default function ModelSettingsVisualEditor(props) {
];
];
const
updateModel
=
(
name
,
field
,
value
)
=>
{
const
updateModel
=
(
name
,
field
,
value
)
=>
{
if
(
isNaN
(
value
))
{
showError
(
'请输入数字'
);
return
;
}
setModels
(
prev
=>
setModels
(
prev
=>
prev
.
map
(
model
=>
prev
.
map
(
model
=>
model
.
name
===
name
model
.
name
===
name
...
@@ -247,6 +259,7 @@ export default function ModelSettingsVisualEditor(props) {
...
@@ -247,6 +259,7 @@ export default function ModelSettingsVisualEditor(props) {
}}
}}
>
>
<
Form
>
<
Form
>
<
p
>
请输入固定价格或者模型倍率
+
补全倍率
<
/p
>
<
Form
.
Input
<
Form
.
Input
field
=
"name"
field
=
"name"
label
=
"模型名称"
label
=
"模型名称"
...
@@ -255,17 +268,20 @@ export default function ModelSettingsVisualEditor(props) {
...
@@ -255,17 +268,20 @@ export default function ModelSettingsVisualEditor(props) {
/
>
/
>
<
Form
.
Input
<
Form
.
Input
field
=
"price"
field
=
"price"
label
=
"固定价格"
label
=
"固定价格(每次)"
placeholder
=
"输入每次价格"
onChange
=
{
value
=>
setCurrentModel
(
prev
=>
({
...
prev
,
price
:
value
}))}
onChange
=
{
value
=>
setCurrentModel
(
prev
=>
({
...
prev
,
price
:
value
}))}
/
>
/
>
<
Form
.
Input
<
Form
.
Input
field
=
"ratio"
field
=
"ratio"
label
=
"模型倍率"
label
=
"模型倍率"
placeholder
=
"输入模型倍率"
onChange
=
{
value
=>
setCurrentModel
(
prev
=>
({
...
prev
,
ratio
:
value
}))}
onChange
=
{
value
=>
setCurrentModel
(
prev
=>
({
...
prev
,
ratio
:
value
}))}
/
>
/
>
<
Form
.
Input
<
Form
.
Input
field
=
"completionRatio"
field
=
"completionRatio"
label
=
"补全倍率"
label
=
"补全倍率"
placeholder
=
"输入补全价格"
onChange
=
{
value
=>
setCurrentModel
(
prev
=>
({
...
prev
,
completionRatio
:
value
}))}
onChange
=
{
value
=>
setCurrentModel
(
prev
=>
({
...
prev
,
completionRatio
:
value
}))}
/
>
/
>
<
/Form
>
<
/Form
>
...
...
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