import React, { useState } from 'react'; import { API, isMobile, showError, showSuccess } from '../../helpers'; import Title from '@douyinfe/semi-ui/lib/es/typography/title'; import { Button, Input, SideSheet, Space, Spin } from '@douyinfe/semi-ui'; const AddUser = (props) => { const originInputs = { username: '', display_name: '', password: '', }; const [inputs, setInputs] = useState(originInputs); const [loading, setLoading] = useState(false); const { username, display_name, password } = inputs; const handleInputChange = (name, value) => { setInputs((inputs) => ({ ...inputs, [name]: value })); }; const submit = async () => { setLoading(true); if (inputs.username === '' || inputs.password === '') { setLoading(false); showError('用户名和密码不能为空!'); return; } const res = await API.post(`/api/user/`, inputs); const { success, message } = res.data; if (success) { showSuccess('用户账户创建成功!'); setInputs(originInputs); props.refresh(); props.handleClose(); } else { showError(message); } setLoading(false); }; const handleCancel = () => { props.handleClose(); }; return ( <> {'添加用户'}} headerStyle={{ borderBottom: '1px solid var(--semi-color-border)' }} bodyStyle={{ borderBottom: '1px solid var(--semi-color-border)' }} visible={props.visible} footer={
} closeIcon={null} onCancel={() => handleCancel()} width={isMobile() ? '100%' : 600} > handleInputChange('username', value)} value={username} autoComplete='off' /> handleInputChange('display_name', value)} value={display_name} /> handleInputChange('password', value)} value={password} autoComplete='off' />
); }; export default AddUser;