()
| 41 | const [inputsRow, setInputsRow] = useState(inputs); |
| 42 | |
| 43 | function onSubmit() { |
| 44 | const updateArray = compareObjects(inputs, inputsRow); |
| 45 | if (!updateArray.length) return showWarning(t('你似乎并没有修改什么')); |
| 46 | const requestQueue = updateArray.map((item) => { |
| 47 | let value = String(inputs[item.key]); |
| 48 | |
| 49 | return API.put('/api/option/', { |
| 50 | key: item.key, |
| 51 | value, |
| 52 | }); |
| 53 | }); |
| 54 | setLoading(true); |
| 55 | Promise.all(requestQueue) |
| 56 | .then((res) => { |
| 57 | if (requestQueue.length === 1) { |
| 58 | if (res.includes(undefined)) return; |
| 59 | } else if (requestQueue.length > 1) { |
| 60 | if (res.includes(undefined)) |
| 61 | return showError(t('部分保存失败,请重试')); |
| 62 | } |
| 63 | showSuccess(t('保存成功')); |
| 64 | props.refresh(); |
| 65 | }) |
| 66 | .catch(() => { |
| 67 | showError(t('保存失败,请重试')); |
| 68 | }) |
| 69 | .finally(() => { |
| 70 | setLoading(false); |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | useEffect(() => { |
| 75 | const currentInputs = {}; |
nothing calls this directly
no test coverage detected