2023-04-22 12:39:27 +00:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2023-06-17 03:03:01 +00:00
|
|
|
|
import { Button, Divider, Form, Grid, Header, Message, Modal } from 'semantic-ui-react';
|
2023-04-22 12:39:27 +00:00
|
|
|
|
import { API, showError, showSuccess } from '../helpers';
|
|
|
|
|
import { marked } from 'marked';
|
2024-01-07 09:53:05 +00:00
|
|
|
|
import { Link } from 'react-router-dom';
|
2023-04-22 12:39:27 +00:00
|
|
|
|
|
|
|
|
|
const OtherSetting = () => {
|
|
|
|
|
let [inputs, setInputs] = useState({
|
|
|
|
|
Footer: '',
|
|
|
|
|
Notice: '',
|
|
|
|
|
About: '',
|
2023-05-14 11:29:02 +00:00
|
|
|
|
SystemName: '',
|
|
|
|
|
Logo: '',
|
2024-01-07 09:53:05 +00:00
|
|
|
|
HomePageContent: '',
|
|
|
|
|
Theme: ''
|
2023-04-22 12:39:27 +00:00
|
|
|
|
});
|
|
|
|
|
let [loading, setLoading] = useState(false);
|
|
|
|
|
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
|
|
|
|
const [updateData, setUpdateData] = useState({
|
|
|
|
|
tag_name: '',
|
2023-06-17 03:03:01 +00:00
|
|
|
|
content: ''
|
2023-04-22 12:39:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const getOptions = async () => {
|
2023-05-16 02:04:39 +00:00
|
|
|
|
const res = await API.get('/api/option/');
|
2023-04-22 12:39:27 +00:00
|
|
|
|
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);
|
2023-05-16 02:04:39 +00:00
|
|
|
|
const res = await API.put('/api/option/', {
|
2023-04-22 12:39:27 +00:00
|
|
|
|
key,
|
2023-06-17 03:03:01 +00:00
|
|
|
|
value
|
2023-04-22 12:39:27 +00:00
|
|
|
|
});
|
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
if (success) {
|
|
|
|
|
setInputs((inputs) => ({ ...inputs, [key]: value }));
|
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
|
|
|
|
setLoading(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleInputChange = async (e, { name, value }) => {
|
|
|
|
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const submitNotice = async () => {
|
|
|
|
|
await updateOption('Notice', inputs.Notice);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const submitFooter = async () => {
|
|
|
|
|
await updateOption('Footer', inputs.Footer);
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-14 11:29:02 +00:00
|
|
|
|
const submitSystemName = async () => {
|
|
|
|
|
await updateOption('SystemName', inputs.SystemName);
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-07 09:53:05 +00:00
|
|
|
|
const submitTheme = async () => {
|
|
|
|
|
await updateOption('Theme', inputs.Theme);
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-14 11:29:02 +00:00
|
|
|
|
const submitLogo = async () => {
|
|
|
|
|
await updateOption('Logo', inputs.Logo);
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-22 12:39:27 +00:00
|
|
|
|
const submitAbout = async () => {
|
|
|
|
|
await updateOption('About', inputs.About);
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-13 13:27:49 +00:00
|
|
|
|
const submitOption = async (key) => {
|
|
|
|
|
await updateOption(key, inputs[key]);
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-22 12:39:27 +00:00
|
|
|
|
const openGitHubRelease = () => {
|
|
|
|
|
window.location =
|
2023-04-22 13:14:09 +00:00
|
|
|
|
'https://github.com/songquanpeng/one-api/releases/latest';
|
2023-04-22 12:39:27 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const checkUpdate = async () => {
|
|
|
|
|
const res = await API.get(
|
2023-04-22 13:14:09 +00:00
|
|
|
|
'https://api.github.com/repos/songquanpeng/one-api/releases/latest'
|
2023-04-22 12:39:27 +00:00
|
|
|
|
);
|
|
|
|
|
const { tag_name, body } = res.data;
|
|
|
|
|
if (tag_name === process.env.REACT_APP_VERSION) {
|
|
|
|
|
showSuccess(`已是最新版本:${tag_name}`);
|
|
|
|
|
} else {
|
|
|
|
|
setUpdateData({
|
|
|
|
|
tag_name: tag_name,
|
2023-06-17 03:03:01 +00:00
|
|
|
|
content: marked.parse(body)
|
2023-04-22 12:39:27 +00:00
|
|
|
|
});
|
|
|
|
|
setShowUpdateModal(true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Grid columns={1}>
|
|
|
|
|
<Grid.Column>
|
|
|
|
|
<Form loading={loading}>
|
|
|
|
|
<Header as='h3'>通用设置</Header>
|
|
|
|
|
<Form.Button onClick={checkUpdate}>检查更新</Form.Button>
|
|
|
|
|
<Form.Group widths='equal'>
|
|
|
|
|
<Form.TextArea
|
|
|
|
|
label='公告'
|
2023-08-12 02:49:30 +00:00
|
|
|
|
placeholder='在此输入新的公告内容,支持 Markdown & HTML 代码'
|
2023-04-22 12:39:27 +00:00
|
|
|
|
value={inputs.Notice}
|
|
|
|
|
name='Notice'
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
style={{ minHeight: 150, fontFamily: 'JetBrains Mono, Consolas' }}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Group>
|
|
|
|
|
<Form.Button onClick={submitNotice}>保存公告</Form.Button>
|
|
|
|
|
<Divider />
|
|
|
|
|
<Header as='h3'>个性化设置</Header>
|
2023-05-14 11:29:02 +00:00
|
|
|
|
<Form.Group widths='equal'>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='系统名称'
|
|
|
|
|
placeholder='在此输入系统名称'
|
|
|
|
|
value={inputs.SystemName}
|
|
|
|
|
name='SystemName'
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Group>
|
|
|
|
|
<Form.Button onClick={submitSystemName}>设置系统名称</Form.Button>
|
2024-01-07 09:53:05 +00:00
|
|
|
|
<Form.Group widths='equal'>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label={<label>主题名称(<Link
|
|
|
|
|
to='https://github.com/songquanpeng/one-api/blob/main/web/README.md'>当前可用主题</Link>)</label>}
|
|
|
|
|
placeholder='请输入主题名称'
|
|
|
|
|
value={inputs.Theme}
|
|
|
|
|
name='Theme'
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Group>
|
|
|
|
|
<Form.Button onClick={submitTheme}>设置主题(重启生效)</Form.Button>
|
2023-05-14 11:29:02 +00:00
|
|
|
|
<Form.Group widths='equal'>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='Logo 图片地址'
|
|
|
|
|
placeholder='在此输入 Logo 图片地址'
|
|
|
|
|
value={inputs.Logo}
|
|
|
|
|
name='Logo'
|
|
|
|
|
type='url'
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Group>
|
|
|
|
|
<Form.Button onClick={submitLogo}>设置 Logo</Form.Button>
|
2023-05-13 13:27:49 +00:00
|
|
|
|
<Form.Group widths='equal'>
|
|
|
|
|
<Form.TextArea
|
|
|
|
|
label='首页内容'
|
2023-05-14 08:01:04 +00:00
|
|
|
|
placeholder='在此输入首页内容,支持 Markdown & HTML 代码,设置后首页的状态信息将不再显示。如果输入的是一个链接,则会使用该链接作为 iframe 的 src 属性,这允许你设置任意网页作为首页。'
|
2023-05-13 13:27:49 +00:00
|
|
|
|
value={inputs.HomePageContent}
|
|
|
|
|
name='HomePageContent'
|
|
|
|
|
onChange={handleInputChange}
|
2023-05-14 10:58:54 +00:00
|
|
|
|
style={{ minHeight: 150, fontFamily: 'JetBrains Mono, Consolas' }}
|
2023-05-13 13:27:49 +00:00
|
|
|
|
/>
|
|
|
|
|
</Form.Group>
|
2023-06-17 03:03:01 +00:00
|
|
|
|
<Form.Button onClick={() => submitOption('HomePageContent')}>保存首页内容</Form.Button>
|
2023-04-22 12:39:27 +00:00
|
|
|
|
<Form.Group widths='equal'>
|
|
|
|
|
<Form.TextArea
|
|
|
|
|
label='关于'
|
2023-05-14 10:58:54 +00:00
|
|
|
|
placeholder='在此输入新的关于内容,支持 Markdown & HTML 代码。如果输入的是一个链接,则会使用该链接作为 iframe 的 src 属性,这允许你设置任意网页作为关于页面。'
|
2023-04-22 12:39:27 +00:00
|
|
|
|
value={inputs.About}
|
|
|
|
|
name='About'
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
style={{ minHeight: 150, fontFamily: 'JetBrains Mono, Consolas' }}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Group>
|
|
|
|
|
<Form.Button onClick={submitAbout}>保存关于</Form.Button>
|
2024-01-07 09:53:05 +00:00
|
|
|
|
<Message>移除 One API
|
|
|
|
|
的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目。</Message>
|
2023-04-22 12:39:27 +00:00
|
|
|
|
<Form.Group widths='equal'>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='页脚'
|
|
|
|
|
placeholder='在此输入新的页脚,留空则使用默认页脚,支持 HTML 代码'
|
|
|
|
|
value={inputs.Footer}
|
|
|
|
|
name='Footer'
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Group>
|
|
|
|
|
<Form.Button onClick={submitFooter}>设置页脚</Form.Button>
|
|
|
|
|
</Form>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Modal
|
|
|
|
|
onClose={() => setShowUpdateModal(false)}
|
|
|
|
|
onOpen={() => setShowUpdateModal(true)}
|
|
|
|
|
open={showUpdateModal}
|
|
|
|
|
>
|
|
|
|
|
<Modal.Header>新版本:{updateData.tag_name}</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
|
|
|
|
<Modal.Description>
|
|
|
|
|
<div dangerouslySetInnerHTML={{ __html: updateData.content }}></div>
|
|
|
|
|
</Modal.Description>
|
|
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
|
|
|
|
<Button onClick={() => setShowUpdateModal(false)}>关闭</Button>
|
|
|
|
|
<Button
|
|
|
|
|
content='详情'
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setShowUpdateModal(false);
|
|
|
|
|
openGitHubRelease();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Modal.Actions>
|
|
|
|
|
</Modal>
|
|
|
|
|
</Grid>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default OtherSetting;
|