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