From 1202e7699bdcad7ad322352272dd61fb3d3c0c55 Mon Sep 17 00:00:00 2001 From: "Apple\\Apple" Date: Sat, 16 Mar 2024 10:02:58 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=88=9D=E4=BB=A3air=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E5=B0=86=E4=BD=BF=E7=94=A8default=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E8=BF=90=E8=90=A5=E8=AE=BE=E7=BD=AE=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E3=80=81=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E3=80=81=E5=85=B6=E4=BB=96=E8=AE=BE=E7=BD=AE=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/air/src/components/OperationSetting.js | 305 ++++++----------- web/air/src/components/OtherSetting.js | 359 +++++++++---------- web/air/src/components/SystemSetting.js | 379 ++++++++------------- 3 files changed, 409 insertions(+), 634 deletions(-) diff --git a/web/air/src/components/OperationSetting.js b/web/air/src/components/OperationSetting.js index 874c5524..b823bb28 100644 --- a/web/air/src/components/OperationSetting.js +++ b/web/air/src/components/OperationSetting.js @@ -11,11 +11,10 @@ const OperationSetting = () => { QuotaRemindThreshold: 0, PreConsumedQuota: 0, ModelRatio: '', - ModelPrice: '', + CompletionRatio: '', GroupRatio: '', TopUpLink: '', ChatLink: '', - ChatLink2: '', // 添加的新状态变量 QuotaPerUnit: 0, AutomaticDisableChannelEnabled: '', AutomaticEnableChannelEnabled: '', @@ -23,32 +22,25 @@ const OperationSetting = () => { LogConsumeEnabled: '', DisplayInCurrencyEnabled: '', DisplayTokenStatEnabled: '', - MjNotifyEnabled: '', - DrawingEnabled: '', - DataExportEnabled: '', - DataExportDefaultTime: 'hour', - DataExportInterval: 5, - DefaultCollapseSidebar: '', // 默认折叠侧边栏 + ApproximateTokenEnabled: '', RetryTimes: 0 }); 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; if (success) { let newInputs = {}; data.forEach((item) => { - if (item.key === 'ModelRatio' || item.key === 'GroupRatio' || item.key === 'ModelPrice') { + if (item.key === 'ModelRatio' || item.key === 'GroupRatio' || item.key === 'CompletionRatio') { item.value = JSON.stringify(JSON.parse(item.value), null, 2); } + if (item.value === '{}') { + item.value = ''; + } newInputs[item.key] = item.value; }); setInputs(newInputs); @@ -67,10 +59,6 @@ const OperationSetting = () => { 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 @@ -85,12 +73,7 @@ const OperationSetting = () => { }; 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); - } + if (name.endsWith('Enabled')) { await updateOption(name, value); } else { setInputs((inputs) => ({ ...inputs, [name]: value })); @@ -122,12 +105,12 @@ const OperationSetting = () => { } await updateOption('GroupRatio', inputs.GroupRatio); } - if (originInputs['ModelPrice'] !== inputs.ModelPrice) { - if (!verifyJSON(inputs.ModelPrice)) { - showError('模型固定价格不是合法的 JSON 字符串'); + if (originInputs['CompletionRatio'] !== inputs.CompletionRatio) { + if (!verifyJSON(inputs.CompletionRatio)) { + showError('补全倍率不是合法的 JSON 字符串'); return; } - await updateOption('ModelPrice', inputs.ModelPrice); + await updateOption('CompletionRatio', inputs.CompletionRatio); } break; case 'quota': @@ -151,9 +134,6 @@ const OperationSetting = () => { 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); } @@ -174,80 +154,72 @@ const OperationSetting = () => { } showError('日志清理失败:' + message); }; + return (
-
+
通用设置
- @@ -255,38 +227,20 @@ const OperationSetting = () => { submitConfig('general').then(); }}>保存通用设置 -
- 绘图设置 -
- - - - - -
+
日志设置
- { setHistoryTimestamp(value); }} /> @@ -295,74 +249,42 @@ const OperationSetting = () => { deleteHistoryLogs().then(); }}>清理历史日志 -
- 数据看板 -
- - - - - - -
+
监控设置
@@ -370,89 +292,89 @@ const OperationSetting = () => { submitConfig('monitor').then(); }}>保存监控设置 -
+
额度设置
{ submitConfig('quota').then(); }}>保存额度设置 -
+
倍率设置
- + - - - - + + + + { @@ -461,8 +383,7 @@ const OperationSetting = () => { - ) - ; + ); }; export default OperationSetting; diff --git a/web/air/src/components/OtherSetting.js b/web/air/src/components/OtherSetting.js index 014492de..ae924d9f 100644 --- a/web/air/src/components/OtherSetting.js +++ b/web/air/src/components/OtherSetting.js @@ -1,16 +1,18 @@ -import React, { useEffect, useRef, useState } from 'react'; -import { Banner, Button, Col, Form, Row } from '@douyinfe/semi-ui'; +import React, { useEffect, useState } from 'react'; +import { Button, Divider, Form, Grid, Header, Message, Modal } from 'semantic-ui-react'; import { API, showError, showSuccess } from '../helpers'; import { marked } from 'marked'; +import { Link } from 'react-router-dom'; const OtherSetting = () => { let [inputs, setInputs] = useState({ + Footer: '', Notice: '', + About: '', SystemName: '', Logo: '', - Footer: '', - About: '', - HomePageContent: '' + HomePageContent: '', + Theme: '' }); let [loading, setLoading] = useState(false); const [showUpdateModal, setShowUpdateModal] = useState(false); @@ -19,6 +21,25 @@ const OtherSetting = () => { content: '' }); + const getOptions = async () => { + const res = await API.get('/api/option/'); + const { success, message, data } = res.data; + if (success) { + let newInputs = {}; + data.forEach((item) => { + if (item.key in inputs) { + newInputs[item.key] = item.value; + } + }); + setInputs(newInputs); + } else { + showError(message); + } + }; + + useEffect(() => { + getOptions().then(); + }, []); const updateOption = async (key, value) => { setLoading(true); @@ -35,103 +56,37 @@ const OtherSetting = () => { setLoading(false); }; - const [loadingInput, setLoadingInput] = useState({ - Notice: false, - SystemName: false, - Logo: false, - HomePageContent: false, - About: false, - Footer: false - }); - const handleInputChange = async (value, e) => { - const name = e.target.id; + const handleInputChange = async (e, { name, value }) => { setInputs((inputs) => ({ ...inputs, [name]: value })); }; - // 通用设置 - const formAPISettingGeneral = useRef(); - // 通用设置 - Notice const submitNotice = async () => { - try { - setLoadingInput((loadingInput) => ({ ...loadingInput, Notice: true })); - await updateOption('Notice', inputs.Notice); - showSuccess('公告已更新'); - } catch (error) { - console.error('公告更新失败', error); - showError('公告更新失败'); - } finally { - setLoadingInput((loadingInput) => ({ ...loadingInput, Notice: false })); - } - }; - // 个性化设置 - const formAPIPersonalization = useRef(); - // 个性化设置 - SystemName - const submitSystemName = async () => { - try { - setLoadingInput((loadingInput) => ({ ...loadingInput, SystemName: true })); - await updateOption('SystemName', inputs.SystemName); - showSuccess('系统名称已更新'); - } catch (error) { - console.error('系统名称更新失败', error); - showError('系统名称更新失败'); - } finally { - setLoadingInput((loadingInput) => ({ ...loadingInput, SystemName: false })); - } + await updateOption('Notice', inputs.Notice); }; - // 个性化设置 - Logo - const submitLogo = async () => { - try { - setLoadingInput((loadingInput) => ({ ...loadingInput, Logo: true })); - await updateOption('Logo', inputs.Logo); - showSuccess('Logo 已更新'); - } catch (error) { - console.error('Logo 更新失败', error); - showError('Logo 更新失败'); - } finally { - setLoadingInput((loadingInput) => ({ ...loadingInput, Logo: false })); - } - }; - // 个性化设置 - 首页内容 - const submitOption = async (key) => { - try { - setLoadingInput((loadingInput) => ({ ...loadingInput, HomePageContent: true })); - await updateOption(key, inputs[key]); - showSuccess('首页内容已更新'); - } catch (error) { - console.error('首页内容更新失败', error); - showError('首页内容更新失败'); - } finally { - setLoadingInput((loadingInput) => ({ ...loadingInput, HomePageContent: false })); - } - }; - // 个性化设置 - 关于 - const submitAbout = async () => { - try { - setLoadingInput((loadingInput) => ({ ...loadingInput, About: true })); - await updateOption('About', inputs.About); - showSuccess('关于内容已更新'); - } catch (error) { - console.error('关于内容更新失败', error); - showError('关于内容更新失败'); - } finally { - setLoadingInput((loadingInput) => ({ ...loadingInput, About: false })); - } - }; - // 个性化设置 - 页脚 const submitFooter = async () => { - try { - setLoadingInput((loadingInput) => ({ ...loadingInput, Footer: true })); - await updateOption('Footer', inputs.Footer); - showSuccess('页脚内容已更新'); - } catch (error) { - console.error('页脚内容更新失败', error); - showError('页脚内容更新失败'); - } finally { - setLoadingInput((loadingInput) => ({ ...loadingInput, Footer: false })); - } + await updateOption('Footer', inputs.Footer); }; + const submitSystemName = async () => { + await updateOption('SystemName', inputs.SystemName); + }; + + const submitTheme = async () => { + await updateOption('Theme', inputs.Theme); + }; + + const submitLogo = async () => { + await updateOption('Logo', inputs.Logo); + }; + + const submitAbout = async () => { + await updateOption('About', inputs.About); + }; + + const submitOption = async (key) => { + await updateOption(key, inputs[key]); + }; const openGitHubRelease = () => { window.location = @@ -153,125 +108,117 @@ const OtherSetting = () => { setShowUpdateModal(true); } }; - const getOptions = async () => { - const res = await API.get('/api/option/'); - const { success, message, data } = res.data; - if (success) { - let newInputs = {}; - data.forEach((item) => { - if (item.key in inputs) { - newInputs[item.key] = item.value; - } - }); - setInputs(newInputs); - formAPISettingGeneral.current.setValues(newInputs); - formAPIPersonalization.current.setValues(newInputs); - } else { - showError(message); - } - }; - - useEffect(() => { - getOptions(); - }, []); - return ( - - - {/* 通用设置 */} -
formAPISettingGeneral.current = formAPI} - style={{ marginBottom: 15 }}> - + + + +
通用设置
+ 检查更新 + - -
+ + 保存公告 + +
个性化设置
+ + + + 设置系统名称 + + 主题名称(当前可用主题)} + placeholder='请输入主题名称' + value={inputs.Theme} + name='Theme' + onChange={handleInputChange} + /> + + 设置主题(重启生效) + + + + 设置 Logo + + + + submitOption('HomePageContent')}>保存首页内容 + + + + 保存关于 + 移除 One API + 的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目。 + + + + 设置页脚 - {/* 个性化设置 */} -
formAPIPersonalization.current = formAPI} - style={{ marginBottom: 15 }}> - - - - - - - - - - {/* */} - - - - -
- - {/* setShowUpdateModal(false)}*/} - {/* onOpen={() => setShowUpdateModal(true)}*/} - {/* open={showUpdateModal}*/} - {/*>*/} - {/* 新版本:{updateData.tag_name}*/} - {/* */} - {/* */} - {/*
*/} - {/*
*/} - {/*
*/} - {/* */} - {/* */} - {/* {*/} - {/* setShowUpdateModal(false);*/} - {/* openGitHubRelease();*/} - {/* }}*/} - {/* />*/} - {/* */} - {/**/} -
+ + setShowUpdateModal(false)} + onOpen={() => setShowUpdateModal(true)} + open={showUpdateModal} + > + 新版本:{updateData.tag_name} + + +
+
+
+ + + } @@ -478,8 +370,8 @@ const SystemSetting = () => { submitNewRestrictedDomain(); } }} - autoComplete="new-password" - placeholder="输入新的允许的邮箱域名" + autoComplete='new-password' + placeholder='输入新的允许的邮箱域名' value={restrictedDomainInput} onChange={(e, { value }) => { setRestrictedDomainInput(value); @@ -488,62 +380,62 @@ const SystemSetting = () => {
保存邮箱域名白名单设置 -
+
配置 SMTP 用以支持系统的邮件发送
保存 SMTP 设置 -
+
配置 GitHub OAuth App 用以支持通过 GitHub 进行登录注册, - + 点击此处 管理你的 GitHub OAuth App @@ -556,34 +448,34 @@ const SystemSetting = () => { 保存 GitHub OAuth 设置 -
+
配置 WeChat Server 用以支持通过微信进行登录注册, 点击此处 @@ -592,61 +484,76 @@ const SystemSetting = () => {
保存 WeChat Server 设置 -
配置 Telegram 登录
- +
+ 配置 Message Pusher + + 用以推送报警信息, + + 点击此处 + + 了解 Message Pusher + +
+ - - 保存 Telegram 登录设置 + + 保存 Message Pusher 设置 -
+
配置 Turnstile 用以支持用户校验, - + 点击此处 管理你的 Turnstile Sites,推荐选择 Invisible Widget Type @@ -654,21 +561,21 @@ const SystemSetting = () => {