add token limit

This commit is contained in:
sijinhui 2024-08-31 00:58:41 +08:00
parent 48cf006f83
commit 529ccbc2fa
3 changed files with 31 additions and 6 deletions

View File

@ -25,7 +25,11 @@ async function handle(
id: user_id, id: user_id,
}, },
}); });
if (current_user && current_user.everyLimitToken !== 0) { if (
current_user &&
current_user.everyLimitToken &&
current_user.everyLimitToken > 0
) {
current_day_limit_token = current_user.everyLimitToken * 1000; current_day_limit_token = current_user.everyLimitToken * 1000;
} else { } else {
current_day_limit_token = 0; current_day_limit_token = 0;

View File

@ -6,6 +6,7 @@ import {
Space, Space,
Table, Table,
Input, Input,
InputNumber,
Button, Button,
notification as notificationModule, notification as notificationModule,
Checkbox, Checkbox,
@ -127,6 +128,9 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
<Form.Item name="emailVerified" label="emailVerified"> <Form.Item name="emailVerified" label="emailVerified">
<Input disabled /> <Input disabled />
</Form.Item> </Form.Item>
<Form.Item name="everyLimitToken" label="每日限额">
<InputNumber addonAfter={"k"} />
</Form.Item>
<Form.Item name="createdAt" label="createdAt"> <Form.Item name="createdAt" label="createdAt">
<Input disabled /> <Input disabled />
</Form.Item> </Form.Item>
@ -163,6 +167,7 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
allowToLogin: values.allowToLogin ?? true, allowToLogin: values.allowToLogin ?? true,
isAdmin: values.isAdmin ?? false, isAdmin: values.isAdmin ?? false,
password: values.password ?? null, password: values.password ?? null,
everyLimitToken: values.everyLimitToken ?? 0,
}; };
fetch(`/api/admin/users/${values.id}`, { fetch(`/api/admin/users/${values.id}`, {
method: method, method: method,
@ -228,13 +233,20 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
}); });
}; };
const columns: TableColumnsType<User> = [ const columns: TableColumnsType<User> = [
{ title: "姓名", dataIndex: "name", width: 80 }, { title: "姓名", dataIndex: "name", width: 80, align: "center" },
{ {
title: "用户名", title: "用户名",
dataIndex: "username", dataIndex: "username",
width: 80, width: 80,
align: "center",
},
{ title: "邮箱", dataIndex: "email", width: 180, align: "right" },
{
title: "每日限额",
dataIndex: "everyLimitToken",
width: 60,
align: "right",
}, },
{ title: "邮箱", dataIndex: "email", width: 180 },
{ {
title: "createdAt", title: "createdAt",
dataIndex: "createdAt", dataIndex: "createdAt",
@ -301,7 +313,7 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
<Table <Table
dataSource={users} dataSource={users}
rowKey="id" rowKey="id"
size="middle" size="small"
columns={columns} columns={columns}
loading={loading as boolean} loading={loading as boolean}
scroll={{ scroll={{

View File

@ -1478,7 +1478,13 @@ function _Chat() {
title={ title={
<span style={{ color: "black" }}> <span style={{ color: "black" }}>
{localStorage.getItem("current_day_token") ?? 0}{" "} {localStorage.getItem("current_day_token") ?? 0}{" "}
<span style={{ color: "black" }}>/ 200000</span> <span style={{ color: "black" }}>
/{" "}
{parseInt(
localStorage.getItem("current_day_limit_token") ??
"200000",
)}
</span>
</span> </span>
} }
color={"var(--second)"} color={"var(--second)"}
@ -1488,7 +1494,10 @@ function _Chat() {
<Progress <Progress
percent={ percent={
(parseInt(localStorage.getItem("current_day_token") ?? "0") / (parseInt(localStorage.getItem("current_day_token") ?? "0") /
parseInt(localStorage.getItem("limit_token") ?? "200000")) * parseInt(
localStorage.getItem("current_day_limit_token") ??
"200000",
)) *
100 100
} }
size="small" size="small"