()
| 32 | const { t } = useTranslation(); |
| 33 | |
| 34 | async function onSubmit() { |
| 35 | try { |
| 36 | await refForm.current |
| 37 | .validate() |
| 38 | .then(() => { |
| 39 | const updateArray = compareObjects(inputs, inputsRow); |
| 40 | if (!updateArray.length) |
| 41 | return showWarning(t('你似乎并没有修改什么')); |
| 42 | |
| 43 | const requestQueue = updateArray.map((item) => { |
| 44 | const value = |
| 45 | typeof inputs[item.key] === 'boolean' |
| 46 | ? String(inputs[item.key]) |
| 47 | : inputs[item.key]; |
| 48 | return API.put('/api/option/', { key: item.key, value }); |
| 49 | }); |
| 50 | |
| 51 | setLoading(true); |
| 52 | Promise.all(requestQueue) |
| 53 | .then((res) => { |
| 54 | if (res.includes(undefined)) { |
| 55 | return showError( |
| 56 | requestQueue.length > 1 |
| 57 | ? t('部分保存失败,请重试') |
| 58 | : t('保存失败'), |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | for (let i = 0; i < res.length; i++) { |
| 63 | if (!res[i].data.success) { |
| 64 | return showError(res[i].data.message); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | showSuccess(t('保存成功')); |
| 69 | props.refresh(); |
| 70 | }) |
| 71 | .catch((error) => { |
| 72 | console.error('Unexpected error:', error); |
| 73 | showError(t('保存失败,请重试')); |
| 74 | }) |
| 75 | .finally(() => { |
| 76 | setLoading(false); |
| 77 | }); |
| 78 | }) |
| 79 | .catch(() => { |
| 80 | showError(t('请检查输入')); |
| 81 | }); |
| 82 | } catch (error) { |
| 83 | showError(t('请检查输入')); |
| 84 | console.error(error); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | async function resetModelRatio() { |
| 89 | try { |
nothing calls this directly
no test coverage detected