Skip to content

Commit

Permalink
feat: 更方便地编辑用户额度
Browse files Browse the repository at this point in the history
  • Loading branch information
Calcium-Ion committed May 12, 2024
1 parent 6fb1fbf commit b427f02
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions web/src/pages/User/EditUser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { API, isMobile, showError, showSuccess } from '../../helpers';
import { renderQuotaWithPrompt } from '../../helpers/render';
import { renderQuota, renderQuotaWithPrompt } from '../../helpers/render';
import Title from '@douyinfe/semi-ui/lib/es/typography/title';
import {
Button,
Divider,
Input,
Modal,
Select,
SideSheet,
Space,
Expand All @@ -17,6 +18,8 @@ import {
const EditUser = (props) => {
const userId = props.editingUser.id;
const [loading, setLoading] = useState(true);
const [addQuotaModalOpen, setIsModalOpen] = useState(false);
const [addQuotaLocal, setAddQuotaLocal] = useState(0);
const [inputs, setInputs] = useState({
username: '',
display_name: '',
Expand Down Expand Up @@ -107,6 +110,16 @@ const EditUser = (props) => {
setLoading(false);
};

const addLocalQuota = () => {
let newQuota = parseInt(quota) + addQuotaLocal;
setInputs((inputs) => ({ ...inputs, quota: newQuota }));
};

const openAddQuotaModal = () => {
setAddQuotaLocal(0);
setIsModalOpen(true);
};

return (
<>
<SideSheet
Expand Down Expand Up @@ -192,14 +205,17 @@ const EditUser = (props) => {
<div style={{ marginTop: 20 }}>
<Typography.Text>{`剩余额度${renderQuotaWithPrompt(quota)}`}</Typography.Text>
</div>
<Input
name='quota'
placeholder={'请输入新的剩余额度'}
onChange={(value) => handleInputChange('quota', value)}
value={quota}
type={'number'}
autoComplete='new-password'
/>
<Space>
<Input
name='quota'
placeholder={'请输入新的剩余额度'}
onChange={(value) => handleInputChange('quota', value)}
value={quota}
type={'number'}
autoComplete='new-password'
/>
<Button onClick={openAddQuotaModal}>添加额度</Button>
</Space>
</>
)}
<Divider style={{ marginTop: 20 }}>以下信息不可修改</Divider>
Expand Down Expand Up @@ -245,6 +261,28 @@ const EditUser = (props) => {
/>
</Spin>
</SideSheet>
<Modal
centered={true}
visible={addQuotaModalOpen}
onOk={() => {
addLocalQuota();
setIsModalOpen(false);
}}
onCancel={() => setIsModalOpen(false)}
closable={null}
>
<div style={{ marginTop: 20 }}>
<Typography.Text>{`新额度${renderQuota(quota)} + ${renderQuota(addQuotaLocal)} = ${renderQuota(quota + addQuotaLocal)}`}</Typography.Text>
</div>
<Input
name='addQuotaLocal'
placeholder={'需要添加的额度'}
onChange={(value) => setAddQuotaLocal(parseInt(value))}
value={addQuotaLocal}
type={'number'}
autoComplete='new-password'
/>
</Modal>
</>
);
};
Expand Down

0 comments on commit b427f02

Please sign in to comment.