mirror of
https://github.com/PlayEdu/backend
synced 2025-06-22 04:02:47 +08:00
学员新建、编辑窗口化
This commit is contained in:
parent
d3422f877f
commit
ebaee809eb
@ -7,8 +7,6 @@ export * from "./course/index";
|
||||
export * from "./course/create";
|
||||
export * from "./course/update";
|
||||
export * from "./member/index";
|
||||
export * from "./member/create";
|
||||
export * from "./member/update";
|
||||
export * from "./member/import";
|
||||
export * from "./system/index";
|
||||
export * from "./system/administrator/index";
|
||||
|
184
src/pages/member/compenents/create.tsx
Normal file
184
src/pages/member/compenents/create.tsx
Normal file
@ -0,0 +1,184 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Modal, Form, Cascader, Input, message } from "antd";
|
||||
import styles from "./create.module.less";
|
||||
import { user, department } from "../../../api/index";
|
||||
import { UploadImageButton } from "../../../compenents";
|
||||
|
||||
interface PropInterface {
|
||||
open: boolean;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
interface Option {
|
||||
value: string | number;
|
||||
label: string;
|
||||
children?: Option[];
|
||||
}
|
||||
|
||||
export const MemberCreate: React.FC<PropInterface> = ({ open, onCancel }) => {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [departments, setDepartments] = useState<any>([]);
|
||||
const [avatar, setAvatar] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
getParams();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
form.setFieldsValue({
|
||||
email: "",
|
||||
name: "",
|
||||
password: "",
|
||||
avatar: "",
|
||||
idCard: "",
|
||||
dep_ids: [],
|
||||
});
|
||||
setAvatar("");
|
||||
}, [form, open]);
|
||||
|
||||
const getParams = () => {
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments = res.data.departments;
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(departments, 0);
|
||||
setDepartments(new_arr);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const checkArr = (departments: any[], id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < departments[id].length; i++) {
|
||||
if (!departments[departments[id][i].id]) {
|
||||
arr.push({
|
||||
label: departments[id][i].name,
|
||||
value: departments[id][i].id,
|
||||
});
|
||||
} else {
|
||||
const new_arr: Option[] = checkArr(departments, departments[id][i].id);
|
||||
arr.push({
|
||||
label: departments[id][i].name,
|
||||
value: departments[id][i].id,
|
||||
children: new_arr,
|
||||
});
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
const onFinish = (values: any) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < values.dep_ids.length; i++) {
|
||||
arr.push(values.dep_ids[i][values.dep_ids[i].length - 1]);
|
||||
}
|
||||
user
|
||||
.storeUser(
|
||||
values.email,
|
||||
values.name,
|
||||
values.avatar,
|
||||
values.password,
|
||||
values.idCard,
|
||||
arr
|
||||
)
|
||||
.then((res: any) => {
|
||||
message.success("保存成功!");
|
||||
onCancel();
|
||||
});
|
||||
};
|
||||
|
||||
const onFinishFailed = (errorInfo: any) => {
|
||||
console.log("Failed:", errorInfo);
|
||||
};
|
||||
|
||||
const onChange = (value: any) => {};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
title="添加学员"
|
||||
centered
|
||||
forceRender
|
||||
open={open}
|
||||
width={416}
|
||||
onOk={() => form.submit()}
|
||||
onCancel={() => onCancel()}
|
||||
maskClosable={false}
|
||||
>
|
||||
<div className="float-left mt-24">
|
||||
<Form
|
||||
form={form}
|
||||
name="basic"
|
||||
labelCol={{ span: 8 }}
|
||||
wrapperCol={{ span: 16 }}
|
||||
initialValues={{ remember: true }}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={onFinishFailed}
|
||||
autoComplete="off"
|
||||
>
|
||||
<Form.Item
|
||||
label="学员姓名"
|
||||
name="name"
|
||||
rules={[{ required: true, message: "请输入学员姓名!" }]}
|
||||
>
|
||||
<Input style={{ width: 200 }} placeholder="请输入学员姓名" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员头像"
|
||||
name="avatar"
|
||||
rules={[{ required: true, message: "请上传学员头像!" }]}
|
||||
>
|
||||
<div className="c-flex">
|
||||
<div className="d-flex">
|
||||
<UploadImageButton
|
||||
onSelected={(url) => {
|
||||
setAvatar(url);
|
||||
form.setFieldsValue({ avatar: url });
|
||||
}}
|
||||
></UploadImageButton>
|
||||
</div>
|
||||
{avatar && (
|
||||
<img className="form-avatar mt-10" src={avatar} alt="" />
|
||||
)}
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="登录密码"
|
||||
name="password"
|
||||
rules={[{ required: true, message: "请输入登录密码!" }]}
|
||||
>
|
||||
<Input.Password
|
||||
style={{ width: 200 }}
|
||||
placeholder="请输入登录密码"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员邮箱"
|
||||
name="email"
|
||||
rules={[{ required: true, message: "请输入学员邮箱!" }]}
|
||||
>
|
||||
<Input style={{ width: 200 }} placeholder="请输入学员邮箱" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="身份证号"
|
||||
name="idCard"
|
||||
rules={[{ required: true, message: "请输入身份证号!" }]}
|
||||
>
|
||||
<Input style={{ width: 200 }} placeholder="请输入身份证号" />
|
||||
</Form.Item>
|
||||
<Form.Item label="学员部门" name="dep_ids">
|
||||
<Cascader
|
||||
style={{ width: 200 }}
|
||||
options={departments}
|
||||
onChange={onChange}
|
||||
multiple
|
||||
maxTagCount="responsive"
|
||||
placeholder="请选择学员部门"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
240
src/pages/member/compenents/update.tsx
Normal file
240
src/pages/member/compenents/update.tsx
Normal file
@ -0,0 +1,240 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Modal, Form, Cascader, Input, message } from "antd";
|
||||
import styles from "./create.module.less";
|
||||
import { user, department } from "../../../api/index";
|
||||
import { UploadImageButton } from "../../../compenents";
|
||||
|
||||
interface PropInterface {
|
||||
id: number;
|
||||
open: boolean;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
interface Option {
|
||||
value: string | number;
|
||||
label: string;
|
||||
children?: Option[];
|
||||
}
|
||||
|
||||
export const MemberUpdate: React.FC<PropInterface> = ({
|
||||
id,
|
||||
open,
|
||||
onCancel,
|
||||
}) => {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [departments, setDepartments] = useState<any>([]);
|
||||
const [avatar, setAvatar] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
getParams();
|
||||
}, [id]);
|
||||
|
||||
useEffect(() => {
|
||||
form.setFieldsValue({
|
||||
password: "",
|
||||
});
|
||||
}, [form, open]);
|
||||
|
||||
const getParams = () => {
|
||||
if (id === 0) {
|
||||
return;
|
||||
}
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments = res.data.departments;
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(departments, 0);
|
||||
setDepartments(new_arr);
|
||||
}
|
||||
getDetail(departments);
|
||||
});
|
||||
};
|
||||
|
||||
const getDetail = (deps: any) => {
|
||||
user.user(id).then((res: any) => {
|
||||
let user = res.data.user;
|
||||
setAvatar(user.avatar);
|
||||
let box = res.data.dep_ids;
|
||||
let depIds: any[] = [];
|
||||
if (box.length > 1) {
|
||||
for (let i = 0; i < box.length; i++) {
|
||||
let item = checkChild(deps, box[i]);
|
||||
let arr: any[] = [];
|
||||
if (item === undefined) {
|
||||
arr.push(box[i]);
|
||||
} else if (item.parent_chain === "") {
|
||||
arr.push(box[i]);
|
||||
} else {
|
||||
let new_arr = item.parent_chain.split(",");
|
||||
new_arr.map((num: any) => {
|
||||
arr.push(Number(num));
|
||||
});
|
||||
arr.push(box[i]);
|
||||
}
|
||||
depIds.push(arr);
|
||||
}
|
||||
} else {
|
||||
depIds = res.data.dep_ids;
|
||||
}
|
||||
form.setFieldsValue({
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
nickname: user.nickname,
|
||||
avatar: user.avatar,
|
||||
idCard: user.id_card,
|
||||
dep_ids: depIds,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkChild = (departments: any[], id: number) => {
|
||||
for (let key in departments) {
|
||||
for (let i = 0; i < departments[key].length; i++) {
|
||||
if (departments[key][i].id === id) {
|
||||
return departments[key][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const checkArr = (departments: any[], id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < departments[id].length; i++) {
|
||||
if (!departments[departments[id][i].id]) {
|
||||
arr.push({
|
||||
label: departments[id][i].name,
|
||||
value: departments[id][i].id,
|
||||
});
|
||||
} else {
|
||||
const new_arr: Option[] = checkArr(departments, departments[id][i].id);
|
||||
arr.push({
|
||||
label: departments[id][i].name,
|
||||
value: departments[id][i].id,
|
||||
children: new_arr,
|
||||
});
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
const onFinish = (values: any) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < values.dep_ids.length; i++) {
|
||||
if (Array.isArray(values.dep_ids[i])) {
|
||||
arr.push(values.dep_ids[i][values.dep_ids[i].length - 1]);
|
||||
} else {
|
||||
arr.push(values.dep_ids[i]);
|
||||
}
|
||||
}
|
||||
user
|
||||
.updateUser(
|
||||
id,
|
||||
values.email,
|
||||
values.name,
|
||||
values.nickname,
|
||||
values.avatar,
|
||||
values.password || "",
|
||||
values.idCard,
|
||||
arr
|
||||
)
|
||||
.then((res: any) => {
|
||||
message.success("保存成功!");
|
||||
onCancel();
|
||||
});
|
||||
};
|
||||
|
||||
const onFinishFailed = (errorInfo: any) => {
|
||||
console.log("Failed:", errorInfo);
|
||||
};
|
||||
|
||||
const onChange = (value: any) => {};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
title="编辑学员"
|
||||
centered
|
||||
forceRender
|
||||
open={open}
|
||||
width={416}
|
||||
onOk={() => form.submit()}
|
||||
onCancel={() => onCancel()}
|
||||
maskClosable={false}
|
||||
>
|
||||
<div className="float-left mt-24">
|
||||
<Form
|
||||
form={form}
|
||||
name="basic"
|
||||
labelCol={{ span: 8 }}
|
||||
wrapperCol={{ span: 16 }}
|
||||
initialValues={{ remember: true }}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={onFinishFailed}
|
||||
autoComplete="off"
|
||||
>
|
||||
<Form.Item
|
||||
label="学员姓名"
|
||||
name="name"
|
||||
rules={[{ required: true, message: "请输入学员姓名!" }]}
|
||||
>
|
||||
<Input style={{ width: 200 }} placeholder="请输入学员姓名" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员头像"
|
||||
name="avatar"
|
||||
rules={[{ required: true, message: "请上传学员头像!" }]}
|
||||
>
|
||||
<div className="c-flex">
|
||||
<div className="d-flex">
|
||||
<UploadImageButton
|
||||
onSelected={(url) => {
|
||||
setAvatar(url);
|
||||
form.setFieldsValue({ avatar: url });
|
||||
}}
|
||||
></UploadImageButton>
|
||||
</div>
|
||||
{avatar && (
|
||||
<img className="form-avatar mt-10" src={avatar} alt="" />
|
||||
)}
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="登录密码"
|
||||
name="password"
|
||||
rules={[{ required: true, message: "请输入登录密码!" }]}
|
||||
>
|
||||
<Input.Password
|
||||
style={{ width: 200 }}
|
||||
placeholder="请输入登录密码"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员邮箱"
|
||||
name="email"
|
||||
rules={[{ required: true, message: "请输入学员邮箱!" }]}
|
||||
>
|
||||
<Input style={{ width: 200 }} placeholder="请输入学员邮箱" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="身份证号"
|
||||
name="idCard"
|
||||
rules={[{ required: true, message: "请输入身份证号!" }]}
|
||||
>
|
||||
<Input style={{ width: 200 }} placeholder="请输入身份证号" />
|
||||
</Form.Item>
|
||||
<Form.Item label="学员部门" name="dep_ids">
|
||||
<Cascader
|
||||
style={{ width: 200 }}
|
||||
options={departments}
|
||||
onChange={onChange}
|
||||
multiple
|
||||
maxTagCount="responsive"
|
||||
placeholder="请选择学员部门"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
@ -1,175 +0,0 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Row, Col, Form, Input, Cascader, Button, message } from "antd";
|
||||
import styles from "./create.module.less";
|
||||
import { user, department } from "../../api/index";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { UploadImageButton, BackBartment } from "../../compenents";
|
||||
|
||||
interface Option {
|
||||
value: string | number;
|
||||
label: string;
|
||||
children?: Option[];
|
||||
}
|
||||
|
||||
export const MemberCreatePage: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [departments, setDepartments] = useState<any>([]);
|
||||
const [avatar, setAvatar] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
getParams();
|
||||
}, []);
|
||||
|
||||
const getParams = () => {
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments = res.data.departments;
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(departments, 0);
|
||||
setDepartments(new_arr);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const checkArr = (departments: any[], id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < departments[id].length; i++) {
|
||||
if (!departments[departments[id][i].id]) {
|
||||
arr.push({
|
||||
label: departments[id][i].name,
|
||||
value: departments[id][i].id,
|
||||
});
|
||||
} else {
|
||||
const new_arr: Option[] = checkArr(departments, departments[id][i].id);
|
||||
arr.push({
|
||||
label: departments[id][i].name,
|
||||
value: departments[id][i].id,
|
||||
children: new_arr,
|
||||
});
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
const onFinish = (values: any) => {
|
||||
console.log("Success:", values);
|
||||
const arr = [];
|
||||
for (let i = 0; i < values.dep_ids.length; i++) {
|
||||
arr.push(values.dep_ids[i][values.dep_ids[i].length - 1]);
|
||||
}
|
||||
user
|
||||
.storeUser(
|
||||
values.email,
|
||||
values.name,
|
||||
values.avatar,
|
||||
values.password,
|
||||
values.idCard,
|
||||
arr
|
||||
)
|
||||
.then((res: any) => {
|
||||
message.success("保存成功!");
|
||||
navigate(-1);
|
||||
});
|
||||
};
|
||||
|
||||
const onFinishFailed = (errorInfo: any) => {
|
||||
console.log("Failed:", errorInfo);
|
||||
};
|
||||
|
||||
const onChange = (value: any) => {};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Row className="playedu-main-body">
|
||||
<Col>
|
||||
<div className="float-left mb-24">
|
||||
<BackBartment title="新建学员" />
|
||||
</div>
|
||||
<div className="float-left">
|
||||
<Form
|
||||
form={form}
|
||||
name="basic"
|
||||
labelCol={{ span: 8 }}
|
||||
wrapperCol={{ span: 16 }}
|
||||
style={{ width: 600 }}
|
||||
initialValues={{ remember: true }}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={onFinishFailed}
|
||||
autoComplete="off"
|
||||
>
|
||||
<Form.Item
|
||||
label="学员姓名"
|
||||
name="name"
|
||||
rules={[{ required: true, message: "请输入学员姓名!" }]}
|
||||
>
|
||||
<Input placeholder="请输入学员姓名" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员头像"
|
||||
name="avatar"
|
||||
rules={[{ required: true, message: "请上传学员头像!" }]}
|
||||
>
|
||||
<div className="c-flex">
|
||||
<div className="d-flex">
|
||||
<UploadImageButton
|
||||
onSelected={(url) => {
|
||||
setAvatar(url);
|
||||
form.setFieldsValue({ avatar: url });
|
||||
}}
|
||||
></UploadImageButton>
|
||||
</div>
|
||||
{avatar && (
|
||||
<img className="form-avatar mt-10" src={avatar} alt="" />
|
||||
)}
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="登录密码"
|
||||
name="password"
|
||||
rules={[{ required: true, message: "请输入登录密码!" }]}
|
||||
>
|
||||
<Input.Password placeholder="请输入登录密码" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员邮箱"
|
||||
name="email"
|
||||
rules={[{ required: true, message: "请输入学员邮箱!" }]}
|
||||
>
|
||||
<Input placeholder="请输入学员邮箱" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="身份证号"
|
||||
name="idCard"
|
||||
rules={[{ required: true, message: "请输入身份证号!" }]}
|
||||
>
|
||||
<Input placeholder="请输入身份证号" />
|
||||
</Form.Item>
|
||||
<Form.Item label="学员部门" name="dep_ids">
|
||||
<Cascader
|
||||
options={departments}
|
||||
onChange={onChange}
|
||||
multiple
|
||||
maxTagCount="responsive"
|
||||
placeholder="请选择学员部门"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
|
||||
<Button type="primary" htmlType="submit">
|
||||
保存
|
||||
</Button>
|
||||
<Button
|
||||
className="ml-15"
|
||||
htmlType="button"
|
||||
onClick={() => navigate(-1)}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
</>
|
||||
);
|
||||
};
|
@ -7,6 +7,8 @@ import { user } from "../../api/index";
|
||||
import { dateFormat } from "../../utils/index";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { TreeDepartment, PerButton } from "../../compenents";
|
||||
import { MemberCreate } from "./compenents/create";
|
||||
import { MemberUpdate } from "./compenents/update";
|
||||
const { confirm } = Modal;
|
||||
|
||||
interface DataType {
|
||||
@ -35,6 +37,9 @@ export const MemberPage: React.FC = () => {
|
||||
const [id_card, setIdCard] = useState<string>("");
|
||||
const [dep_ids, setDepIds] = useState<any>([]);
|
||||
const [selLabel, setLabel] = useState<string>("全部部门");
|
||||
const [createVisible, setCreateVisible] = useState<boolean>(false);
|
||||
const [updateVisible, setUpdateVisible] = useState<boolean>(false);
|
||||
const [mid, setMid] = useState<number>(0);
|
||||
|
||||
const columns: ColumnsType<DataType> = [
|
||||
{
|
||||
@ -78,7 +83,10 @@ export const MemberPage: React.FC = () => {
|
||||
class="b-link c-red"
|
||||
icon={null}
|
||||
p="user-update"
|
||||
onClick={() => navigate(`/member/update/${record.id}`)}
|
||||
onClick={() => {
|
||||
setMid(Number(record.id));
|
||||
setUpdateVisible(true);
|
||||
}}
|
||||
disabled={null}
|
||||
/>
|
||||
<div className="form-column"></div>
|
||||
@ -192,17 +200,15 @@ export const MemberPage: React.FC = () => {
|
||||
<div className="playedu-main-title float-left mb-24">{selLabel}</div>
|
||||
<div className="float-left j-b-flex mb-24">
|
||||
<div className="d-flex">
|
||||
<Link style={{ textDecoration: "none" }} to={`/member/create`}>
|
||||
<PerButton
|
||||
type="primary"
|
||||
text="添加学员"
|
||||
class="mr-16"
|
||||
icon={<PlusOutlined />}
|
||||
p="user-store"
|
||||
onClick={() => null}
|
||||
disabled={null}
|
||||
/>
|
||||
</Link>
|
||||
<PerButton
|
||||
type="primary"
|
||||
text="添加学员"
|
||||
class="mr-16"
|
||||
icon={<PlusOutlined />}
|
||||
p="user-store"
|
||||
onClick={() => setCreateVisible(true)}
|
||||
disabled={null}
|
||||
/>
|
||||
<Link style={{ textDecoration: "none" }} to={`/member/import`}>
|
||||
<PerButton
|
||||
type="primary"
|
||||
@ -274,6 +280,21 @@ export const MemberPage: React.FC = () => {
|
||||
pagination={paginationProps}
|
||||
rowKey={(record) => record.id}
|
||||
/>
|
||||
<MemberCreate
|
||||
open={createVisible}
|
||||
onCancel={() => {
|
||||
setCreateVisible(false);
|
||||
setRefresh(!refresh);
|
||||
}}
|
||||
/>
|
||||
<MemberUpdate
|
||||
id={mid}
|
||||
open={updateVisible}
|
||||
onCancel={() => {
|
||||
setUpdateVisible(false);
|
||||
setRefresh(!refresh);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,234 +0,0 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Row, Col, Form, Input, Cascader, Button, message } from "antd";
|
||||
import styles from "./update.module.less";
|
||||
import { user, department } from "../../api/index";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { UploadImageButton, BackBartment } from "../../compenents";
|
||||
|
||||
interface Option {
|
||||
value: string | number;
|
||||
label: string;
|
||||
children?: Option[];
|
||||
}
|
||||
|
||||
export const MemberUpdatePage: React.FC = () => {
|
||||
const params = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [departments, setDepartments] = useState<any>([]);
|
||||
const [avatar, setAvatar] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
getParams();
|
||||
}, [params.memberId]);
|
||||
|
||||
const getParams = () => {
|
||||
department.departmentList().then((res: any) => {
|
||||
const departments = res.data.departments;
|
||||
if (JSON.stringify(departments) !== "{}") {
|
||||
const new_arr: Option[] = checkArr(departments, 0);
|
||||
setDepartments(new_arr);
|
||||
}
|
||||
getDetail(departments);
|
||||
});
|
||||
};
|
||||
|
||||
const getDetail = (deps: any) => {
|
||||
user.user(Number(params.memberId)).then((res: any) => {
|
||||
let user = res.data.user;
|
||||
setAvatar(user.avatar);
|
||||
let box = res.data.dep_ids;
|
||||
let depIds: any[] = [];
|
||||
if (box.length > 1) {
|
||||
for (let i = 0; i < box.length; i++) {
|
||||
let item = checkChild(deps, box[i]);
|
||||
let arr: any[] = [];
|
||||
if (item === undefined) {
|
||||
arr.push(box[i]);
|
||||
} else if (item.parent_chain === "") {
|
||||
arr.push(box[i]);
|
||||
} else {
|
||||
let new_arr = item.parent_chain.split(",");
|
||||
new_arr.map((num: any) => {
|
||||
arr.push(Number(num));
|
||||
});
|
||||
arr.push(box[i]);
|
||||
}
|
||||
depIds.push(arr);
|
||||
}
|
||||
} else {
|
||||
depIds = res.data.dep_ids;
|
||||
}
|
||||
form.setFieldsValue({
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
nickname: user.nickname,
|
||||
avatar: user.avatar,
|
||||
idCard: user.id_card,
|
||||
dep_ids: depIds,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const checkChild = (departments: any[], id: number) => {
|
||||
for (let key in departments) {
|
||||
for (let i = 0; i < departments[key].length; i++) {
|
||||
if (departments[key][i].id === id) {
|
||||
return departments[key][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const checkArr = (departments: any[], id: number) => {
|
||||
const arr = [];
|
||||
for (let i = 0; i < departments[id].length; i++) {
|
||||
if (!departments[departments[id][i].id]) {
|
||||
arr.push({
|
||||
label: departments[id][i].name,
|
||||
value: departments[id][i].id,
|
||||
});
|
||||
} else {
|
||||
const new_arr: Option[] = checkArr(departments, departments[id][i].id);
|
||||
arr.push({
|
||||
label: departments[id][i].name,
|
||||
value: departments[id][i].id,
|
||||
children: new_arr,
|
||||
});
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
const onFinish = (values: any) => {
|
||||
console.log("Success:", values);
|
||||
let id = Number(params.memberId);
|
||||
const arr = [];
|
||||
for (let i = 0; i < values.dep_ids.length; i++) {
|
||||
if (Array.isArray(values.dep_ids[i])) {
|
||||
arr.push(values.dep_ids[i][values.dep_ids[i].length - 1]);
|
||||
} else {
|
||||
arr.push(values.dep_ids[i]);
|
||||
}
|
||||
}
|
||||
user
|
||||
.updateUser(
|
||||
id,
|
||||
values.email,
|
||||
values.name,
|
||||
values.nickname,
|
||||
values.avatar,
|
||||
values.password || "",
|
||||
values.idCard,
|
||||
arr
|
||||
)
|
||||
.then((res: any) => {
|
||||
message.success("保存成功!");
|
||||
navigate(-1);
|
||||
});
|
||||
};
|
||||
|
||||
const onFinishFailed = (errorInfo: any) => {
|
||||
console.log("Failed:", errorInfo);
|
||||
};
|
||||
|
||||
const onChange = (value: any) => {};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Row className="playedu-main-body">
|
||||
<Col>
|
||||
<div className="float-left mb-24">
|
||||
<BackBartment title="编辑学员" />
|
||||
</div>
|
||||
<div className="float-left">
|
||||
<Form
|
||||
form={form}
|
||||
name="basic"
|
||||
labelCol={{ span: 8 }}
|
||||
wrapperCol={{ span: 16 }}
|
||||
style={{ width: 600 }}
|
||||
initialValues={{ remember: true }}
|
||||
onFinish={onFinish}
|
||||
onFinishFailed={onFinishFailed}
|
||||
autoComplete="off"
|
||||
>
|
||||
<Form.Item
|
||||
label="学员姓名"
|
||||
name="name"
|
||||
rules={[{ required: true, message: "请输入学员姓名!" }]}
|
||||
>
|
||||
<Input placeholder="请输入学员姓名" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员昵称"
|
||||
name="nickname"
|
||||
rules={[{ required: true, message: "请输入学员昵称!" }]}
|
||||
>
|
||||
<Input placeholder="请输入学员昵称" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员头像"
|
||||
name="avatar"
|
||||
rules={[{ required: true, message: "请上传学员头像!" }]}
|
||||
>
|
||||
<div className="c-flex">
|
||||
<div className="d-flex">
|
||||
<UploadImageButton
|
||||
onSelected={(url) => {
|
||||
setAvatar(url);
|
||||
form.setFieldsValue({ avatar: url });
|
||||
}}
|
||||
></UploadImageButton>
|
||||
</div>
|
||||
{avatar && (
|
||||
<img className="form-avatar mt-10" src={avatar} alt="" />
|
||||
)}
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item label="登录密码" name="password">
|
||||
<Input.Password placeholder="请输入登录密码" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="学员邮箱"
|
||||
name="email"
|
||||
rules={[{ required: true, message: "请输入学员邮箱!" }]}
|
||||
>
|
||||
<Input placeholder="请输入学员邮箱" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="身份证号"
|
||||
name="idCard"
|
||||
rules={[{ required: true, message: "请输入身份证号!" }]}
|
||||
>
|
||||
<Input placeholder="请输入身份证号" />
|
||||
</Form.Item>
|
||||
<Form.Item label="学员部门" name="dep_ids">
|
||||
<Cascader
|
||||
options={departments}
|
||||
onChange={onChange}
|
||||
multiple
|
||||
maxTagCount="responsive"
|
||||
placeholder="请选择学员部门"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
|
||||
<Button type="primary" htmlType="submit">
|
||||
保存
|
||||
</Button>
|
||||
<Button
|
||||
className="ml-15"
|
||||
htmlType="button"
|
||||
onClick={() => navigate(-1)}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
</>
|
||||
);
|
||||
};
|
@ -9,8 +9,6 @@ import {
|
||||
CourseUpdatePage,
|
||||
TestPage,
|
||||
MemberPage,
|
||||
MemberCreatePage,
|
||||
MemberUpdatePage,
|
||||
MemberImportPage,
|
||||
SystemAdministratorPage,
|
||||
SystemAdminrolesPage,
|
||||
@ -64,14 +62,6 @@ const routes: RouteObject[] = [
|
||||
path: "/member",
|
||||
element: <MemberPage />,
|
||||
},
|
||||
{
|
||||
path: "/member/create",
|
||||
element: <MemberCreatePage />,
|
||||
},
|
||||
{
|
||||
path: "/member/update/:memberId",
|
||||
element: <MemberUpdatePage />,
|
||||
},
|
||||
{
|
||||
path: "/member/import",
|
||||
element: <MemberImportPage />,
|
||||
|
Loading…
x
Reference in New Issue
Block a user