mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-12 19:33:41 +08:00
feat: berry theme update & bug fix (#1282)
* ⚡️ improve: delete google fonts * ⚡️ improve: Optimized priority input handling in TableRow component. * 🔖 chore: channel batch add * ✨ feat: add dark mod * ✨ feat: support token limit ip range and models * ✨ feat: add MessagePusher * ✨ feat: add lark login
This commit is contained in:
@@ -21,15 +21,16 @@ import {
|
||||
Container,
|
||||
Autocomplete,
|
||||
FormHelperText,
|
||||
Checkbox
|
||||
Switch,
|
||||
Checkbox,
|
||||
} from "@mui/material";
|
||||
|
||||
import { Formik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import { defaultConfig, typeConfig } from "../type/Config"; //typeConfig
|
||||
import { createFilterOptions } from "@mui/material/Autocomplete";
|
||||
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
|
||||
import CheckBoxIcon from '@mui/icons-material/CheckBox';
|
||||
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank";
|
||||
import CheckBoxIcon from "@mui/icons-material/CheckBox";
|
||||
|
||||
const icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
|
||||
const checkedIcon = <CheckBoxIcon fontSize="small" />;
|
||||
@@ -79,6 +80,7 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
const [inputPrompt, setInputPrompt] = useState(defaultConfig.prompt);
|
||||
const [groupOptions, setGroupOptions] = useState([]);
|
||||
const [modelOptions, setModelOptions] = useState([]);
|
||||
const [batchAdd, setBatchAdd] = useState(false);
|
||||
|
||||
const initChannel = (typeValue) => {
|
||||
if (typeConfig[typeValue]?.inputLabel) {
|
||||
@@ -151,7 +153,7 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
try {
|
||||
let res = await API.get(`/api/channel/models`);
|
||||
const { data } = res.data;
|
||||
data.forEach(item => {
|
||||
data.forEach((item) => {
|
||||
if (!item.owned_by) {
|
||||
item.owned_by = "未知";
|
||||
}
|
||||
@@ -166,7 +168,7 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
});
|
||||
|
||||
setModelOptions(
|
||||
data.map((model) => {
|
||||
data.map((model) => {
|
||||
return {
|
||||
id: model.id,
|
||||
group: model.owned_by,
|
||||
@@ -258,7 +260,7 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
2
|
||||
);
|
||||
}
|
||||
data.base_url = data.base_url ?? '';
|
||||
data.base_url = data.base_url ?? "";
|
||||
data.is_edit = true;
|
||||
initChannel(data.type);
|
||||
setInitialInput(data);
|
||||
@@ -273,6 +275,7 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setBatchAdd(false);
|
||||
if (channelId) {
|
||||
loadChannel().then();
|
||||
} else {
|
||||
@@ -340,15 +343,17 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
},
|
||||
}}
|
||||
>
|
||||
{Object.values(CHANNEL_OPTIONS).sort((a, b) => {
|
||||
return a.text.localeCompare(b.text)
|
||||
}).map((option) => {
|
||||
return (
|
||||
<MenuItem key={option.value} value={option.value}>
|
||||
{option.text}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
{Object.values(CHANNEL_OPTIONS)
|
||||
.sort((a, b) => {
|
||||
return a.text.localeCompare(b.text);
|
||||
})
|
||||
.map((option) => {
|
||||
return (
|
||||
<MenuItem key={option.value} value={option.value}>
|
||||
{option.text}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
{touched.type && errors.type ? (
|
||||
<FormHelperText error id="helper-tex-channel-type-label">
|
||||
@@ -553,7 +558,12 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
}}
|
||||
renderOption={(props, option, { selected }) => (
|
||||
<li {...props}>
|
||||
<Checkbox icon={icon} checkedIcon={checkedIcon} style={{ marginRight: 8 }} checked={selected} />
|
||||
<Checkbox
|
||||
icon={icon}
|
||||
checkedIcon={checkedIcon}
|
||||
style={{ marginRight: 8 }}
|
||||
checked={selected}
|
||||
/>
|
||||
{option.id}
|
||||
</li>
|
||||
)}
|
||||
@@ -599,20 +609,38 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
error={Boolean(touched.key && errors.key)}
|
||||
sx={{ ...theme.typography.otherInput }}
|
||||
>
|
||||
<InputLabel htmlFor="channel-key-label">
|
||||
{inputLabel.key}
|
||||
</InputLabel>
|
||||
<OutlinedInput
|
||||
id="channel-key-label"
|
||||
label={inputLabel.key}
|
||||
type="text"
|
||||
value={values.key}
|
||||
name="key"
|
||||
onBlur={handleBlur}
|
||||
onChange={handleChange}
|
||||
inputProps={{}}
|
||||
aria-describedby="helper-text-channel-key-label"
|
||||
/>
|
||||
{!batchAdd ? (
|
||||
<>
|
||||
<InputLabel htmlFor="channel-key-label">
|
||||
{inputLabel.key}
|
||||
</InputLabel>
|
||||
<OutlinedInput
|
||||
id="channel-key-label"
|
||||
label={inputLabel.key}
|
||||
type="text"
|
||||
value={values.key}
|
||||
name="key"
|
||||
onBlur={handleBlur}
|
||||
onChange={handleChange}
|
||||
inputProps={{}}
|
||||
aria-describedby="helper-text-channel-key-label"
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<TextField
|
||||
multiline
|
||||
id="channel-key-label"
|
||||
label={inputLabel.key}
|
||||
value={values.key}
|
||||
name="key"
|
||||
onBlur={handleBlur}
|
||||
onChange={handleChange}
|
||||
aria-describedby="helper-text-channel-key-label"
|
||||
minRows={5}
|
||||
placeholder={inputPrompt.key + ",一行一个密钥"}
|
||||
/>
|
||||
)}
|
||||
|
||||
{touched.key && errors.key ? (
|
||||
<FormHelperText error id="helper-tex-channel-key-label">
|
||||
{errors.key}
|
||||
@@ -624,6 +652,19 @@ const EditModal = ({ open, channelId, onCancel, onOk }) => {
|
||||
</FormHelperText>
|
||||
)}
|
||||
</FormControl>
|
||||
{channelId === 0 && (
|
||||
<Container
|
||||
sx={{
|
||||
textAlign: "right",
|
||||
}}
|
||||
>
|
||||
<Switch
|
||||
checked={batchAdd}
|
||||
onChange={(e) => setBatchAdd(e.target.checked)}
|
||||
/>
|
||||
批量添加
|
||||
</Container>
|
||||
)}
|
||||
<FormControl
|
||||
fullWidth
|
||||
error={Boolean(touched.model_mapping && errors.model_mapping)}
|
||||
|
||||
@@ -11,10 +11,7 @@ import {
|
||||
MenuItem,
|
||||
TableCell,
|
||||
IconButton,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
InputAdornment,
|
||||
Input,
|
||||
TextField,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
@@ -31,12 +28,7 @@ import ResponseTimeLabel from "./ResponseTimeLabel";
|
||||
import GroupLabel from "./GroupLabel";
|
||||
import NameLabel from "./NameLabel";
|
||||
|
||||
import {
|
||||
IconDotsVertical,
|
||||
IconEdit,
|
||||
IconTrash,
|
||||
IconPencil,
|
||||
} from "@tabler/icons-react";
|
||||
import { IconDotsVertical, IconEdit, IconTrash } from "@tabler/icons-react";
|
||||
|
||||
export default function ChannelTableRow({
|
||||
item,
|
||||
@@ -79,11 +71,19 @@ export default function ChannelTableRow({
|
||||
}
|
||||
};
|
||||
|
||||
const handlePriority = async () => {
|
||||
if (priorityValve === "" || priorityValve === item.priority) {
|
||||
const handlePriority = async (event) => {
|
||||
const currentValue = parseInt(event.target.value);
|
||||
if (isNaN(currentValue) || currentValue === priorityValve) {
|
||||
return;
|
||||
}
|
||||
await manageChannel(item.id, "priority", priorityValve);
|
||||
|
||||
if (currentValue < 0) {
|
||||
showError("优先级不能小于 0");
|
||||
return;
|
||||
}
|
||||
|
||||
await manageChannel(item.id, "priority", currentValue);
|
||||
setPriority(currentValue);
|
||||
};
|
||||
|
||||
const handleResponseTime = async () => {
|
||||
@@ -170,9 +170,7 @@ export default function ChannelTableRow({
|
||||
handle_action={handleResponseTime}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{renderNumber(item.used_quota)}
|
||||
</TableCell>
|
||||
<TableCell>{renderNumber(item.used_quota)}</TableCell>
|
||||
<TableCell>
|
||||
<Tooltip
|
||||
title={"点击更新余额"}
|
||||
@@ -183,27 +181,16 @@ export default function ChannelTableRow({
|
||||
</Tooltip>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<FormControl sx={{ m: 1, width: "70px" }} variant="standard">
|
||||
<InputLabel htmlFor={`priority-${item.id}`}>优先级</InputLabel>
|
||||
<Input
|
||||
id={`priority-${item.id}`}
|
||||
type="text"
|
||||
value={priorityValve}
|
||||
onChange={(e) => setPriority(e.target.value)}
|
||||
sx={{ textAlign: "center" }}
|
||||
endAdornment={
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
onClick={handlePriority}
|
||||
sx={{ color: "rgb(99, 115, 129)" }}
|
||||
size="small"
|
||||
>
|
||||
<IconPencil />
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<TextField
|
||||
id={`priority-${item.id}`}
|
||||
onBlur={handlePriority}
|
||||
type="number"
|
||||
label="优先级"
|
||||
variant="standard"
|
||||
defaultValue={item.priority}
|
||||
inputProps={{ min: "0" }}
|
||||
sx={{ width: 80 }}
|
||||
/>
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
|
||||
Reference in New Issue
Block a user