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