From 83dd62982ec4000bc8881cc6f718e7c0a0ffb41e Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Wed, 8 May 2024 14:57:36 +0800 Subject: [PATCH 01/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E9=80=9A=E7=94=A8=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/OperationSetting.js | 728 ++++++++---------- web/src/helpers/utils.js | 25 + .../Setting/Operation/GeneralSettings.js | 198 +++++ 3 files changed, 561 insertions(+), 390 deletions(-) create mode 100644 web/src/pages/Setting/Operation/GeneralSettings.js diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index 7566faa..ecf3d77 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -1,5 +1,7 @@ import React, { useEffect, useState } from 'react'; import { Divider, Form, Grid, Header } from 'semantic-ui-react'; +import { Card } from '@douyinfe/semi-ui'; +import GeneralSettings from '../pages/Setting/Operation/GeneralSettings.js'; import { API, showError, @@ -30,8 +32,8 @@ const OperationSetting = () => { AutomaticEnableChannelEnabled: '', ChannelDisableThreshold: 0, LogConsumeEnabled: '', - DisplayInCurrencyEnabled: '', - DisplayTokenStatEnabled: '', + DisplayInCurrencyEnabled: false, + DisplayTokenStatEnabled: false, CheckSensitiveEnabled: '', CheckSensitiveOnPromptEnabled: '', CheckSensitiveOnCompletionEnabled: '', @@ -45,7 +47,7 @@ const OperationSetting = () => { DataExportEnabled: '', DataExportDefaultTime: 'hour', DataExportInterval: 5, - DefaultCollapseSidebar: '', // 默认折叠侧边栏 + DefaultCollapseSidebar: false, // 默认折叠侧边栏 RetryTimes: 0, }); const [originInputs, setOriginInputs] = useState({}); @@ -72,8 +74,16 @@ const OperationSetting = () => { ) { item.value = JSON.stringify(JSON.parse(item.value), null, 2); } - newInputs[item.key] = item.value; + if ( + item.key.endsWith('Enabled') || + ['DefaultCollapseSidebar'].includes(item.key) + ) { + newInputs[item.key] = item.value === 'true' ? true : false; + } else { + newInputs[item.key] = item.value; + } }); + setInputs(newInputs); setOriginInputs(newInputs); } else { @@ -224,396 +234,334 @@ const OperationSetting = () => { showError('日志清理失败:' + message); }; return ( - - -
-
- 通用设置 -
- - - - - - - - - - - - - { - submitConfig('general').then(); - }} - > - 保存通用设置 - - -
- 绘图设置 -
- - - - - - - - -
- 屏蔽词过滤设置 -
- - - - - - {/**/} - - {/**/} - {/* */} - {/**/} - {/**/} - {/* */} - {/**/} - - - - { - submitConfig('words').then(); - }} - > - 保存屏蔽词设置 - - -
- 日志设置 -
- - - - - { - setHistoryTimestamp(value); + <> + + {/* 通用设置 */} + + + + + + +
+ 绘图设置 +
+ + + + + + + + +
+ 屏蔽词过滤设置 +
+ + + + + + {/**/} + + {/**/} + {/* */} + {/**/} + {/**/} + {/* */} + {/**/} + + + + { + submitConfig('words').then(); }} - /> -
- { - deleteHistoryLogs().then(); - }} - > - 清理历史日志 - - -
- 数据看板 -
- - - - - - -
- 监控设置 -
- - - - - + > + 保存屏蔽词设置 + + +
+ 日志设置 +
+ + + + + { + setHistoryTimestamp(value); + }} + /> + + { + deleteHistoryLogs().then(); + }} + > + 清理历史日志 + + +
+ 数据看板 +
- -
- { - submitConfig('monitor').then(); - }} - > - 保存监控设置 - - -
- 额度设置 -
- - - - - - - { - submitConfig('quota').then(); - }} - > - 保存额度设置 - - -
- 倍率设置 -
- - - - - - - - - - { - submitConfig('ratio').then(); - }} - > - 保存倍率设置 - - -
-
+ + + + + +
+ 监控设置 +
+ + + + + + + + + { + submitConfig('monitor').then(); + }} + > + 保存监控设置 + + +
+ 额度设置 +
+ + + + + + + { + submitConfig('quota').then(); + }} + > + 保存额度设置 + + +
+ 倍率设置 +
+ + + + + + + + + + { + submitConfig('ratio').then(); + }} + > + 保存倍率设置 + + + + + ); }; diff --git a/web/src/helpers/utils.js b/web/src/helpers/utils.js index 78fa3d6..0ca3476 100644 --- a/web/src/helpers/utils.js +++ b/web/src/helpers/utils.js @@ -220,3 +220,28 @@ export function shouldShowPrompt(id) { export function setPromptShown(id) { localStorage.setItem(`prompt-${id}`, 'true'); } + +/** + * 比较两个对象的属性,找出有变化的属性,并返回包含变化属性信息的数组 + * @param {Object} oldObject - 旧对象 + * @param {Object} newObject - 新对象 + * @return {Array} 包含变化属性信息的数组,每个元素是一个对象,包含 key, oldValue 和 newValue + */ +export function compareObjects(oldObject, newObject) { + const changedProperties = []; + + // 比较两个对象的属性 + for (const key in oldObject) { + if (oldObject.hasOwnProperty(key) && newObject.hasOwnProperty(key)) { + if (oldObject[key] !== newObject[key]) { + changedProperties.push({ + key: key, + oldValue: oldObject[key], + newValue: newObject[key], + }); + } + } + } + + return changedProperties; +} diff --git a/web/src/pages/Setting/Operation/GeneralSettings.js b/web/src/pages/Setting/Operation/GeneralSettings.js new file mode 100644 index 0000000..6805a3b --- /dev/null +++ b/web/src/pages/Setting/Operation/GeneralSettings.js @@ -0,0 +1,198 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { Button, Col, Form, Row, Spin } from '@douyinfe/semi-ui'; +import { + compareObjects, + API, + showError, + showSuccess, + showWarning, +} from '../../../helpers'; + +export default function GeneralSettings(props) { + const [loading, setLoading] = useState(false); + const [inputs, setInputs] = useState({ + TopUpLink: '', + ChatLink: '', + ChatLink2: '', + QuotaPerUnit: '', + RetryTimes: '', + DisplayInCurrencyEnabled: false, + DisplayTokenStatEnabled: false, + DefaultCollapseSidebar: false, + }); + const refForm = useRef(); + const [inputsRow, setInputsRow] = useState(inputs); + function onChange(value, e) { + const name = e.target.id; + setInputs((inputs) => ({ ...inputs, [name]: value })); + } + function onSubmit() { + const updateArray = compareObjects(inputs, inputsRow); + if (!updateArray.length) return showWarning('你似乎并没有修改什么'); + const requestQueue = updateArray.map((item) => { + let value = ''; + if (typeof inputs[item.key] === 'boolean') { + value = String(inputs[item.key]); + } else { + value = inputs[item.key]; + } + return API.put('/api/option/', { + key: item.key, + value, + }); + }); + setLoading(true); + Promise.all(requestQueue) + .then((res) => { + if (requestQueue.length === 1) { + if (res.includes(undefined)) return; + } else if (requestQueue.length > 1) { + if (res.includes(undefined)) return showError('部分更新失败'); + } + showSuccess('更新成功'); + }) + .catch(() => { + showError('更新失败'); + }) + .finally(() => { + setLoading(false); + setInputsRow(structuredClone(inputs)); + }); + } + + useEffect(() => { + const currentInputs = {}; + for (let key in props.options) { + if (Object.keys(inputs).includes(key)) { + currentInputs[key] = props.options[key]; + } + } + setInputs(currentInputs); + setInputsRow(structuredClone(currentInputs)); + refForm.current.setValues(currentInputs); + }, [props.options]); + return ( + <> + +
(refForm.current = formAPI)} + style={{ marginBottom: 15 }} + > + + + + + + + + + + + + + + + + + + + + + { + setInputs({ + ...inputs, + DisplayInCurrencyEnabled: value, + }); + }} + /> + + + + setInputs({ + ...inputs, + DisplayTokenStatEnabled: value, + }) + } + /> + + + + setInputs({ + ...inputs, + DefaultCollapseSidebar: value, + }) + } + /> + + + + + + +
+
+ + ); +} From 9886cdd52741922b555d92d51d6b7df133a9827d Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Thu, 9 May 2024 17:20:51 +0800 Subject: [PATCH 02/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E7=BB=98=E5=9B=BE=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/OperationSetting.js | 44 +---- .../Setting/Operation/DrawingSettings.js | 179 ++++++++++++++++++ 2 files changed, 185 insertions(+), 38 deletions(-) create mode 100644 web/src/pages/Setting/Operation/DrawingSettings.js diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index ecf3d77..829e981 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react'; import { Divider, Form, Grid, Header } from 'semantic-ui-react'; import { Card } from '@douyinfe/semi-ui'; import GeneralSettings from '../pages/Setting/Operation/GeneralSettings.js'; +import DrawingSettings from '../pages/Setting/Operation/DrawingSettings.js'; import { API, showError, @@ -235,50 +236,17 @@ const OperationSetting = () => { }; return ( <> + {/* 通用设置 */} - {/* 通用设置 */} + {/* 绘图设置 */} + + +
- -
- 绘图设置 -
- - - - - - - -
屏蔽词过滤设置
diff --git a/web/src/pages/Setting/Operation/DrawingSettings.js b/web/src/pages/Setting/Operation/DrawingSettings.js new file mode 100644 index 0000000..46187f0 --- /dev/null +++ b/web/src/pages/Setting/Operation/DrawingSettings.js @@ -0,0 +1,179 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { Button, Col, Form, Row, Spin, Tag } from '@douyinfe/semi-ui'; +import { + compareObjects, + API, + showError, + showSuccess, + showWarning, +} from '../../../helpers'; + +export default function GeneralSettings(props) { + const [loading, setLoading] = useState(false); + const [inputs, setInputs] = useState({ + DrawingEnabled: false, + MjNotifyEnabled: false, + MjAccountFilterEnabled: false, + MjForwardUrlEnabled: false, + MjModeClearEnabled: false, + }); + const refForm = useRef(); + const [inputsRow, setInputsRow] = useState(inputs); + + function onSubmit() { + const updateArray = compareObjects(inputs, inputsRow); + if (!updateArray.length) return showWarning('你似乎并没有修改什么'); + const requestQueue = updateArray.map((item) => { + let value = ''; + if (typeof inputs[item.key] === 'boolean') { + value = String(inputs[item.key]); + } else { + value = inputs[item.key]; + } + return API.put('/api/option/', { + key: item.key, + value, + }); + }); + setLoading(true); + Promise.all(requestQueue) + .then((res) => { + if (requestQueue.length === 1) { + if (res.includes(undefined)) return; + } else if (requestQueue.length > 1) { + if (res.includes(undefined)) return showError('部分更新失败'); + } + showSuccess('更新成功'); + }) + .catch(() => { + showError('更新失败'); + }) + .finally(() => { + setLoading(false); + setInputsRow(structuredClone(inputs)); + }); + } + + useEffect(() => { + const currentInputs = {}; + for (let key in props.options) { + if (Object.keys(inputs).includes(key)) { + currentInputs[key] = props.options[key]; + } + } + setInputs(currentInputs); + setInputsRow(structuredClone(currentInputs)); + refForm.current.setValues(currentInputs); + }, [props.options]); + return ( + <> + + (refForm.current = formAPI)} + style={{ marginBottom: 15 }} + > + + + + { + setInputs({ + ...inputs, + DrawingEnabled: value, + }); + }} + /> + + + + setInputs({ + ...inputs, + MjNotifyEnabled: value, + }) + } + /> + + + + setInputs({ + ...inputs, + MjAccountFilterEnabled: value, + }) + } + /> + + + + setInputs({ + ...inputs, + MjForwardUrlEnabled: value, + }) + } + /> + + + + 开启之后会清除用户提示词中的 --fast 、 + --relax 以及 --turbo 参数 + + } + size='large' + checkedText='|' + uncheckedText='〇' + defaultChecked={false} + checked={false} + onChange={(value) => + setInputs({ + ...inputs, + MjModeClearEnabled: value, + }) + } + /> + + + + + + + + + + ); +} From 96468ce64f299e53f9f84057f63125ced9f3843f Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Fri, 10 May 2024 16:17:48 +0800 Subject: [PATCH 03/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E5=B1=8F=E8=94=BD=E8=AF=8D=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/OperationSetting.js | 61 ++------ ...{DrawingSettings.js => SettingsDrawing.js} | 2 +- ...{GeneralSettings.js => SettingsGeneral.js} | 0 .../Operation/SettingsSensitiveWords.js | 139 ++++++++++++++++++ 4 files changed, 151 insertions(+), 51 deletions(-) rename web/src/pages/Setting/Operation/{DrawingSettings.js => SettingsDrawing.js} (99%) rename web/src/pages/Setting/Operation/{GeneralSettings.js => SettingsGeneral.js} (100%) create mode 100644 web/src/pages/Setting/Operation/SettingsSensitiveWords.js diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index 829e981..3da0dcc 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -1,8 +1,10 @@ import React, { useEffect, useState } from 'react'; import { Divider, Form, Grid, Header } from 'semantic-ui-react'; import { Card } from '@douyinfe/semi-ui'; -import GeneralSettings from '../pages/Setting/Operation/GeneralSettings.js'; -import DrawingSettings from '../pages/Setting/Operation/DrawingSettings.js'; +import SettingsGeneral from '../pages/Setting/Operation/SettingsGeneral.js'; +import SettingsDrawing from '../pages/Setting/Operation/SettingsDrawing.js'; +import SettingsSensitiveWords from '../pages/Setting/Operation/SettingsSensitiveWords.js'; + import { API, showError, @@ -238,40 +240,19 @@ const OperationSetting = () => { <> {/* 通用设置 */} - + {/* 绘图设置 */} - + + + {/* 屏蔽词过滤设置 */} + +
-
- 屏蔽词过滤设置 -
- - - - - - {/**/} - {/**/} {/* { {/* placeholder="例如:10"*/} {/* />*/} {/**/} - - - - { - submitConfig('words').then(); - }} - > - 保存屏蔽词设置 - - +
日志设置
diff --git a/web/src/pages/Setting/Operation/DrawingSettings.js b/web/src/pages/Setting/Operation/SettingsDrawing.js similarity index 99% rename from web/src/pages/Setting/Operation/DrawingSettings.js rename to web/src/pages/Setting/Operation/SettingsDrawing.js index 46187f0..4815d2f 100644 --- a/web/src/pages/Setting/Operation/DrawingSettings.js +++ b/web/src/pages/Setting/Operation/SettingsDrawing.js @@ -8,7 +8,7 @@ import { showWarning, } from '../../../helpers'; -export default function GeneralSettings(props) { +export default function SettingsDrawing(props) { const [loading, setLoading] = useState(false); const [inputs, setInputs] = useState({ DrawingEnabled: false, diff --git a/web/src/pages/Setting/Operation/GeneralSettings.js b/web/src/pages/Setting/Operation/SettingsGeneral.js similarity index 100% rename from web/src/pages/Setting/Operation/GeneralSettings.js rename to web/src/pages/Setting/Operation/SettingsGeneral.js diff --git a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js new file mode 100644 index 0000000..3a2a4cd --- /dev/null +++ b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js @@ -0,0 +1,139 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { Button, Col, Form, Row, Spin, Tag } from '@douyinfe/semi-ui'; +import { + compareObjects, + API, + showError, + showSuccess, + showWarning, +} from '../../../helpers'; + +export default function SettingsSensitiveWords(props) { + const [loading, setLoading] = useState(false); + const [inputs, setInputs] = useState({ + CheckSensitiveEnabled: false, + CheckSensitiveOnPromptEnabled: false, + SensitiveWords: '', + }); + const refForm = useRef(); + const [inputsRow, setInputsRow] = useState(inputs); + + function onSubmit() { + const updateArray = compareObjects(inputs, inputsRow); + if (!updateArray.length) return showWarning('你似乎并没有修改什么'); + const requestQueue = updateArray.map((item) => { + let value = ''; + if (typeof inputs[item.key] === 'boolean') { + value = String(inputs[item.key]); + } else { + value = inputs[item.key]; + } + return API.put('/api/option/', { + key: item.key, + value, + }); + }); + setLoading(true); + Promise.all(requestQueue) + .then((res) => { + if (requestQueue.length === 1) { + if (res.includes(undefined)) return; + } else if (requestQueue.length > 1) { + if (res.includes(undefined)) return showError('部分更新失败'); + } + showSuccess('更新成功'); + }) + .catch(() => { + showError('更新失败'); + }) + .finally(() => { + setLoading(false); + setInputsRow(structuredClone(inputs)); + }); + } + + useEffect(() => { + const currentInputs = {}; + for (let key in props.options) { + if (Object.keys(inputs).includes(key)) { + currentInputs[key] = props.options[key]; + } + } + setInputs(currentInputs); + setInputsRow(structuredClone(currentInputs)); + refForm.current.setValues(currentInputs); + }, [props.options]); + return ( + <> + + (refForm.current = formAPI)} + style={{ marginBottom: 15 }} + > + + + + { + setInputs({ + ...inputs, + CheckSensitiveEnabled: value, + }); + }} + /> + + + + setInputs({ + ...inputs, + CheckSensitiveOnPromptEnabled: value, + }) + } + /> + + + + + + setInputs({ + ...inputs, + SensitiveWords: value, + }) + } + style={{ fontFamily: 'JetBrains Mono, Consolas' }} + autosize={{ minRows: 6, maxRows: 12 }} + /> + + + + + + + + + + ); +} From 003745abcbb901704f50c6a7c553ef5d5ce7e79e Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Sat, 11 May 2024 14:06:32 +0800 Subject: [PATCH 04/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E6=97=A5=E5=BF=97=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/package.json | 3 +- web/src/components/OperationSetting.js | 64 ++------ .../pages/Setting/Operation/SettingsLog.js | 150 ++++++++++++++++++ 3 files changed, 165 insertions(+), 52 deletions(-) create mode 100644 web/src/pages/Setting/Operation/SettingsLog.js diff --git a/web/package.json b/web/package.json index 4f9eced..e814d65 100644 --- a/web/package.json +++ b/web/package.json @@ -5,11 +5,12 @@ "type": "module", "dependencies": { "@douyinfe/semi-icons": "^2.46.1", - "@douyinfe/semi-ui": "^2.46.1", + "@douyinfe/semi-ui": "^2.55.3", "@visactor/react-vchart": "~1.8.8", "@visactor/vchart": "~1.8.8", "@visactor/vchart-semi-theme": "~1.8.8", "axios": "^0.27.2", + "dayjs": "^1.11.11", "history": "^5.3.0", "marked": "^4.1.1", "react": "^18.2.0", diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index 3da0dcc..6835e1a 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -4,6 +4,7 @@ import { Card } from '@douyinfe/semi-ui'; import SettingsGeneral from '../pages/Setting/Operation/SettingsGeneral.js'; import SettingsDrawing from '../pages/Setting/Operation/SettingsDrawing.js'; import SettingsSensitiveWords from '../pages/Setting/Operation/SettingsSensitiveWords.js'; +import SettingsLog from '../pages/Setting/Operation/SettingsLog.js'; import { API, @@ -34,19 +35,19 @@ const OperationSetting = () => { AutomaticDisableChannelEnabled: '', AutomaticEnableChannelEnabled: '', ChannelDisableThreshold: 0, - LogConsumeEnabled: '', + LogConsumeEnabled: false, DisplayInCurrencyEnabled: false, DisplayTokenStatEnabled: false, - CheckSensitiveEnabled: '', - CheckSensitiveOnPromptEnabled: '', + CheckSensitiveEnabled: false, + CheckSensitiveOnPromptEnabled: false, CheckSensitiveOnCompletionEnabled: '', StopOnSensitiveEnabled: '', SensitiveWords: '', - MjNotifyEnabled: '', - MjAccountFilterEnabled: '', - MjModeClearEnabled: '', - MjForwardUrlEnabled: '', - DrawingEnabled: '', + MjNotifyEnabled: false, + MjAccountFilterEnabled: false, + MjModeClearEnabled: false, + MjForwardUrlEnabled: false, + DrawingEnabled: false, DataExportEnabled: '', DataExportDefaultTime: 'hour', DataExportInterval: 5, @@ -223,19 +224,6 @@ const OperationSetting = () => { break; } }; - - const deleteHistoryLogs = async () => { - console.log(inputs); - const res = await API.delete( - `/api/log/?target_timestamp=${Date.parse(historyTimestamp) / 1000}`, - ); - const { success, message, data } = res.data; - if (success) { - showSuccess(`${data} 条日志已清理!`); - return; - } - showError('日志清理失败:' + message); - }; return ( <> {/* 通用设置 */} @@ -250,6 +238,10 @@ const OperationSetting = () => { + {/* 日志设置 */} + + +
@@ -273,36 +265,6 @@ const OperationSetting = () => { {/* />*/} {/**/} -
- 日志设置 -
- - - - - { - setHistoryTimestamp(value); - }} - /> - - { - deleteHistoryLogs().then(); - }} - > - 清理历史日志 - -
数据看板
diff --git a/web/src/pages/Setting/Operation/SettingsLog.js b/web/src/pages/Setting/Operation/SettingsLog.js new file mode 100644 index 0000000..77120ea --- /dev/null +++ b/web/src/pages/Setting/Operation/SettingsLog.js @@ -0,0 +1,150 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { Button, Col, Form, Row, Spin, DatePicker } from '@douyinfe/semi-ui'; +import dayjs from 'dayjs'; +import { + compareObjects, + API, + showError, + showSuccess, + showWarning, +} from '../../../helpers'; + +export default function SettingsLog(props) { + const [loading, setLoading] = useState(false); + const [loadingCleanHistoryLog, setLoadingCleanHistoryLog] = useState(false); + const [inputs, setInputs] = useState({ + LogConsumeEnabled: false, + historyTimestamp: dayjs().subtract(1, 'month').toDate(), + }); + // const [historyTimestamp, setHistoryTimestamp] = useState( + // dayjs().subtract(1, 'month').toDate(), + // ); + const refForm = useRef(); + const [inputsRow, setInputsRow] = useState(inputs); + + function onSubmit() { + const updateArray = compareObjects(inputs, inputsRow).filter( + (item) => item.key !== 'historyTimestamp', + ); + + if (!updateArray.length) return showWarning('你似乎并没有修改什么'); + const requestQueue = updateArray.map((item) => { + let value = ''; + if (typeof inputs[item.key] === 'boolean') { + value = String(inputs[item.key]); + } else { + value = inputs[item.key]; + } + return API.put('/api/option/', { + key: item.key, + value, + }); + }); + setLoading(true); + Promise.all(requestQueue) + .then((res) => { + if (requestQueue.length === 1) { + if (res.includes(undefined)) return; + } else if (requestQueue.length > 1) { + if (res.includes(undefined)) return showError('部分更新失败'); + } + showSuccess('更新成功'); + }) + .catch(() => { + showError('更新失败'); + }) + .finally(() => { + setLoading(false); + setInputsRow(structuredClone(inputs)); + }); + } + async function onCleanHistoryLog() { + try { + setLoadingCleanHistoryLog(true); + if (!inputs.historyTimestamp) throw new Error('请选择日志记录时间'); + const res = await API.delete( + `/api/log/?target_timestamp=${Date.parse(inputs.historyTimestamp) / 1000}`, + ); + const { success, message, data } = res.data; + if (success) { + showSuccess(`${data} 条日志已清理!`); + return; + } else { + throw new Error('日志清理失败:' + message); + } + } catch (error) { + showError(error.message); + } finally { + setLoadingCleanHistoryLog(false); + } + } + + useEffect(() => { + const currentInputs = {}; + for (let key in props.options) { + if (Object.keys(inputs).includes(key)) { + currentInputs[key] = props.options[key]; + } + } + currentInputs['historyTimestamp'] = inputs.historyTimestamp; + setInputs(Object.assign(inputs, currentInputs)); + setInputsRow(structuredClone(currentInputs)); + refForm.current.setValues(currentInputs); + }, [props.options]); + return ( + <> + + (refForm.current = formAPI)} + style={{ marginBottom: 15 }} + > + + + + { + setInputs({ + ...inputs, + LogConsumeEnabled: value, + }); + }} + /> + + + + { + setInputs({ + ...inputs, + historyTimestamp: value, + }); + }} + /> + + + + + + + + + + + + + ); +} From a9d9877bce607e68166202319f155c088052e962 Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Sat, 11 May 2024 16:13:28 +0800 Subject: [PATCH 05/12] =?UTF-8?q?perf:=20=E7=A7=BB=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Setting/Operation/SettingsDrawing.js | 10 ---------- web/src/pages/Setting/Operation/SettingsGeneral.js | 6 ------ .../pages/Setting/Operation/SettingsSensitiveWords.js | 4 ---- 3 files changed, 20 deletions(-) diff --git a/web/src/pages/Setting/Operation/SettingsDrawing.js b/web/src/pages/Setting/Operation/SettingsDrawing.js index 4815d2f..085cfd1 100644 --- a/web/src/pages/Setting/Operation/SettingsDrawing.js +++ b/web/src/pages/Setting/Operation/SettingsDrawing.js @@ -82,8 +82,6 @@ export default function SettingsDrawing(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => { setInputs({ ...inputs, @@ -99,8 +97,6 @@ export default function SettingsDrawing(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => setInputs({ ...inputs, @@ -116,8 +112,6 @@ export default function SettingsDrawing(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => setInputs({ ...inputs, @@ -133,8 +127,6 @@ export default function SettingsDrawing(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => setInputs({ ...inputs, @@ -155,8 +147,6 @@ export default function SettingsDrawing(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => setInputs({ ...inputs, diff --git a/web/src/pages/Setting/Operation/SettingsGeneral.js b/web/src/pages/Setting/Operation/SettingsGeneral.js index 6805a3b..83fb7c8 100644 --- a/web/src/pages/Setting/Operation/SettingsGeneral.js +++ b/web/src/pages/Setting/Operation/SettingsGeneral.js @@ -140,8 +140,6 @@ export default function GeneralSettings(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => { setInputs({ ...inputs, @@ -157,8 +155,6 @@ export default function GeneralSettings(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => setInputs({ ...inputs, @@ -174,8 +170,6 @@ export default function GeneralSettings(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => setInputs({ ...inputs, diff --git a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js index 3a2a4cd..f251013 100644 --- a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js +++ b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js @@ -80,8 +80,6 @@ export default function SettingsSensitiveWords(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => { setInputs({ ...inputs, @@ -97,8 +95,6 @@ export default function SettingsSensitiveWords(props) { size='large' checkedText='|' uncheckedText='〇' - defaultChecked={false} - checked={false} onChange={(value) => setInputs({ ...inputs, From 76f6b41bb2f112e5df258140ba5316fa74539286 Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Sat, 11 May 2024 16:19:35 +0800 Subject: [PATCH 06/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E6=95=B0=E6=8D=AE=E7=9C=8B=E6=9D=BF=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/OperationSetting.js | 48 +----- .../Operation/SettingsDataDashboard.js | 147 ++++++++++++++++++ .../Setting/Operation/SettingsDrawing.js | 1 + 3 files changed, 155 insertions(+), 41 deletions(-) create mode 100644 web/src/pages/Setting/Operation/SettingsDataDashboard.js diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index 6835e1a..09acab0 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -5,6 +5,7 @@ import SettingsGeneral from '../pages/Setting/Operation/SettingsGeneral.js'; import SettingsDrawing from '../pages/Setting/Operation/SettingsDrawing.js'; import SettingsSensitiveWords from '../pages/Setting/Operation/SettingsSensitiveWords.js'; import SettingsLog from '../pages/Setting/Operation/SettingsLog.js'; +import SettingsDataDashboard from '../pages/Setting/Operation/SettingsDataDashboard.js'; import { API, @@ -48,7 +49,7 @@ const OperationSetting = () => { MjModeClearEnabled: false, MjForwardUrlEnabled: false, DrawingEnabled: false, - DataExportEnabled: '', + DataExportEnabled: false, DataExportDefaultTime: 'hour', DataExportInterval: 5, DefaultCollapseSidebar: false, // 默认折叠侧边栏 @@ -56,15 +57,7 @@ const OperationSetting = () => { }); const [originInputs, setOriginInputs] = useState({}); let [loading, setLoading] = useState(false); - let [historyTimestamp, setHistoryTimestamp] = useState( - timestamp2string(now.getTime() / 1000 - 30 * 24 * 3600), - ); // a month ago - // 精确时间选项(小时,天,周) - const timeOptions = [ - { key: 'hour', text: '小时', value: 'hour' }, - { key: 'day', text: '天', value: 'day' }, - { key: 'week', text: '周', value: 'week' }, - ]; + const getOptions = async () => { const res = await API.get('/api/option/'); const { success, message, data } = res.data; @@ -242,6 +235,10 @@ const OperationSetting = () => { + {/* 数据看板 */} + + +
@@ -265,37 +262,6 @@ const OperationSetting = () => { {/* />*/} {/**/} -
- 数据看板 -
- - - - -
监控设置 diff --git a/web/src/pages/Setting/Operation/SettingsDataDashboard.js b/web/src/pages/Setting/Operation/SettingsDataDashboard.js new file mode 100644 index 0000000..85fd1dc --- /dev/null +++ b/web/src/pages/Setting/Operation/SettingsDataDashboard.js @@ -0,0 +1,147 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { Button, Col, Form, Row, Spin, Tag } from '@douyinfe/semi-ui'; +import { + compareObjects, + API, + showError, + showSuccess, + showWarning, +} from '../../../helpers'; + +export default function DataDashboard(props) { + const optionsDataExportDefaultTime = [ + { key: 'hour', label: '小时', value: 'hour' }, + { key: 'day', label: '天', value: 'day' }, + { key: 'week', label: '周', value: 'week' }, + ]; + const [loading, setLoading] = useState(false); + const [inputs, setInputs] = useState({ + DataExportEnabled: false, + DataExportInterval: '', + DataExportDefaultTime: '', + }); + const refForm = useRef(); + const [inputsRow, setInputsRow] = useState(inputs); + + function onSubmit() { + const updateArray = compareObjects(inputs, inputsRow); + if (!updateArray.length) return showWarning('你似乎并没有修改什么'); + const requestQueue = updateArray.map((item) => { + let value = ''; + if (typeof inputs[item.key] === 'boolean') { + value = String(inputs[item.key]); + } else { + value = inputs[item.key]; + } + return API.put('/api/option/', { + key: item.key, + value, + }); + }); + setLoading(true); + Promise.all(requestQueue) + .then((res) => { + if (requestQueue.length === 1) { + if (res.includes(undefined)) return; + } else if (requestQueue.length > 1) { + if (res.includes(undefined)) return showError('部分更新失败'); + } + showSuccess('更新成功'); + }) + .catch(() => { + showError('更新失败'); + }) + .finally(() => { + setLoading(false); + setInputsRow(structuredClone(inputs)); + }); + } + + useEffect(() => { + const currentInputs = {}; + for (let key in props.options) { + if (Object.keys(inputs).includes(key)) { + currentInputs[key] = props.options[key]; + } + } + setInputs(currentInputs); + setInputsRow(structuredClone(currentInputs)); + refForm.current.setValues(currentInputs); + localStorage.setItem( + 'data_export_default_time', + String(inputs.DataExportDefaultTime), + ); + }, [props.options]); + + return ( + <> + + (refForm.current = formAPI)} + style={{ marginBottom: 15 }} + > + + + + { + setInputs({ + ...inputs, + DataExportEnabled: value, + }); + }} + /> + + + + + + setInputs({ + ...inputs, + DataExportInterval: String(value), + }) + } + /> + + + + setInputs({ + ...inputs, + DataExportDefaultTime: String(value), + }) + } + /> + + + + + + + + + + ); +} diff --git a/web/src/pages/Setting/Operation/SettingsDrawing.js b/web/src/pages/Setting/Operation/SettingsDrawing.js index 085cfd1..560bbc7 100644 --- a/web/src/pages/Setting/Operation/SettingsDrawing.js +++ b/web/src/pages/Setting/Operation/SettingsDrawing.js @@ -64,6 +64,7 @@ export default function SettingsDrawing(props) { setInputs(currentInputs); setInputsRow(structuredClone(currentInputs)); refForm.current.setValues(currentInputs); + localStorage.setItem('mj_notify_enabled', String(inputs.MjNotifyEnabled)); }, [props.options]); return ( <> From 88bc2958558f1e8baffd354aec106da24893e631 Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Sat, 11 May 2024 17:20:18 +0800 Subject: [PATCH 07/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E7=9B=91=E6=8E=A7=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/OperationSetting.js | 58 +------ .../Setting/Operation/SettingsMonitoring.js | 154 ++++++++++++++++++ 2 files changed, 162 insertions(+), 50 deletions(-) create mode 100644 web/src/pages/Setting/Operation/SettingsMonitoring.js diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index 09acab0..b9e8e9e 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -6,6 +6,7 @@ import SettingsDrawing from '../pages/Setting/Operation/SettingsDrawing.js'; import SettingsSensitiveWords from '../pages/Setting/Operation/SettingsSensitiveWords.js'; import SettingsLog from '../pages/Setting/Operation/SettingsLog.js'; import SettingsDataDashboard from '../pages/Setting/Operation/SettingsDataDashboard.js'; +import SettingsMonitoring from '../pages/Setting/Operation/SettingsMonitoring.js'; import { API, @@ -33,8 +34,8 @@ const OperationSetting = () => { ChatLink: '', ChatLink2: '', // 添加的新状态变量 QuotaPerUnit: 0, - AutomaticDisableChannelEnabled: '', - AutomaticEnableChannelEnabled: '', + AutomaticDisableChannelEnabled: false, + AutomaticEnableChannelEnabled: false, ChannelDisableThreshold: 0, LogConsumeEnabled: false, DisplayInCurrencyEnabled: false, @@ -220,7 +221,7 @@ const OperationSetting = () => { return ( <> {/* 通用设置 */} - + {/* 绘图设置 */} @@ -239,6 +240,10 @@ const OperationSetting = () => { + {/* 监控设置 */} + + +
@@ -262,53 +267,6 @@ const OperationSetting = () => { {/* />*/} {/**/} - -
- 监控设置 -
- - - - - - - - - { - submitConfig('monitor').then(); - }} - > - 保存监控设置 -
额度设置 diff --git a/web/src/pages/Setting/Operation/SettingsMonitoring.js b/web/src/pages/Setting/Operation/SettingsMonitoring.js new file mode 100644 index 0000000..6fed48f --- /dev/null +++ b/web/src/pages/Setting/Operation/SettingsMonitoring.js @@ -0,0 +1,154 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { Button, Col, Form, Row, Spin } from '@douyinfe/semi-ui'; +import { + compareObjects, + API, + showError, + showSuccess, + showWarning, +} from '../../../helpers'; + +export default function SettingsMonitoring(props) { + const [loading, setLoading] = useState(false); + const [inputs, setInputs] = useState({ + ChannelDisableThreshold: '', + QuotaRemindThreshold: '', + AutomaticDisableChannelEnabled: false, + AutomaticEnableChannelEnabled: false, + }); + const refForm = useRef(); + const [inputsRow, setInputsRow] = useState(inputs); + + function onSubmit() { + const updateArray = compareObjects(inputs, inputsRow); + if (!updateArray.length) return showWarning('你似乎并没有修改什么'); + const requestQueue = updateArray.map((item) => { + let value = ''; + if (typeof inputs[item.key] === 'boolean') { + value = String(inputs[item.key]); + } else { + value = inputs[item.key]; + } + return API.put('/api/option/', { + key: item.key, + value, + }); + }); + setLoading(true); + Promise.all(requestQueue) + .then((res) => { + if (requestQueue.length === 1) { + if (res.includes(undefined)) return; + } else if (requestQueue.length > 1) { + if (res.includes(undefined)) return showError('部分更新失败'); + } + showSuccess('更新成功'); + }) + .catch(() => { + showError('更新失败'); + }) + .finally(() => { + setLoading(false); + setInputsRow(structuredClone(inputs)); + }); + } + + useEffect(() => { + const currentInputs = {}; + for (let key in props.options) { + if (Object.keys(inputs).includes(key)) { + currentInputs[key] = props.options[key]; + } + } + setInputs(currentInputs); + setInputsRow(structuredClone(currentInputs)); + refForm.current.setValues(currentInputs); + }, [props.options]); + return ( + <> + + (refForm.current = formAPI)} + style={{ marginBottom: 15 }} + > + + + + + setInputs({ + ...inputs, + ChannelDisableThreshold: String(value), + }) + } + /> + + + + setInputs({ + ...inputs, + QuotaRemindThreshold: String(value), + }) + } + /> + + + + + { + setInputs({ + ...inputs, + AutomaticDisableChannelEnabled: value, + }); + }} + /> + + + + setInputs({ + ...inputs, + AutomaticEnableChannelEnabled: value, + }) + } + /> + + + + + + + + + + ); +} From 968ef1e5fa425db1d5681af6463f8014b0df742e Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Sat, 11 May 2024 17:48:05 +0800 Subject: [PATCH 08/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E9=A2=9D=E5=BA=A6=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/OperationSetting.js | 58 +------ .../Setting/Operation/SettingsCreditLimit.js | 156 ++++++++++++++++++ 2 files changed, 161 insertions(+), 53 deletions(-) create mode 100644 web/src/pages/Setting/Operation/SettingsCreditLimit.js diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index b9e8e9e..2dd5489 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -7,6 +7,7 @@ import SettingsSensitiveWords from '../pages/Setting/Operation/SettingsSensitive import SettingsLog from '../pages/Setting/Operation/SettingsLog.js'; import SettingsDataDashboard from '../pages/Setting/Operation/SettingsDataDashboard.js'; import SettingsMonitoring from '../pages/Setting/Operation/SettingsMonitoring.js'; +import SettingsCreditLimit from '../pages/Setting/Operation/SettingsCreditLimit.js'; import { API, @@ -244,6 +245,10 @@ const OperationSetting = () => { + {/* 额度设置 */} + + +
@@ -267,59 +272,6 @@ const OperationSetting = () => { {/* />*/} {/**/} - -
- 额度设置 -
- - - - - - - { - submitConfig('quota').then(); - }} - > - 保存额度设置 -
倍率设置 diff --git a/web/src/pages/Setting/Operation/SettingsCreditLimit.js b/web/src/pages/Setting/Operation/SettingsCreditLimit.js new file mode 100644 index 0000000..4fcbb4e --- /dev/null +++ b/web/src/pages/Setting/Operation/SettingsCreditLimit.js @@ -0,0 +1,156 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { Button, Col, Form, Row, Spin } from '@douyinfe/semi-ui'; +import { + compareObjects, + API, + showError, + showSuccess, + showWarning, +} from '../../../helpers'; + +export default function SettingsCreditLimit(props) { + const [loading, setLoading] = useState(false); + const [inputs, setInputs] = useState({ + QuotaForNewUser: '', + PreConsumedQuota: '', + QuotaForInviter: '', + QuotaForInvitee: '', + }); + const refForm = useRef(); + const [inputsRow, setInputsRow] = useState(inputs); + + function onSubmit() { + const updateArray = compareObjects(inputs, inputsRow); + if (!updateArray.length) return showWarning('你似乎并没有修改什么'); + const requestQueue = updateArray.map((item) => { + let value = ''; + if (typeof inputs[item.key] === 'boolean') { + value = String(inputs[item.key]); + } else { + value = inputs[item.key]; + } + return API.put('/api/option/', { + key: item.key, + value, + }); + }); + setLoading(true); + Promise.all(requestQueue) + .then((res) => { + if (requestQueue.length === 1) { + if (res.includes(undefined)) return; + } else if (requestQueue.length > 1) { + if (res.includes(undefined)) return showError('部分更新失败'); + } + showSuccess('更新成功'); + }) + .catch(() => { + showError('更新失败'); + }) + .finally(() => { + setLoading(false); + setInputsRow(structuredClone(inputs)); + }); + } + + useEffect(() => { + const currentInputs = {}; + for (let key in props.options) { + if (Object.keys(inputs).includes(key)) { + currentInputs[key] = props.options[key]; + } + } + setInputs(currentInputs); + setInputsRow(structuredClone(currentInputs)); + refForm.current.setValues(currentInputs); + }, [props.options]); + return ( + <> + + (refForm.current = formAPI)} + style={{ marginBottom: 15 }} + > + + + + + setInputs({ + ...inputs, + QuotaForNewUser: String(value), + }) + } + /> + + + + setInputs({ + ...inputs, + PreConsumedQuota: String(value), + }) + } + /> + + + + setInputs({ + ...inputs, + QuotaForInviter: String(value), + }) + } + /> + + + + setInputs({ + ...inputs, + QuotaForInvitee: String(value), + }) + } + /> + + + + + + + + + + + ); +} From b283365ebcf3c6c94e1c03898294e21fb6f65b49 Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Mon, 13 May 2024 17:55:15 +0800 Subject: [PATCH 09/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E5=80=8D=E7=8E=87=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/OperationSetting.js | 309 +++--------------- .../Operation/SettingsMagnification.js | 193 +++++++++++ 2 files changed, 242 insertions(+), 260 deletions(-) create mode 100644 web/src/pages/Setting/Operation/SettingsMagnification.js diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index 31345a5..2529ca2 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import { Divider, Form, Grid, Header } from 'semantic-ui-react'; -import { Card } from '@douyinfe/semi-ui'; +import { Card, Spin } from '@douyinfe/semi-ui'; import SettingsGeneral from '../pages/Setting/Operation/SettingsGeneral.js'; import SettingsDrawing from '../pages/Setting/Operation/SettingsDrawing.js'; import SettingsSensitiveWords from '../pages/Setting/Operation/SettingsSensitiveWords.js'; @@ -8,6 +8,7 @@ import SettingsLog from '../pages/Setting/Operation/SettingsLog.js'; import SettingsDataDashboard from '../pages/Setting/Operation/SettingsDataDashboard.js'; import SettingsMonitoring from '../pages/Setting/Operation/SettingsMonitoring.js'; import SettingsCreditLimit from '../pages/Setting/Operation/SettingsCreditLimit.js'; +import SettingsMagnification from '../pages/Setting/Operation/SettingsMagnification.js'; import { API, @@ -17,10 +18,7 @@ import { verifyJSON, } from '../helpers'; -import { useTheme } from '../context/Theme'; - const OperationSetting = () => { - let now = new Date(); let [inputs, setInputs] = useState({ QuotaForNewUser: 0, QuotaForInviter: 0, @@ -58,7 +56,7 @@ const OperationSetting = () => { DefaultCollapseSidebar: false, // 默认折叠侧边栏 RetryTimes: 0, }); - const [originInputs, setOriginInputs] = useState({}); + let [loading, setLoading] = useState(false); const getOptions = async () => { @@ -86,271 +84,62 @@ const OperationSetting = () => { }); setInputs(newInputs); - setOriginInputs(newInputs); } else { showError(message); } }; - - const theme = useTheme(); - const isDark = theme === 'dark'; + async function onRefresh() { + try { + setLoading(true); + await getOptions(); + showSuccess('刷新成功'); + } catch (error) { + showError('刷新失败'); + } finally { + setLoading(false); + } + } useEffect(() => { - getOptions().then(); + getOptions(); }, []); - const updateOption = async (key, value) => { - setLoading(true); - if (key.endsWith('Enabled')) { - value = inputs[key] === 'true' ? 'false' : 'true'; - } - if (key === 'DefaultCollapseSidebar') { - value = inputs[key] === 'true' ? 'false' : 'true'; - } - console.log(key, value); - const res = await API.put('/api/option/', { - key, - value, - }); - const { success, message } = res.data; - if (success) { - setInputs((inputs) => ({ ...inputs, [key]: value })); - } else { - showError(message); - } - setLoading(false); - }; - - const handleInputChange = async (e, { name, value }) => { - if ( - name.endsWith('Enabled') || - name === 'DataExportInterval' || - name === 'DataExportDefaultTime' || - name === 'DefaultCollapseSidebar' - ) { - if (name === 'DataExportDefaultTime') { - localStorage.setItem('data_export_default_time', value); - } else if (name === 'MjNotifyEnabled') { - localStorage.setItem('mj_notify_enabled', value); - } - await updateOption(name, value); - } else { - setInputs((inputs) => ({ ...inputs, [name]: value })); - } - }; - - const submitConfig = async (group) => { - switch (group) { - case 'monitor': - if ( - originInputs['ChannelDisableThreshold'] !== - inputs.ChannelDisableThreshold - ) { - await updateOption( - 'ChannelDisableThreshold', - inputs.ChannelDisableThreshold, - ); - } - if ( - originInputs['QuotaRemindThreshold'] !== inputs.QuotaRemindThreshold - ) { - await updateOption( - 'QuotaRemindThreshold', - inputs.QuotaRemindThreshold, - ); - } - break; - case 'ratio': - if (originInputs['ModelRatio'] !== inputs.ModelRatio) { - if (!verifyJSON(inputs.ModelRatio)) { - showError('模型倍率不是合法的 JSON 字符串'); - return; - } - await updateOption('ModelRatio', inputs.ModelRatio); - } - if (originInputs['CompletionRatio'] !== inputs.CompletionRatio) { - if (!verifyJSON(inputs.CompletionRatio)) { - showError('模型补全倍率不是合法的 JSON 字符串'); - return; - } - await updateOption('CompletionRatio', inputs.CompletionRatio); - } - if (originInputs['GroupRatio'] !== inputs.GroupRatio) { - if (!verifyJSON(inputs.GroupRatio)) { - showError('分组倍率不是合法的 JSON 字符串'); - return; - } - await updateOption('GroupRatio', inputs.GroupRatio); - } - if (originInputs['ModelPrice'] !== inputs.ModelPrice) { - if (!verifyJSON(inputs.ModelPrice)) { - showError('模型固定价格不是合法的 JSON 字符串'); - return; - } - await updateOption('ModelPrice', inputs.ModelPrice); - } - break; - case 'words': - if (originInputs['SensitiveWords'] !== inputs.SensitiveWords) { - await updateOption('SensitiveWords', inputs.SensitiveWords); - } - break; - case 'quota': - if (originInputs['QuotaForNewUser'] !== inputs.QuotaForNewUser) { - await updateOption('QuotaForNewUser', inputs.QuotaForNewUser); - } - if (originInputs['QuotaForInvitee'] !== inputs.QuotaForInvitee) { - await updateOption('QuotaForInvitee', inputs.QuotaForInvitee); - } - if (originInputs['QuotaForInviter'] !== inputs.QuotaForInviter) { - await updateOption('QuotaForInviter', inputs.QuotaForInviter); - } - if (originInputs['PreConsumedQuota'] !== inputs.PreConsumedQuota) { - await updateOption('PreConsumedQuota', inputs.PreConsumedQuota); - } - break; - case 'general': - if (originInputs['TopUpLink'] !== inputs.TopUpLink) { - await updateOption('TopUpLink', inputs.TopUpLink); - } - if (originInputs['ChatLink'] !== inputs.ChatLink) { - await updateOption('ChatLink', inputs.ChatLink); - } - if (originInputs['ChatLink2'] !== inputs.ChatLink2) { - await updateOption('ChatLink2', inputs.ChatLink2); - } - if (originInputs['QuotaPerUnit'] !== inputs.QuotaPerUnit) { - await updateOption('QuotaPerUnit', inputs.QuotaPerUnit); - } - if (originInputs['RetryTimes'] !== inputs.RetryTimes) { - await updateOption('RetryTimes', inputs.RetryTimes); - } - break; - } - }; return ( <> - {/* 通用设置 */} - - - - {/* 绘图设置 */} - - - - {/* 屏蔽词过滤设置 */} - - - - {/* 日志设置 */} - - - - {/* 数据看板 */} - - - - {/* 监控设置 */} - - - - {/* 额度设置 */} - - - - - -
- {/**/} - {/* */} - {/**/} - {/**/} - {/* */} - {/**/} - - -
- 倍率设置 -
- - - - - - - - - - - - - { - submitConfig('ratio').then(); - }} - > - 保存倍率设置 - - -
-
+ + {/* 通用设置 */} + + + + {/* 绘图设置 */} + + + + {/* 屏蔽词过滤设置 */} + + + + {/* 日志设置 */} + + + + {/* 数据看板 */} + + + + {/* 监控设置 */} + + + + {/* 额度设置 */} + + + + {/* 倍率设置 */} + + + + ); }; diff --git a/web/src/pages/Setting/Operation/SettingsMagnification.js b/web/src/pages/Setting/Operation/SettingsMagnification.js new file mode 100644 index 0000000..3f38b37 --- /dev/null +++ b/web/src/pages/Setting/Operation/SettingsMagnification.js @@ -0,0 +1,193 @@ +import React, { useEffect, useState, useRef } from 'react'; +import { Button, Col, Form, Row, Spin } from '@douyinfe/semi-ui'; +import { + compareObjects, + API, + showError, + showSuccess, + showWarning, + verifyJSON, +} from '../../../helpers'; + +export default function SettingsMagnification(props) { + const [loading, setLoading] = useState(false); + const [inputs, setInputs] = useState({ + ModelPrice: '', + ModelRatio: '', + CompletionRatio: '', + GroupRatio: '', + }); + const refForm = useRef(); + const [inputsRow, setInputsRow] = useState(inputs); + + async function onSubmit() { + try { + await refForm.current.validate(); + const updateArray = compareObjects(inputs, inputsRow); + if (!updateArray.length) return showWarning('你似乎并没有修改什么'); + const requestQueue = updateArray.map((item) => { + let value = ''; + if (typeof inputs[item.key] === 'boolean') { + value = String(inputs[item.key]); + } else { + value = inputs[item.key]; + } + return API.put('/api/option/', { + key: item.key, + value, + }); + }); + setLoading(true); + Promise.all(requestQueue) + .then((res) => { + if (requestQueue.length === 1) { + if (res.includes(undefined)) return; + } else if (requestQueue.length > 1) { + if (res.includes(undefined)) return showError('部分更新失败'); + } + showSuccess('更新成功'); + }) + .catch(() => { + showError('更新失败'); + }) + .finally(() => { + setLoading(false); + setInputsRow(structuredClone(inputs)); + }); + } catch (error) { + showError('请检查输入'); + console.error(error); + } finally { + } + } + + useEffect(() => { + const currentInputs = {}; + for (let key in props.options) { + if (Object.keys(inputs).includes(key)) { + currentInputs[key] = props.options[key]; + } + } + setInputs(currentInputs); + setInputsRow(structuredClone(currentInputs)); + refForm.current.setValues(currentInputs); + }, [props.options]); + return ( + <> + +
(refForm.current = formAPI)} + style={{ marginBottom: 15 }} + > + + + + verifyJSON(value), + message: '不是合法的 JSON 字符串', + }, + ]} + onChange={(value) => + setInputs({ + ...inputs, + ModelPrice: value, + }) + } + /> + + + + + verifyJSON(value), + message: '不是合法的 JSON 字符串', + }, + ]} + onChange={(value) => + setInputs({ + ...inputs, + ModelRatio: value, + }) + } + /> + + + + + verifyJSON(value), + message: '不是合法的 JSON 字符串', + }, + ]} + onChange={(value) => + setInputs({ + ...inputs, + CompletionRatio: value, + }) + } + /> + + + + + verifyJSON(value), + message: '不是合法的 JSON 字符串', + }, + ]} + onChange={(value) => + setInputs({ + ...inputs, + GroupRatio: value, + }) + } + /> + + + + + + + +
+
+ + ); +} From 98c347e048ca6977d15a895c69e509404b2bdbdc Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Mon, 13 May 2024 18:14:57 +0800 Subject: [PATCH 10/12] =?UTF-8?q?refactor:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E6=95=B0=E6=8D=AE=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/OperationSetting.js | 27 +++++++------------ .../Setting/Operation/SettingsCreditLimit.js | 2 +- .../Operation/SettingsDataDashboard.js | 2 +- .../Setting/Operation/SettingsDrawing.js | 2 +- .../Setting/Operation/SettingsGeneral.js | 2 +- .../pages/Setting/Operation/SettingsLog.js | 5 +--- .../Operation/SettingsMagnification.js | 2 +- .../Setting/Operation/SettingsMonitoring.js | 2 +- .../Operation/SettingsSensitiveWords.js | 2 +- 9 files changed, 18 insertions(+), 28 deletions(-) diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index 2529ca2..3273f24 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -1,5 +1,4 @@ import React, { useEffect, useState } from 'react'; -import { Divider, Form, Grid, Header } from 'semantic-ui-react'; import { Card, Spin } from '@douyinfe/semi-ui'; import SettingsGeneral from '../pages/Setting/Operation/SettingsGeneral.js'; import SettingsDrawing from '../pages/Setting/Operation/SettingsDrawing.js'; @@ -10,13 +9,7 @@ import SettingsMonitoring from '../pages/Setting/Operation/SettingsMonitoring.js import SettingsCreditLimit from '../pages/Setting/Operation/SettingsCreditLimit.js'; import SettingsMagnification from '../pages/Setting/Operation/SettingsMagnification.js'; -import { - API, - showError, - showSuccess, - timestamp2string, - verifyJSON, -} from '../helpers'; +import { API, showError, showSuccess } from '../helpers'; const OperationSetting = () => { let [inputs, setInputs] = useState({ @@ -101,7 +94,7 @@ const OperationSetting = () => { } useEffect(() => { - getOptions(); + onRefresh(); }, []); return ( @@ -109,35 +102,35 @@ const OperationSetting = () => { {/* 通用设置 */} - + {/* 绘图设置 */} - + {/* 屏蔽词过滤设置 */} - + {/* 日志设置 */} - + {/* 数据看板 */} - + {/* 监控设置 */} - + {/* 额度设置 */} - + {/* 倍率设置 */} - + diff --git a/web/src/pages/Setting/Operation/SettingsCreditLimit.js b/web/src/pages/Setting/Operation/SettingsCreditLimit.js index 4fcbb4e..90dfddf 100644 --- a/web/src/pages/Setting/Operation/SettingsCreditLimit.js +++ b/web/src/pages/Setting/Operation/SettingsCreditLimit.js @@ -49,7 +49,7 @@ export default function SettingsCreditLimit(props) { }) .finally(() => { setLoading(false); - setInputsRow(structuredClone(inputs)); + props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsDataDashboard.js b/web/src/pages/Setting/Operation/SettingsDataDashboard.js index 85fd1dc..8710639 100644 --- a/web/src/pages/Setting/Operation/SettingsDataDashboard.js +++ b/web/src/pages/Setting/Operation/SettingsDataDashboard.js @@ -53,7 +53,7 @@ export default function DataDashboard(props) { }) .finally(() => { setLoading(false); - setInputsRow(structuredClone(inputs)); + props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsDrawing.js b/web/src/pages/Setting/Operation/SettingsDrawing.js index 560bbc7..d0c0ef7 100644 --- a/web/src/pages/Setting/Operation/SettingsDrawing.js +++ b/web/src/pages/Setting/Operation/SettingsDrawing.js @@ -50,7 +50,7 @@ export default function SettingsDrawing(props) { }) .finally(() => { setLoading(false); - setInputsRow(structuredClone(inputs)); + props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsGeneral.js b/web/src/pages/Setting/Operation/SettingsGeneral.js index 83fb7c8..a988ce8 100644 --- a/web/src/pages/Setting/Operation/SettingsGeneral.js +++ b/web/src/pages/Setting/Operation/SettingsGeneral.js @@ -56,7 +56,7 @@ export default function GeneralSettings(props) { }) .finally(() => { setLoading(false); - setInputsRow(structuredClone(inputs)); + props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsLog.js b/web/src/pages/Setting/Operation/SettingsLog.js index 77120ea..4377e73 100644 --- a/web/src/pages/Setting/Operation/SettingsLog.js +++ b/web/src/pages/Setting/Operation/SettingsLog.js @@ -16,9 +16,6 @@ export default function SettingsLog(props) { LogConsumeEnabled: false, historyTimestamp: dayjs().subtract(1, 'month').toDate(), }); - // const [historyTimestamp, setHistoryTimestamp] = useState( - // dayjs().subtract(1, 'month').toDate(), - // ); const refForm = useRef(); const [inputsRow, setInputsRow] = useState(inputs); @@ -55,7 +52,7 @@ export default function SettingsLog(props) { }) .finally(() => { setLoading(false); - setInputsRow(structuredClone(inputs)); + props.refresh(); }); } async function onCleanHistoryLog() { diff --git a/web/src/pages/Setting/Operation/SettingsMagnification.js b/web/src/pages/Setting/Operation/SettingsMagnification.js index 3f38b37..f92dae9 100644 --- a/web/src/pages/Setting/Operation/SettingsMagnification.js +++ b/web/src/pages/Setting/Operation/SettingsMagnification.js @@ -52,7 +52,7 @@ export default function SettingsMagnification(props) { }) .finally(() => { setLoading(false); - setInputsRow(structuredClone(inputs)); + props.refresh(); }); } catch (error) { showError('请检查输入'); diff --git a/web/src/pages/Setting/Operation/SettingsMonitoring.js b/web/src/pages/Setting/Operation/SettingsMonitoring.js index 6fed48f..39ee002 100644 --- a/web/src/pages/Setting/Operation/SettingsMonitoring.js +++ b/web/src/pages/Setting/Operation/SettingsMonitoring.js @@ -49,7 +49,7 @@ export default function SettingsMonitoring(props) { }) .finally(() => { setLoading(false); - setInputsRow(structuredClone(inputs)); + props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js index f251013..f13daff 100644 --- a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js +++ b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js @@ -48,7 +48,7 @@ export default function SettingsSensitiveWords(props) { }) .finally(() => { setLoading(false); - setInputsRow(structuredClone(inputs)); + props.refresh(); }); } From 65ae70919b43c74f1dfe3c8e49ecdad4fdd35243 Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Tue, 14 May 2024 10:17:20 +0800 Subject: [PATCH 11/12] =?UTF-8?q?perf:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E6=95=B0=E6=8D=AE=E5=88=B7=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Setting/Operation/SettingsCreditLimit.js | 4 ++-- web/src/pages/Setting/Operation/SettingsDataDashboard.js | 2 +- web/src/pages/Setting/Operation/SettingsDrawing.js | 2 +- web/src/pages/Setting/Operation/SettingsGeneral.js | 2 +- web/src/pages/Setting/Operation/SettingsLog.js | 2 +- web/src/pages/Setting/Operation/SettingsMagnification.js | 2 +- web/src/pages/Setting/Operation/SettingsMonitoring.js | 2 +- web/src/pages/Setting/Operation/SettingsSensitiveWords.js | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/web/src/pages/Setting/Operation/SettingsCreditLimit.js b/web/src/pages/Setting/Operation/SettingsCreditLimit.js index 90dfddf..80e6191 100644 --- a/web/src/pages/Setting/Operation/SettingsCreditLimit.js +++ b/web/src/pages/Setting/Operation/SettingsCreditLimit.js @@ -40,16 +40,16 @@ export default function SettingsCreditLimit(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败'); + if (res.includes(undefined)) return showError('部分更新失败,请重试'); } showSuccess('更新成功'); + props.refresh(); }) .catch(() => { showError('更新失败'); }) .finally(() => { setLoading(false); - props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsDataDashboard.js b/web/src/pages/Setting/Operation/SettingsDataDashboard.js index 8710639..263f7cb 100644 --- a/web/src/pages/Setting/Operation/SettingsDataDashboard.js +++ b/web/src/pages/Setting/Operation/SettingsDataDashboard.js @@ -47,13 +47,13 @@ export default function DataDashboard(props) { if (res.includes(undefined)) return showError('部分更新失败'); } showSuccess('更新成功'); + props.refresh(); }) .catch(() => { showError('更新失败'); }) .finally(() => { setLoading(false); - props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsDrawing.js b/web/src/pages/Setting/Operation/SettingsDrawing.js index d0c0ef7..c9f63af 100644 --- a/web/src/pages/Setting/Operation/SettingsDrawing.js +++ b/web/src/pages/Setting/Operation/SettingsDrawing.js @@ -44,13 +44,13 @@ export default function SettingsDrawing(props) { if (res.includes(undefined)) return showError('部分更新失败'); } showSuccess('更新成功'); + props.refresh(); }) .catch(() => { showError('更新失败'); }) .finally(() => { setLoading(false); - props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsGeneral.js b/web/src/pages/Setting/Operation/SettingsGeneral.js index a988ce8..314068a 100644 --- a/web/src/pages/Setting/Operation/SettingsGeneral.js +++ b/web/src/pages/Setting/Operation/SettingsGeneral.js @@ -50,13 +50,13 @@ export default function GeneralSettings(props) { if (res.includes(undefined)) return showError('部分更新失败'); } showSuccess('更新成功'); + props.refresh(); }) .catch(() => { showError('更新失败'); }) .finally(() => { setLoading(false); - props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsLog.js b/web/src/pages/Setting/Operation/SettingsLog.js index 4377e73..1a9b509 100644 --- a/web/src/pages/Setting/Operation/SettingsLog.js +++ b/web/src/pages/Setting/Operation/SettingsLog.js @@ -46,13 +46,13 @@ export default function SettingsLog(props) { if (res.includes(undefined)) return showError('部分更新失败'); } showSuccess('更新成功'); + props.refresh(); }) .catch(() => { showError('更新失败'); }) .finally(() => { setLoading(false); - props.refresh(); }); } async function onCleanHistoryLog() { diff --git a/web/src/pages/Setting/Operation/SettingsMagnification.js b/web/src/pages/Setting/Operation/SettingsMagnification.js index f92dae9..849a9ad 100644 --- a/web/src/pages/Setting/Operation/SettingsMagnification.js +++ b/web/src/pages/Setting/Operation/SettingsMagnification.js @@ -46,13 +46,13 @@ export default function SettingsMagnification(props) { if (res.includes(undefined)) return showError('部分更新失败'); } showSuccess('更新成功'); + props.refresh(); }) .catch(() => { showError('更新失败'); }) .finally(() => { setLoading(false); - props.refresh(); }); } catch (error) { showError('请检查输入'); diff --git a/web/src/pages/Setting/Operation/SettingsMonitoring.js b/web/src/pages/Setting/Operation/SettingsMonitoring.js index 39ee002..b8c891c 100644 --- a/web/src/pages/Setting/Operation/SettingsMonitoring.js +++ b/web/src/pages/Setting/Operation/SettingsMonitoring.js @@ -43,13 +43,13 @@ export default function SettingsMonitoring(props) { if (res.includes(undefined)) return showError('部分更新失败'); } showSuccess('更新成功'); + props.refresh(); }) .catch(() => { showError('更新失败'); }) .finally(() => { setLoading(false); - props.refresh(); }); } diff --git a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js index f13daff..279e304 100644 --- a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js +++ b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js @@ -42,13 +42,13 @@ export default function SettingsSensitiveWords(props) { if (res.includes(undefined)) return showError('部分更新失败'); } showSuccess('更新成功'); + props.refresh(); }) .catch(() => { showError('更新失败'); }) .finally(() => { setLoading(false); - props.refresh(); }); } From 470f3a1d51a96311cc89d9b236402a065c061122 Mon Sep 17 00:00:00 2001 From: QuentinHsu Date: Tue, 14 May 2024 10:18:24 +0800 Subject: [PATCH 12/12] =?UTF-8?q?perf:=20=E8=BF=90=E8=90=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE-=E6=8F=90=E7=A4=BA=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Setting/Operation/SettingsCreditLimit.js | 6 +++--- web/src/pages/Setting/Operation/SettingsDataDashboard.js | 6 +++--- web/src/pages/Setting/Operation/SettingsDrawing.js | 6 +++--- web/src/pages/Setting/Operation/SettingsGeneral.js | 6 +++--- web/src/pages/Setting/Operation/SettingsLog.js | 6 +++--- web/src/pages/Setting/Operation/SettingsMagnification.js | 7 ++++--- web/src/pages/Setting/Operation/SettingsMonitoring.js | 6 +++--- web/src/pages/Setting/Operation/SettingsSensitiveWords.js | 6 +++--- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/web/src/pages/Setting/Operation/SettingsCreditLimit.js b/web/src/pages/Setting/Operation/SettingsCreditLimit.js index 80e6191..ed5862a 100644 --- a/web/src/pages/Setting/Operation/SettingsCreditLimit.js +++ b/web/src/pages/Setting/Operation/SettingsCreditLimit.js @@ -40,13 +40,13 @@ export default function SettingsCreditLimit(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败,请重试'); + if (res.includes(undefined)) return showError('部分保存失败,请重试'); } - showSuccess('更新成功'); + showSuccess('保存成功'); props.refresh(); }) .catch(() => { - showError('更新失败'); + showError('保存失败,请重试'); }) .finally(() => { setLoading(false); diff --git a/web/src/pages/Setting/Operation/SettingsDataDashboard.js b/web/src/pages/Setting/Operation/SettingsDataDashboard.js index 263f7cb..de0911e 100644 --- a/web/src/pages/Setting/Operation/SettingsDataDashboard.js +++ b/web/src/pages/Setting/Operation/SettingsDataDashboard.js @@ -44,13 +44,13 @@ export default function DataDashboard(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败'); + if (res.includes(undefined)) return showError('部分保存失败,请重试'); } - showSuccess('更新成功'); + showSuccess('保存成功'); props.refresh(); }) .catch(() => { - showError('更新失败'); + showError('保存失败,请重试'); }) .finally(() => { setLoading(false); diff --git a/web/src/pages/Setting/Operation/SettingsDrawing.js b/web/src/pages/Setting/Operation/SettingsDrawing.js index c9f63af..bb1c047 100644 --- a/web/src/pages/Setting/Operation/SettingsDrawing.js +++ b/web/src/pages/Setting/Operation/SettingsDrawing.js @@ -41,13 +41,13 @@ export default function SettingsDrawing(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败'); + if (res.includes(undefined)) return showError('部分保存失败,请重试'); } - showSuccess('更新成功'); + showSuccess('保存成功'); props.refresh(); }) .catch(() => { - showError('更新失败'); + showError('保存失败,请重试'); }) .finally(() => { setLoading(false); diff --git a/web/src/pages/Setting/Operation/SettingsGeneral.js b/web/src/pages/Setting/Operation/SettingsGeneral.js index 314068a..ef52371 100644 --- a/web/src/pages/Setting/Operation/SettingsGeneral.js +++ b/web/src/pages/Setting/Operation/SettingsGeneral.js @@ -47,13 +47,13 @@ export default function GeneralSettings(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败'); + if (res.includes(undefined)) return showError('部分保存失败,请重试'); } - showSuccess('更新成功'); + showSuccess('保存成功'); props.refresh(); }) .catch(() => { - showError('更新失败'); + showError('保存失败,请重试'); }) .finally(() => { setLoading(false); diff --git a/web/src/pages/Setting/Operation/SettingsLog.js b/web/src/pages/Setting/Operation/SettingsLog.js index 1a9b509..6977dca 100644 --- a/web/src/pages/Setting/Operation/SettingsLog.js +++ b/web/src/pages/Setting/Operation/SettingsLog.js @@ -43,13 +43,13 @@ export default function SettingsLog(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败'); + if (res.includes(undefined)) return showError('部分保存失败,请重试'); } - showSuccess('更新成功'); + showSuccess('保存成功'); props.refresh(); }) .catch(() => { - showError('更新失败'); + showError('保存失败,请重试'); }) .finally(() => { setLoading(false); diff --git a/web/src/pages/Setting/Operation/SettingsMagnification.js b/web/src/pages/Setting/Operation/SettingsMagnification.js index 849a9ad..9c64793 100644 --- a/web/src/pages/Setting/Operation/SettingsMagnification.js +++ b/web/src/pages/Setting/Operation/SettingsMagnification.js @@ -43,13 +43,14 @@ export default function SettingsMagnification(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败'); + if (res.includes(undefined)) + return showError('部分保存失败,请重试'); } - showSuccess('更新成功'); + showSuccess('保存成功'); props.refresh(); }) .catch(() => { - showError('更新失败'); + showError('保存失败,请重试'); }) .finally(() => { setLoading(false); diff --git a/web/src/pages/Setting/Operation/SettingsMonitoring.js b/web/src/pages/Setting/Operation/SettingsMonitoring.js index b8c891c..fc86b97 100644 --- a/web/src/pages/Setting/Operation/SettingsMonitoring.js +++ b/web/src/pages/Setting/Operation/SettingsMonitoring.js @@ -40,13 +40,13 @@ export default function SettingsMonitoring(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败'); + if (res.includes(undefined)) return showError('部分保存失败,请重试'); } - showSuccess('更新成功'); + showSuccess('保存成功'); props.refresh(); }) .catch(() => { - showError('更新失败'); + showError('保存失败,请重试'); }) .finally(() => { setLoading(false); diff --git a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js index 279e304..21583b6 100644 --- a/web/src/pages/Setting/Operation/SettingsSensitiveWords.js +++ b/web/src/pages/Setting/Operation/SettingsSensitiveWords.js @@ -39,13 +39,13 @@ export default function SettingsSensitiveWords(props) { if (requestQueue.length === 1) { if (res.includes(undefined)) return; } else if (requestQueue.length > 1) { - if (res.includes(undefined)) return showError('部分更新失败'); + if (res.includes(undefined)) return showError('部分保存失败,请重试'); } - showSuccess('更新成功'); + showSuccess('保存成功'); props.refresh(); }) .catch(() => { - showError('更新失败'); + showError('保存失败,请重试'); }) .finally(() => { setLoading(false);