mirror of
https://github.com/PlayEdu/backend
synced 2025-06-09 00:44:08 +08:00
学员添加和编辑
This commit is contained in:
parent
86eb59622d
commit
04effd9df8
BIN
public/avatar/avatar.png
Normal file
BIN
public/avatar/avatar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
@ -232,8 +232,9 @@ code {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.form-avatar {
|
.form-avatar {
|
||||||
width: 100px;
|
width: 60px;
|
||||||
height: 100px;
|
height: 60px;
|
||||||
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-course-thumb {
|
.form-course-thumb {
|
||||||
|
@ -3,6 +3,7 @@ import { Modal, Form, Cascader, Input, message } from "antd";
|
|||||||
import styles from "./create.module.less";
|
import styles from "./create.module.less";
|
||||||
import { user, department } from "../../../api/index";
|
import { user, department } from "../../../api/index";
|
||||||
import { UploadImageButton } from "../../../compenents";
|
import { UploadImageButton } from "../../../compenents";
|
||||||
|
import { ValidataCredentials, getHost } from "../../../utils/index";
|
||||||
|
|
||||||
interface PropInterface {
|
interface PropInterface {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@ -19,7 +20,7 @@ export const MemberCreate: React.FC<PropInterface> = ({ open, onCancel }) => {
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
const [departments, setDepartments] = useState<any>([]);
|
const [departments, setDepartments] = useState<any>([]);
|
||||||
const [avatar, setAvatar] = useState<string>("");
|
const [avatar, setAvatar] = useState<string>(getHost() + "avatar/avatar.png");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getParams();
|
getParams();
|
||||||
@ -30,11 +31,11 @@ export const MemberCreate: React.FC<PropInterface> = ({ open, onCancel }) => {
|
|||||||
email: "",
|
email: "",
|
||||||
name: "",
|
name: "",
|
||||||
password: "",
|
password: "",
|
||||||
avatar: "",
|
avatar: getHost() + "avatar/avatar.png",
|
||||||
idCard: "",
|
idCard: "",
|
||||||
dep_ids: [],
|
dep_ids: [],
|
||||||
});
|
});
|
||||||
setAvatar("");
|
setAvatar(getHost() + "avatar/avatar.png");
|
||||||
}, [form, open]);
|
}, [form, open]);
|
||||||
|
|
||||||
const getParams = () => {
|
const getParams = () => {
|
||||||
@ -68,6 +69,10 @@ export const MemberCreate: React.FC<PropInterface> = ({ open, onCancel }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onFinish = (values: any) => {
|
const onFinish = (values: any) => {
|
||||||
|
if (!ValidataCredentials(values.idCard)) {
|
||||||
|
message.error("请输入正确的身份证号!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const arr = [];
|
const arr = [];
|
||||||
for (let i = 0; i < values.dep_ids.length; i++) {
|
for (let i = 0; i < values.dep_ids.length; i++) {
|
||||||
arr.push(values.dep_ids[i][values.dep_ids[i].length - 1]);
|
arr.push(values.dep_ids[i][values.dep_ids[i].length - 1]);
|
||||||
@ -100,16 +105,16 @@ export const MemberCreate: React.FC<PropInterface> = ({ open, onCancel }) => {
|
|||||||
centered
|
centered
|
||||||
forceRender
|
forceRender
|
||||||
open={open}
|
open={open}
|
||||||
width={416}
|
width={484}
|
||||||
onOk={() => form.submit()}
|
onOk={() => form.submit()}
|
||||||
onCancel={() => onCancel()}
|
onCancel={() => onCancel()}
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
>
|
>
|
||||||
<div className="float-left mt-24">
|
<div className="member-form float-left mt-24">
|
||||||
<Form
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
name="create-basic"
|
name="create-basic"
|
||||||
labelCol={{ span: 8 }}
|
labelCol={{ span: 7 }}
|
||||||
wrapperCol={{ span: 16 }}
|
wrapperCol={{ span: 16 }}
|
||||||
initialValues={{ remember: true }}
|
initialValues={{ remember: true }}
|
||||||
onFinish={onFinish}
|
onFinish={onFinish}
|
||||||
@ -117,18 +122,15 @@ export const MemberCreate: React.FC<PropInterface> = ({ open, onCancel }) => {
|
|||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="姓名"
|
label="学员头像"
|
||||||
name="name"
|
labelCol={{ style: { marginTop: 15, marginLeft: 46 } }}
|
||||||
rules={[{ required: true, message: "请输入姓名!" }]}
|
|
||||||
>
|
|
||||||
<Input style={{ width: 200 }} placeholder="请输入姓名" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
label="头像"
|
|
||||||
name="avatar"
|
name="avatar"
|
||||||
rules={[{ required: true, message: "请上传头像!" }]}
|
rules={[{ required: true, message: "请上传学员头像!" }]}
|
||||||
>
|
>
|
||||||
<div className="c-flex">
|
<div className="d-flex">
|
||||||
|
{avatar && (
|
||||||
|
<img className="form-avatar mr-16" src={avatar} alt="" />
|
||||||
|
)}
|
||||||
<div className="d-flex">
|
<div className="d-flex">
|
||||||
<UploadImageButton
|
<UploadImageButton
|
||||||
onSelected={(url) => {
|
onSelected={(url) => {
|
||||||
@ -137,45 +139,49 @@ export const MemberCreate: React.FC<PropInterface> = ({ open, onCancel }) => {
|
|||||||
}}
|
}}
|
||||||
></UploadImageButton>
|
></UploadImageButton>
|
||||||
</div>
|
</div>
|
||||||
{avatar && (
|
|
||||||
<img className="form-avatar mt-10" src={avatar} alt="" />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label="学员姓名"
|
||||||
|
name="name"
|
||||||
|
rules={[{ required: true, message: "请输入学员姓名!" }]}
|
||||||
|
>
|
||||||
|
<Input style={{ width: 274 }} placeholder="请填写学员姓名" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label="登录邮箱"
|
||||||
|
name="email"
|
||||||
|
rules={[{ required: true, message: "请输入登录邮箱!" }]}
|
||||||
|
>
|
||||||
|
<Input style={{ width: 274 }} placeholder="请输入学员登录邮箱" />
|
||||||
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="登录密码"
|
label="登录密码"
|
||||||
name="password"
|
name="password"
|
||||||
rules={[{ required: true, message: "请输入登录密码!" }]}
|
rules={[{ required: true, message: "请输入登录密码!" }]}
|
||||||
>
|
>
|
||||||
<Input.Password
|
<Input.Password
|
||||||
style={{ width: 200 }}
|
style={{ width: 274 }}
|
||||||
placeholder="请输入登录密码"
|
placeholder="请输入登录密码"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="邮箱"
|
label="所属部门"
|
||||||
name="email"
|
|
||||||
rules={[{ required: true, message: "请输入邮箱!" }]}
|
|
||||||
>
|
|
||||||
<Input style={{ width: 200 }} placeholder="请输入邮箱" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item label="身份证号" name="idCard">
|
|
||||||
<Input style={{ width: 200 }} placeholder="请输入身份证号" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
label="部门"
|
|
||||||
name="dep_ids"
|
name="dep_ids"
|
||||||
rules={[{ required: true, message: "请选择部门!" }]}
|
rules={[{ required: true, message: "请选择学员所属部门!" }]}
|
||||||
>
|
>
|
||||||
<Cascader
|
<Cascader
|
||||||
style={{ width: 200 }}
|
style={{ width: 274 }}
|
||||||
options={departments}
|
options={departments}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
multiple
|
multiple
|
||||||
maxTagCount="responsive"
|
maxTagCount="responsive"
|
||||||
placeholder="请选择部门"
|
placeholder="请选择学员所属部门"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item label="身份证号" name="idCard">
|
||||||
|
<Input style={{ width: 274 }} placeholder="请填写学员身份证号" />
|
||||||
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@ -3,6 +3,7 @@ import { Modal, Form, Cascader, Input, message } from "antd";
|
|||||||
import styles from "./create.module.less";
|
import styles from "./create.module.less";
|
||||||
import { user, department } from "../../../api/index";
|
import { user, department } from "../../../api/index";
|
||||||
import { UploadImageButton } from "../../../compenents";
|
import { UploadImageButton } from "../../../compenents";
|
||||||
|
import { ValidataCredentials, getHost } from "../../../utils/index";
|
||||||
|
|
||||||
interface PropInterface {
|
interface PropInterface {
|
||||||
id: number;
|
id: number;
|
||||||
@ -24,7 +25,7 @@ export const MemberUpdate: React.FC<PropInterface> = ({
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
const [departments, setDepartments] = useState<any>([]);
|
const [departments, setDepartments] = useState<any>([]);
|
||||||
const [avatar, setAvatar] = useState<string>("");
|
const [avatar, setAvatar] = useState<string>(getHost() + "avatar/avatar.png");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getParams();
|
getParams();
|
||||||
@ -117,6 +118,10 @@ export const MemberUpdate: React.FC<PropInterface> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onFinish = (values: any) => {
|
const onFinish = (values: any) => {
|
||||||
|
if (!ValidataCredentials(values.idCard)) {
|
||||||
|
message.error("请输入正确的身份证号!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const arr = [];
|
const arr = [];
|
||||||
for (let i = 0; i < values.dep_ids.length; i++) {
|
for (let i = 0; i < values.dep_ids.length; i++) {
|
||||||
if (Array.isArray(values.dep_ids[i])) {
|
if (Array.isArray(values.dep_ids[i])) {
|
||||||
@ -154,7 +159,7 @@ export const MemberUpdate: React.FC<PropInterface> = ({
|
|||||||
centered
|
centered
|
||||||
forceRender
|
forceRender
|
||||||
open={open}
|
open={open}
|
||||||
width={416}
|
width={484}
|
||||||
onOk={() => form.submit()}
|
onOk={() => form.submit()}
|
||||||
onCancel={() => onCancel()}
|
onCancel={() => onCancel()}
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
@ -171,18 +176,15 @@ export const MemberUpdate: React.FC<PropInterface> = ({
|
|||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="姓名"
|
label="学员头像"
|
||||||
name="name"
|
labelCol={{ style: { marginTop: 15, marginLeft: 46 } }}
|
||||||
rules={[{ required: true, message: "请输入姓名!" }]}
|
|
||||||
>
|
|
||||||
<Input style={{ width: 200 }} placeholder="请输入姓名" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
label="头像"
|
|
||||||
name="avatar"
|
name="avatar"
|
||||||
rules={[{ required: true, message: "请上传头像!" }]}
|
rules={[{ required: true, message: "请上传学员头像!" }]}
|
||||||
>
|
>
|
||||||
<div className="c-flex">
|
<div className="d-flex">
|
||||||
|
{avatar && (
|
||||||
|
<img className="form-avatar mr-16" src={avatar} alt="" />
|
||||||
|
)}
|
||||||
<div className="d-flex">
|
<div className="d-flex">
|
||||||
<UploadImageButton
|
<UploadImageButton
|
||||||
onSelected={(url) => {
|
onSelected={(url) => {
|
||||||
@ -191,41 +193,45 @@ export const MemberUpdate: React.FC<PropInterface> = ({
|
|||||||
}}
|
}}
|
||||||
></UploadImageButton>
|
></UploadImageButton>
|
||||||
</div>
|
</div>
|
||||||
{avatar && (
|
|
||||||
<img className="form-avatar mt-10" src={avatar} alt="" />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label="学员姓名"
|
||||||
|
name="name"
|
||||||
|
rules={[{ required: true, message: "请输入学员姓名!" }]}
|
||||||
|
>
|
||||||
|
<Input style={{ width: 274 }} placeholder="请填写学员姓名" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label="登录邮箱"
|
||||||
|
name="email"
|
||||||
|
rules={[{ required: true, message: "请输入登录邮箱!" }]}
|
||||||
|
>
|
||||||
|
<Input style={{ width: 274 }} placeholder="请输入学员登录邮箱" />
|
||||||
|
</Form.Item>
|
||||||
<Form.Item label="登录密码" name="password">
|
<Form.Item label="登录密码" name="password">
|
||||||
<Input.Password
|
<Input.Password
|
||||||
style={{ width: 200 }}
|
style={{ width: 274 }}
|
||||||
placeholder="请输入登录密码"
|
placeholder="请输入登录密码"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="邮箱"
|
label="所属部门"
|
||||||
name="email"
|
|
||||||
rules={[{ required: true, message: "请输入邮箱!" }]}
|
|
||||||
>
|
|
||||||
<Input style={{ width: 200 }} placeholder="请输入邮箱" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item label="身份证号" name="idCard">
|
|
||||||
<Input style={{ width: 200 }} placeholder="请输入身份证号" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
label="部门"
|
|
||||||
name="dep_ids"
|
name="dep_ids"
|
||||||
rules={[{ required: true, message: "请选择部门!" }]}
|
rules={[{ required: true, message: "请选择学员所属部门!" }]}
|
||||||
>
|
>
|
||||||
<Cascader
|
<Cascader
|
||||||
style={{ width: 200 }}
|
style={{ width: 274 }}
|
||||||
options={departments}
|
options={departments}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
multiple
|
multiple
|
||||||
maxTagCount="responsive"
|
maxTagCount="responsive"
|
||||||
placeholder="请选择部门"
|
placeholder="请选择学员所属部门"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item label="身份证号" name="idCard">
|
||||||
|
<Input style={{ width: 274 }} placeholder="请填写学员身份证号" />
|
||||||
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
@ -87,3 +87,53 @@ export function inStrArray(array: string[], value: string): boolean {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ValidataCredentials(value: any) {
|
||||||
|
let regIdCard =
|
||||||
|
/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
|
||||||
|
if (regIdCard.test(value)) {
|
||||||
|
if (value.length == 18) {
|
||||||
|
var idCardWi = new Array(
|
||||||
|
7,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
5,
|
||||||
|
8,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
6,
|
||||||
|
3,
|
||||||
|
7,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
5,
|
||||||
|
8,
|
||||||
|
4,
|
||||||
|
2
|
||||||
|
); //将前17位加权因子保存在数组里
|
||||||
|
var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2); //这是除以11后,可能产生的11位余数、验证码,也保存成数组
|
||||||
|
var idCardWiSum = 0; //用来保存前17位各自乖以加权因子后的总和
|
||||||
|
for (var i = 0; i < 17; i++) {
|
||||||
|
idCardWiSum += value.substring(i, i + 1) * idCardWi[i];
|
||||||
|
}
|
||||||
|
var idCardMod = idCardWiSum % 11; //计算出校验码所在数组的位置
|
||||||
|
var idCardLast = value.substring(17); //得到最后一位身份证号码
|
||||||
|
//如果等于2,则说明校验码是10,身份证号码最后一位应该是X
|
||||||
|
if (idCardMod == 2) {
|
||||||
|
if (idCardLast == "X" || idCardLast == "x") {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码
|
||||||
|
if (idCardLast == idCardY[idCardMod]) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user