ratio must gte 0
This commit is contained in:
@@ -20,14 +20,8 @@ func GroupRatio2JSONString() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UpdateGroupRatioByJSONString(jsonStr string) error {
|
func UpdateGroupRatioByJSONString(jsonStr string) error {
|
||||||
tempGroupRatio := make(map[string]float64)
|
GroupRatio = make(map[string]float64)
|
||||||
err := json.Unmarshal([]byte(jsonStr), &tempGroupRatio)
|
return json.Unmarshal([]byte(jsonStr), &GroupRatio)
|
||||||
err = checkGroupRatio(tempGroupRatio)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
GroupRatio = tempGroupRatio
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupRatio(name string) float64 {
|
func GetGroupRatio(name string) float64 {
|
||||||
@@ -39,7 +33,12 @@ func GetGroupRatio(name string) float64 {
|
|||||||
return ratio
|
return ratio
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkGroupRatio(checkGroupRatio map[string]float64) error {
|
func CheckGroupRatio(jsonStr string) error {
|
||||||
|
checkGroupRatio := make(map[string]float64)
|
||||||
|
err := json.Unmarshal([]byte(jsonStr), &GroupRatio)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for name, ratio := range checkGroupRatio {
|
for name, ratio := range checkGroupRatio {
|
||||||
if ratio < 0 {
|
if ratio < 0 {
|
||||||
return errors.New("group ratio must be greater than 0: " + name)
|
return errors.New("group ratio must be greater than 0: " + name)
|
||||||
|
|||||||
@@ -74,6 +74,15 @@ func UpdateOption(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
case "GroupRatio":
|
||||||
|
err = common.CheckGroupRatio(option.Value)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = model.UpdateOption(option.Key, option.Value)
|
err = model.UpdateOption(option.Key, option.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ export default function SettingsMagnification(props) {
|
|||||||
if (res.includes(undefined))
|
if (res.includes(undefined))
|
||||||
return showError('部分保存失败,请重试');
|
return showError('部分保存失败,请重试');
|
||||||
}
|
}
|
||||||
|
for (let i = 0; i < res.length; i++) {
|
||||||
|
if (!res[i].success) {
|
||||||
|
return showError(res[i].message)
|
||||||
|
}
|
||||||
|
}
|
||||||
showSuccess('保存成功');
|
showSuccess('保存成功');
|
||||||
props.refresh();
|
props.refresh();
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user