fix: fix option update logic not working properly

This commit is contained in:
JustSong
2023-05-16 10:04:39 +08:00
parent a5406c6963
commit c48327ff91
4 changed files with 25 additions and 9 deletions

View File

@@ -12,7 +12,6 @@ const OtherSetting = () => {
Logo: '',
HomePageContent: '',
});
let originInputs = {};
let [loading, setLoading] = useState(false);
const [showUpdateModal, setShowUpdateModal] = useState(false);
const [updateData, setUpdateData] = useState({
@@ -21,7 +20,7 @@ const OtherSetting = () => {
});
const getOptions = async () => {
const res = await API.get('/api/option');
const res = await API.get('/api/option/');
const { success, message, data } = res.data;
if (success) {
let newInputs = {};
@@ -31,7 +30,6 @@ const OtherSetting = () => {
}
});
setInputs(newInputs);
originInputs = newInputs;
} else {
showError(message);
}
@@ -43,7 +41,7 @@ const OtherSetting = () => {
const updateOption = async (key, value) => {
setLoading(true);
const res = await API.put('/api/option', {
const res = await API.put('/api/option/', {
key,
value,
});

View File

@@ -27,16 +27,17 @@ const SystemSetting = () => {
TurnstileSecretKey: '',
RegisterEnabled: '',
QuotaForNewUser: 0,
QuotaRemindThreshold: 0,
ModelRatio: '',
TopUpLink: '',
AutomaticDisableChannelEnabled: '',
ChannelDisableThreshold: 0,
});
let originInputs = {};
const [originInputs, setOriginInputs] = useState({});
let [loading, setLoading] = useState(false);
const getOptions = async () => {
const res = await API.get('/api/option');
const res = await API.get('/api/option/');
const { success, message, data } = res.data;
if (success) {
let newInputs = {};
@@ -44,7 +45,7 @@ const SystemSetting = () => {
newInputs[item.key] = item.value;
});
setInputs(newInputs);
originInputs = newInputs;
setOriginInputs(newInputs);
} else {
showError(message);
}
@@ -70,7 +71,7 @@ const SystemSetting = () => {
default:
break;
}
const res = await API.put('/api/option', {
const res = await API.put('/api/option/', {
key,
value
});
@@ -96,6 +97,7 @@ const SystemSetting = () => {
name === 'TurnstileSiteKey' ||
name === 'TurnstileSecretKey' ||
name === 'QuotaForNewUser' ||
name === 'QuotaRemindThreshold' ||
name === 'ModelRatio' ||
name === 'TopUpLink'
) {
@@ -114,6 +116,9 @@ const SystemSetting = () => {
if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) {
await updateOption('QuotaForNewUser', inputs.QuotaForNewUser);
}
if (originInputs['QuotaRemindThreshold'] !== inputs.QuotaRemindThreshold) {
await updateOption('QuotaRemindThreshold', inputs.QuotaRemindThreshold);
}
if (originInputs['ModelRatio'] !== inputs.ModelRatio) {
if (!verifyJSON(inputs.ModelRatio)) {
showError('模型倍率不是合法的 JSON 字符串');
@@ -287,6 +292,16 @@ const SystemSetting = () => {
type='link'
placeholder='例如发卡网站的购买链接'
/>
<Form.Input
label='额度提醒阈值'
name='QuotaRemindThreshold'
onChange={handleInputChange}
autoComplete='new-password'
value={inputs.QuotaRemindThreshold}
type='number'
min='0'
placeholder='低于此额度时将发送邮件提醒用户'
/>
</Form.Group>
<Form.Group widths='equal'>
<Form.TextArea