|
@@ -1,9 +1,9 @@
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
-import type { UploadProps } from 'antd';
|
|
|
-import { Cascader } from 'antd';
|
|
|
-import { Checkbox, Col, Form, Input, message, Modal, Row, Select, Upload } from 'antd';
|
|
|
-import { createUser, editUser, queryRoleUser, queryTreeList } from '@/services/setting';
|
|
|
-import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
+// import type { UploadProps } from 'antd';
|
|
|
+// import { Cascader } from 'antd';
|
|
|
+import { Checkbox, Col, Form, Input, message, Modal, Row } from 'antd';
|
|
|
+import { createUser, editUser } from '@/services/setting';
|
|
|
+// import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
import md5 from 'js-md5';
|
|
|
import { queryRoleList } from '@/services/role';
|
|
|
import { infoQuery } from '@/services/ReportingManagement';
|
|
@@ -22,24 +22,24 @@ interface userEditPros {
|
|
|
const Edit: React.FC<userEditPros> = (props) => {
|
|
|
const { visible, editCallback, detailData } = props;
|
|
|
const [form] = Form.useForm();
|
|
|
- const uploadHeaders = { Authorization: `${localStorage.getItem('token')}` };
|
|
|
- const [fileUrl, setFileUrl]: any = useState(
|
|
|
- detailData && detailData.photo ? detailData.photo : '',
|
|
|
- );
|
|
|
- const [loading, setLoading] = useState(false);
|
|
|
+ // const uploadHeaders = { Authorization: `${localStorage.getItem('token')}` };
|
|
|
+ // const [fileUrl, setFileUrl]: any = useState(
|
|
|
+ // detailData && detailData.photo ? detailData.photo : '',
|
|
|
+ // );
|
|
|
+ // const [loading, setLoading] = useState(false);
|
|
|
const [roleList, setRoleList] = useState([]);
|
|
|
- const [selectList, setSelectList] = useState([]);
|
|
|
- const [areaList, setAreaList] = useState([]);
|
|
|
+ // const [selectList, setSelectList] = useState([]);
|
|
|
+ // const [areaList, setAreaList] = useState([]);
|
|
|
const [isCurrent, setIsCurrent] = useState(false);
|
|
|
|
|
|
- const getBase64 = (img: any) => {
|
|
|
- const reader = new FileReader();
|
|
|
- reader.readAsDataURL(img);
|
|
|
- reader.onloadend = () => {
|
|
|
- const url = reader.result;
|
|
|
- setFileUrl(url);
|
|
|
- };
|
|
|
- };
|
|
|
+ // const getBase64 = (img: any) => {
|
|
|
+ // const reader = new FileReader();
|
|
|
+ // reader.readAsDataURL(img);
|
|
|
+ // reader.onloadend = () => {
|
|
|
+ // const url = reader.result;
|
|
|
+ // setFileUrl(url);
|
|
|
+ // };
|
|
|
+ // };
|
|
|
|
|
|
useEffect(() => {
|
|
|
// 编辑时
|
|
@@ -73,20 +73,20 @@ const Edit: React.FC<userEditPros> = (props) => {
|
|
|
});
|
|
|
|
|
|
// 编辑时,所属地区根据角色id回显数据
|
|
|
- const data = [...detailData?.user_role].sort((a: any, b: any) => b.level - a.level);
|
|
|
- if (data && data.length) {
|
|
|
- const param = {
|
|
|
- q: 'list',
|
|
|
- role_id: data[0].role_id,
|
|
|
- user_id: detailData.record_id,
|
|
|
- };
|
|
|
- // 根据角色id请求用户列表接口 保证所属名称字段编辑时回显
|
|
|
- queryRoleUser(param).then((item) => {
|
|
|
- if (item.code === 0) {
|
|
|
- setSelectList(item?.data || []);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ // const data = [...detailData?.user_role].sort((a: any, b: any) => b.level - a.level);
|
|
|
+ // if (data && data.length) {
|
|
|
+ // const param = {
|
|
|
+ // q: 'list',
|
|
|
+ // role_id: data[0].role_id,
|
|
|
+ // user_id: detailData.record_id,
|
|
|
+ // };
|
|
|
+ // // 根据角色id请求用户列表接口 保证所属名称字段编辑时回显
|
|
|
+ // queryRoleUser(param).then((item) => {
|
|
|
+ // if (item.code === 0) {
|
|
|
+ // setSelectList(item?.data || []);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
} else {
|
|
|
// 新增
|
|
|
// 角色列表
|
|
@@ -98,61 +98,61 @@ const Edit: React.FC<userEditPros> = (props) => {
|
|
|
}
|
|
|
|
|
|
// 地区列表
|
|
|
- queryTreeList({ q: 'tree' }).then((res) => {
|
|
|
- if (res && res.code === 0) {
|
|
|
- setAreaList(res.data.list || []);
|
|
|
- }
|
|
|
- });
|
|
|
+ // queryTreeList({ q: 'tree' }).then((res) => {
|
|
|
+ // if (res && res.code === 0) {
|
|
|
+ // setAreaList(res.data.list || []);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
}, []);
|
|
|
|
|
|
- const handleLevel = (values: any) => {
|
|
|
- const data: any = roleList.filter((option: { record_id: string }) =>
|
|
|
- values.includes(option.record_id),
|
|
|
- );
|
|
|
- return [...data].sort((a: any, b: any) => b.level - a.level);
|
|
|
- };
|
|
|
+ // const handleLevel = (values: any) => {
|
|
|
+ // const data: any = roleList.filter((option: { record_id: string }) =>
|
|
|
+ // values.includes(option.record_id),
|
|
|
+ // );
|
|
|
+ // return [...data].sort((a: any, b: any) => b.level - a.level);
|
|
|
+ // };
|
|
|
|
|
|
// 角色选择
|
|
|
- const onRoleChange = (selectedValues: any) => {
|
|
|
- // 切换角色时,所属名称要清空重新选择
|
|
|
- form.setFieldsValue({ parent_id: '' });
|
|
|
- const sortedData = handleLevel(selectedValues);
|
|
|
- if (sortedData && sortedData.length > 0) {
|
|
|
- const maxLevelObject = sortedData[0];
|
|
|
- const param = {
|
|
|
- q: 'list',
|
|
|
- role_id: maxLevelObject.record_id,
|
|
|
- };
|
|
|
- queryRoleUser(param).then((res) => {
|
|
|
- if (res.code === 0) {
|
|
|
- setSelectList(res?.data || []);
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- setSelectList([]);
|
|
|
- }
|
|
|
- };
|
|
|
+ // const onRoleChange = (selectedValues: any) => {
|
|
|
+ // // 切换角色时,所属名称要清空重新选择
|
|
|
+ // form.setFieldsValue({ parent_id: '' });
|
|
|
+ // const sortedData = handleLevel(selectedValues);
|
|
|
+ // if (sortedData && sortedData.length > 0) {
|
|
|
+ // const maxLevelObject = sortedData[0];
|
|
|
+ // const param = {
|
|
|
+ // q: 'list',
|
|
|
+ // role_id: maxLevelObject.record_id,
|
|
|
+ // };
|
|
|
+ // queryRoleUser(param).then((res) => {
|
|
|
+ // if (res.code === 0) {
|
|
|
+ // setSelectList(res?.data || []);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // } else {
|
|
|
+ // setSelectList([]);
|
|
|
+ // }
|
|
|
+ // };
|
|
|
|
|
|
- const filesProps: UploadProps = {
|
|
|
- maxCount: 1,
|
|
|
- action: '/web/v1/files',
|
|
|
- headers: uploadHeaders,
|
|
|
- listType: 'picture-card',
|
|
|
- showUploadList: false,
|
|
|
- onChange(info) {
|
|
|
- if (info.file.status === 'uploading') {
|
|
|
- setLoading(true);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (info.file.status === 'done') {
|
|
|
- setLoading(false);
|
|
|
- getBase64(info.file.originFileObj);
|
|
|
- } else if (info.file.status === 'error') {
|
|
|
- setLoading(false);
|
|
|
- message.error('文件上传失败');
|
|
|
- }
|
|
|
- },
|
|
|
- };
|
|
|
+ // const filesProps: UploadProps = {
|
|
|
+ // maxCount: 1,
|
|
|
+ // action: '/web/v1/files',
|
|
|
+ // headers: uploadHeaders,
|
|
|
+ // listType: 'picture-card',
|
|
|
+ // showUploadList: false,
|
|
|
+ // onChange(info) {
|
|
|
+ // if (info.file.status === 'uploading') {
|
|
|
+ // setLoading(true);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // if (info.file.status === 'done') {
|
|
|
+ // setLoading(false);
|
|
|
+ // getBase64(info.file.originFileObj);
|
|
|
+ // } else if (info.file.status === 'error') {
|
|
|
+ // setLoading(false);
|
|
|
+ // message.error('文件上传失败');
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // };
|
|
|
|
|
|
/**
|
|
|
* 确定
|
|
@@ -247,12 +247,12 @@ const Edit: React.FC<userEditPros> = (props) => {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
- const uploadButton = (
|
|
|
- <div>
|
|
|
- {loading ? <LoadingOutlined /> : <PlusOutlined />}
|
|
|
- <div className="ant-upload-text">上传</div>
|
|
|
- </div>
|
|
|
- );
|
|
|
+ // const uploadButton = (
|
|
|
+ // <div>
|
|
|
+ // {loading ? <LoadingOutlined /> : <PlusOutlined />}
|
|
|
+ // <div className="ant-upload-text">上传</div>
|
|
|
+ // </div>
|
|
|
+ // );
|
|
|
|
|
|
return (
|
|
|
<Modal
|
|
@@ -327,61 +327,61 @@ const Edit: React.FC<userEditPros> = (props) => {
|
|
|
record_id: option.record_id,
|
|
|
}))}
|
|
|
disabled={isCurrent}
|
|
|
- onChange={onRoleChange}
|
|
|
+ // onChange={onRoleChange}
|
|
|
/>
|
|
|
</Form.Item>
|
|
|
</Col>
|
|
|
- <Col span={24}>
|
|
|
- <Form.Item
|
|
|
- {...formItemLayoutTwo}
|
|
|
- name="parent_id"
|
|
|
- label="上级用户"
|
|
|
- initialValue={detailData?.parent_id || ''}
|
|
|
- >
|
|
|
- <Select placeholder="请选择所属名称" disabled={isCurrent}>
|
|
|
- {selectList && selectList.length
|
|
|
- ? selectList.map(
|
|
|
- (res: { user_name: string; record_id: string; parent_id: string }) => {
|
|
|
- return (
|
|
|
- <Select.Option key={res.record_id} value={res.record_id}>
|
|
|
- {res?.user_name}
|
|
|
- </Select.Option>
|
|
|
- );
|
|
|
- },
|
|
|
- )
|
|
|
- : null}
|
|
|
- </Select>
|
|
|
- </Form.Item>
|
|
|
- </Col>
|
|
|
- <Col span={24}>
|
|
|
- <Form.Item
|
|
|
- {...formItemLayoutTwo}
|
|
|
- name="area"
|
|
|
- label="所属地区"
|
|
|
- initialValue={
|
|
|
- detailData?.province || detailData?.city || detailData?.district
|
|
|
- ? [detailData?.province, detailData?.city, detailData?.district]
|
|
|
- : []
|
|
|
- }
|
|
|
- >
|
|
|
- <Cascader
|
|
|
- options={areaList}
|
|
|
- placeholder="请选择所属地区"
|
|
|
- fieldNames={{ label: 'name', value: 'name', children: 'children' }}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- </Col>
|
|
|
- <Col span={12}>
|
|
|
- <Form.Item {...formItemLayout} name="photo" label="头像" initialValue={[]}>
|
|
|
- <Upload {...filesProps}>
|
|
|
- {fileUrl === '' ? (
|
|
|
- uploadButton
|
|
|
- ) : (
|
|
|
- <img src={fileUrl} alt="data" style={{ width: '100%' }} />
|
|
|
- )}
|
|
|
- </Upload>
|
|
|
- </Form.Item>
|
|
|
- </Col>
|
|
|
+ {/*<Col span={24}>*/}
|
|
|
+ {/* <Form.Item*/}
|
|
|
+ {/* {...formItemLayoutTwo}*/}
|
|
|
+ {/* name="parent_id"*/}
|
|
|
+ {/* label="上级用户"*/}
|
|
|
+ {/* initialValue={detailData?.parent_id || ''}*/}
|
|
|
+ {/* >*/}
|
|
|
+ {/* <Select placeholder="请选择所属名称" disabled={isCurrent}>*/}
|
|
|
+ {/* {selectList && selectList.length*/}
|
|
|
+ {/* ? selectList.map(*/}
|
|
|
+ {/* (res: { user_name: string; record_id: string; parent_id: string }) => {*/}
|
|
|
+ {/* return (*/}
|
|
|
+ {/* <Select.Option key={res.record_id} value={res.record_id}>*/}
|
|
|
+ {/* {res?.user_name}*/}
|
|
|
+ {/* </Select.Option>*/}
|
|
|
+ {/* );*/}
|
|
|
+ {/* },*/}
|
|
|
+ {/* )*/}
|
|
|
+ {/* : null}*/}
|
|
|
+ {/* </Select>*/}
|
|
|
+ {/* </Form.Item>*/}
|
|
|
+ {/*</Col>*/}
|
|
|
+ {/*<Col span={24}>*/}
|
|
|
+ {/* <Form.Item*/}
|
|
|
+ {/* {...formItemLayoutTwo}*/}
|
|
|
+ {/* name="area"*/}
|
|
|
+ {/* label="所属地区"*/}
|
|
|
+ {/* initialValue={*/}
|
|
|
+ {/* detailData?.province || detailData?.city || detailData?.district*/}
|
|
|
+ {/* ? [detailData?.province, detailData?.city, detailData?.district]*/}
|
|
|
+ {/* : []*/}
|
|
|
+ {/* }*/}
|
|
|
+ {/* >*/}
|
|
|
+ {/* <Cascader*/}
|
|
|
+ {/* options={areaList}*/}
|
|
|
+ {/* placeholder="请选择所属地区"*/}
|
|
|
+ {/* fieldNames={{ label: 'name', value: 'name', children: 'children' }}*/}
|
|
|
+ {/* />*/}
|
|
|
+ {/* </Form.Item>*/}
|
|
|
+ {/*</Col>*/}
|
|
|
+ {/*<Col span={12}>*/}
|
|
|
+ {/* <Form.Item {...formItemLayout} name="photo" label="头像" initialValue={[]}>*/}
|
|
|
+ {/* <Upload {...filesProps}>*/}
|
|
|
+ {/* {fileUrl === '' ? (*/}
|
|
|
+ {/* uploadButton*/}
|
|
|
+ {/* ) : (*/}
|
|
|
+ {/* <img src={fileUrl} alt="data" style={{ width: '100%' }} />*/}
|
|
|
+ {/* )}*/}
|
|
|
+ {/* </Upload>*/}
|
|
|
+ {/* </Form.Item>*/}
|
|
|
+ {/*</Col>*/}
|
|
|
</Row>
|
|
|
</Form>
|
|
|
</Modal>
|