()
| 120 | const pagedData = getPagedData(filteredModels, currentPage, pageSize); |
| 121 | |
| 122 | const SubmitData = async () => { |
| 123 | setLoading(true); |
| 124 | const output = { |
| 125 | ModelPrice: JSON.parse(props.options.ModelPrice || '{}'), |
| 126 | ModelRatio: JSON.parse(props.options.ModelRatio || '{}'), |
| 127 | CompletionRatio: JSON.parse(props.options.CompletionRatio || '{}'), |
| 128 | }; |
| 129 | |
| 130 | try { |
| 131 | // 数据转换 - 只处理已修改的模型 |
| 132 | models.forEach((model) => { |
| 133 | // 只有当用户设置了值时才更新 |
| 134 | if (model.price !== '') { |
| 135 | // 如果价格不为空,则转换为浮点数,忽略倍率参数 |
| 136 | output.ModelPrice[model.name] = parseFloat(model.price); |
| 137 | } else { |
| 138 | if (model.ratio !== '') |
| 139 | output.ModelRatio[model.name] = parseFloat(model.ratio); |
| 140 | if (model.completionRatio !== '') |
| 141 | output.CompletionRatio[model.name] = parseFloat( |
| 142 | model.completionRatio, |
| 143 | ); |
| 144 | } |
| 145 | }); |
| 146 | |
| 147 | // 准备API请求数组 |
| 148 | const finalOutput = { |
| 149 | ModelPrice: JSON.stringify(output.ModelPrice, null, 2), |
| 150 | ModelRatio: JSON.stringify(output.ModelRatio, null, 2), |
| 151 | CompletionRatio: JSON.stringify(output.CompletionRatio, null, 2), |
| 152 | }; |
| 153 | |
| 154 | const requestQueue = Object.entries(finalOutput).map(([key, value]) => { |
| 155 | return API.put('/api/option/', { |
| 156 | key, |
| 157 | value, |
| 158 | }); |
| 159 | }); |
| 160 | |
| 161 | // 批量处理请求 |
| 162 | const results = await Promise.all(requestQueue); |
| 163 | |
| 164 | // 验证结果 |
| 165 | if (requestQueue.length === 1) { |
| 166 | if (results.includes(undefined)) return; |
| 167 | } else if (requestQueue.length > 1) { |
| 168 | if (results.includes(undefined)) { |
| 169 | return showError(t('部分保存失败,请重试')); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // 检查每个请求的结果 |
| 174 | for (const res of results) { |
| 175 | if (!res.data.success) { |
| 176 | return showError(res.data.message); |
| 177 | } |
| 178 | } |
| 179 |
nothing calls this directly
no test coverage detected