()
| 23 | const [inputsRow, setInputsRow] = useState(inputs); |
| 24 | |
| 25 | function onSubmit() { |
| 26 | const updateArray = compareObjects(inputs, inputsRow); |
| 27 | if (!updateArray.length) return showWarning(t('你似乎并没有修改什么')); |
| 28 | const requestQueue = updateArray.map((item) => { |
| 29 | let value = String(inputs[item.key]); |
| 30 | |
| 31 | return API.put('/api/option/', { |
| 32 | key: item.key, |
| 33 | value, |
| 34 | }); |
| 35 | }); |
| 36 | setLoading(true); |
| 37 | Promise.all(requestQueue) |
| 38 | .then((res) => { |
| 39 | if (requestQueue.length === 1) { |
| 40 | if (res.includes(undefined)) return; |
| 41 | } else if (requestQueue.length > 1) { |
| 42 | if (res.includes(undefined)) |
| 43 | return showError(t('部分保存失败,请重试')); |
| 44 | } |
| 45 | showSuccess(t('保存成功')); |
| 46 | props.refresh(); |
| 47 | }) |
| 48 | .catch(() => { |
| 49 | showError(t('保存失败,请重试')); |
| 50 | }) |
| 51 | .finally(() => { |
| 52 | setLoading(false); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | useEffect(() => { |
| 57 | const currentInputs = {}; |
nothing calls this directly
no test coverage detected