import { useState, useEffect } from 'react';
import SubCard from 'ui-component/cards/SubCard';
import {
Stack,
FormControl,
InputLabel,
OutlinedInput,
Button,
Alert,
TextField,
Dialog,
DialogTitle,
DialogActions,
DialogContent,
Divider
} from '@mui/material';
import Grid from '@mui/material/Unstable_Grid2';
import { showError, showSuccess } from 'utils/common'; //,
import { API } from 'utils/api';
import { marked } from 'marked';
const OtherSetting = () => {
let [inputs, setInputs] = useState({
Footer: '',
Notice: '',
About: '',
SystemName: '',
Logo: '',
HomePageContent: ''
});
let [loading, setLoading] = useState(false);
const [showUpdateModal, setShowUpdateModal] = useState(false);
const [updateData, setUpdateData] = useState({
tag_name: '',
content: ''
});
const getOptions = async () => {
try {
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);
}
} catch (error) {
return;
}
};
useEffect(() => {
getOptions().then();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const updateOption = async (key, value) => {
setLoading(true);
try {
const res = await API.put('/api/option/', {
key,
value
});
const { success, message } = res.data;
if (success) {
setInputs((inputs) => ({ ...inputs, [key]: value }));
showSuccess('保存成功');
} else {
showError(message);
}
setLoading(false);
} catch (error) {
return;
}
};
const handleInputChange = async (event) => {
let { name, value } = event.target;
setInputs((inputs) => ({ ...inputs, [name]: value }));
};
const submitNotice = async () => {
await updateOption('Notice', inputs.Notice);
};
const submitFooter = async () => {
await updateOption('Footer', inputs.Footer);
};
const submitSystemName = async () => {
await updateOption('SystemName', inputs.SystemName);
};
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 = 'https://github.com/MartialBE/one-api/releases/latest';
};
const checkUpdate = async () => {
try {
const res = await API.get('https://api.github.com/repos/MartialBE/one-api/releases/latest');
const { tag_name, body } = res.data;
if (tag_name === process.env.REACT_APP_VERSION) {
showSuccess(`已是最新版本:${tag_name}`);
} else {
setUpdateData({
tag_name: tag_name,
content: marked.parse(body)
});
setShowUpdateModal(true);
}
} catch (error) {
return;
}
};
return (
<>
系统名称
Logo 图片地址
移除 One API 的版权标识必须首先获得授权,项目维护需要花费大量精力,如果本项目对你有意义,请主动支持本项目。
>
);
};
export default OtherSetting;