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