master
Joe 2 years ago
parent b4da146492
commit 3f034f4b9a

@ -46,7 +46,7 @@ export default defineConfig({
{
path: '/',
component: '../layouts/BasicLayout',
authority: ['admin', 'user'],
authority: ['employeeQuery', 'dataQuery', 'settingSave', 'userSave'],
routes: [
{
path: '/',
@ -56,20 +56,30 @@ export default defineConfig({
name: '员工信息',
icon: 'idcard',
path: 'employee',
authority: ['employeeQuery'],
component: './Employee'
},
{
name: '数据统计',
icon: 'barChart',
path: 'data-statistics',
authority: ['dataQuery'],
component: './DataStatistics'
},
{
name: 'list.maintain',
icon: 'setting',
path: 'info-setting',
authority: ['settingSave'],
component: './InfoSetting'
},
{
name: '账号管理',
icon: 'idcard',
path: 'maintain',
authority: ['userSave'],
component: './UserList',
},
{
component: './404',
},

@ -76,8 +76,12 @@ const Model: LoginModelType = {
reducers: {
changeLoginStatus(state, { payload }) {
if (payload.retcode) {
setAuthority('admin')
localStorage.setItem('token', payload.data)
let list: any[] = []
if (payload.data.user && payload.data.user.permission) {
list = JSON.parse(payload.data.user.permission)
}
setAuthority(list)
localStorage.setItem('token', payload.data.token)
}
return {
...state,

@ -1,8 +1,11 @@
import React, { useState } from 'react';
import { Form, Button, Input, Col, Drawer, Row } from 'antd';
import { Form, Button, Input, Col, Drawer, Row, Select } from 'antd';
import { TableListItem } from '../data.d';
const { Option } = Select;
export interface FormValueType extends Partial<TableListItem> {
degree?: string;
isEducation?: string;
education?: string;
school?: string;
speciality?: string;
@ -32,6 +35,8 @@ const UpdateEducationResumeForm: React.FC<UpdateFormProps> = (props) => {
undergraduateSchools: props.values.undergraduateSchools,
undergraduateMajor: props.values.undergraduateMajor,
intake: props.values.intake,
isEducation: props.values.isEducation,
degree: props.values.degree,
graduationTime: props.values.graduationTime,
});
@ -97,41 +102,32 @@ const UpdateEducationResumeForm: React.FC<UpdateFormProps> = (props) => {
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="highestEducation" label="最高学历">
<Input placeholder="请输入最高学历" />
<Form.Item name="isEducation" label="是否就业学历">
<Select placeholder="请选择是否就业学历" allowClear>
<Option value={1} key={1}></Option>
<Option value={2} key={2}></Option>
</Select>
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={12}>
<Form.Item name="undergraduateSchools" label="本科学历学校">
<Input placeholder="请输入本科学历学校" />
<Form.Item name="degree" label="学位">
<Input placeholder="请输入学位" />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="undergraduateMajor" label="本科学历专业">
<Input placeholder="请输入本科学历专业" />
<Form.Item name="school" label="学校">
<Input placeholder="请输入学校" />
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={12}>
<Form.Item name="school" label="最高学历学校">
<Input placeholder="请输入最高学历学校" />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="speciality" label="专业">
<Input placeholder="请输入专业" />
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={12}>
<Form.Item name="intake" label="入学日期">
<Input placeholder="请输入入学日期" />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="graduationTime" label="毕业日期">
<Input placeholder="请输入毕业日期" />

@ -1,11 +1,14 @@
import React, { useState } from 'react';
import { Form, Button, Input, Col, Drawer, Row } from 'antd';
import { Form, Button, Input, Col, Drawer, Row, DatePicker } from 'antd';
import { TableListItem } from '../data.d';
import moment, { Moment } from 'moment';
export interface FormValueType extends Partial<TableListItem> {
relationName?: string;
relation?: string;
relationMobile?: string;
workUnit?: string;
birthday?: Moment | null;
}
export interface UpdateFormProps {
@ -15,6 +18,8 @@ export interface UpdateFormProps {
values: FormValueType;
}
const dateFormat = 'YYYYMMDD';
const UpdateFamilyMembersForm: React.FC<UpdateFormProps> = (props) => {
const [formVals, setFormVals] = useState<FormValueType>({
id: props.values.id,
@ -23,6 +28,8 @@ const UpdateFamilyMembersForm: React.FC<UpdateFormProps> = (props) => {
relationName: props.values.relationName,
relation: props.values.relation,
relationMobile: props.values.relationMobile,
workUnit: props.values.workUnit,
birthday: props.values.birthday ? moment(props.values.birthday, dateFormat) : null
});
const [form] = Form.useForm();
@ -39,7 +46,7 @@ const UpdateFamilyMembersForm: React.FC<UpdateFormProps> = (props) => {
setFormVals({ ...formVals, ...fieldsValue });
handleUpdate({ ...formVals, ...fieldsValue });
handleUpdate({ ...formVals, ...fieldsValue, birthday: fieldsValue.birthday ? fieldsValue.birthday.format(dateFormat) : '', });
};
return (
@ -94,8 +101,13 @@ const UpdateFamilyMembersForm: React.FC<UpdateFormProps> = (props) => {
</Row>
<Row gutter={16}>
<Col span={12}>
<Form.Item name="relationMobile" label="电话">
<Input placeholder="请输入电话" />
<Form.Item name="workUnit" label="工作单位">
<Input placeholder="请输入工作单位" />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="birthday" label="出生日期">
<DatePicker placeholder="请选择出生日期" />
</Form.Item>
</Col>
</Row>

@ -11,7 +11,6 @@ import {
Modal,
Popconfirm,
message,
Image,
InputNumber,
DatePicker,
Upload,
@ -41,10 +40,10 @@ import UpdateHonorForm from './UpdateHonorForm';
import { useReactToPrint } from 'react-to-print';
//@ts-ignore
import Html2Pdf from 'js-html2pdf';
import EmptyImage from '@/assets/empty.png'
import moment, { Moment } from 'moment';
import { RcFile, UploadChangeParam, UploadFile, UploadProps } from 'antd/lib/upload';
import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
import { getAuthority } from '@/utils/authority';
const { Option } = Select;
export interface FormValueType extends Partial<TableListItem> {
@ -255,11 +254,22 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const educationResumeColumns: ColumnsType<any> = [
{
title: '最高学历',
dataIndex: 'highestEducation',
title: '学历',
dataIndex: 'education',
},
{
title: '是否就业学历',
dataIndex: 'isEducation',
render(value, record, index) {
return value == 1 ? '是' : ''
},
},
{
title: '最高学历学校',
title: '学位',
dataIndex: 'degree',
},
{
title: '学校',
dataIndex: 'school',
},
{
@ -267,57 +277,37 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
dataIndex: 'speciality',
},
{
title: '就业学历',
dataIndex: 'education',
},
{
title: '本科学历学校',
dataIndex: 'undergraduateSchools',
title: '毕业时间',
dataIndex: 'graduationTime'
},
];
const educationResumeColumns1: ColumnsType<any> = [
{
title: '本科学历专业',
dataIndex: 'undergraduateMajor',
title: '学历',
dataIndex: 'education',
},
{
title: '时间',
dataIndex: 'intake',
title: '是否就业学历',
dataIndex: 'isEducation',
render(value, record, index) {
return record.intake + '~' + record.graduationTime;
return value == 1 ? '是' : ''
},
},
];
const educationResumeColumns1: ColumnsType<any> = [
{
title: '最高学历',
dataIndex: 'highestEducation',
title: '学位',
dataIndex: 'degree',
},
{
title: '最高学历学校',
title: '学校',
dataIndex: 'school',
},
{
title: '专业',
dataIndex: 'speciality',
},
{
title: '就业学历',
dataIndex: 'education',
},
{
title: '本科学历学校',
dataIndex: 'undergraduateSchools',
},
{
title: '本科学历专业',
dataIndex: 'undergraduateMajor',
},
{
title: '入学时间',
dataIndex: 'intake',
},
{
title: '毕业时间',
dataIndex: 'intake',
dataIndex: 'graduationTime'
},
{
title: '操作',
@ -356,8 +346,12 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
dataIndex: 'relation',
},
{
title: '电话',
dataIndex: 'relationMobile',
title: '工作单位',
dataIndex: 'workUnit',
},
{
title: '出生日期',
dataIndex: 'birthday',
},
];
const familyMembersColumns1: ColumnsType<any> = [
@ -370,8 +364,12 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
dataIndex: 'relation',
},
{
title: '电话',
dataIndex: 'relationMobile',
title: '工作单位',
dataIndex: 'workUnit',
},
{
title: '出生日期',
dataIndex: 'birthday',
},
{
title: '操作',
@ -402,29 +400,37 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
];
const workExperienceColumns: ColumnsType<any> = [
{
title: '现岗位',
dataIndex: 'transferredPosition',
title: '部门',
dataIndex: 'department',
},
{
title: '原岗位',
dataIndex: 'originalPosition',
title: '班组',
dataIndex: 'groups',
},
{
title: '调岗日期',
title: '岗位',
dataIndex: 'transferredPosition',
},
{
title: '起始时间',
dataIndex: 'transferDate',
},
];
const workExperienceColumns1: ColumnsType<any> = [
{
title: '现岗位',
dataIndex: 'transferredPosition',
title: '部门',
dataIndex: 'department',
},
{
title: '原岗位',
dataIndex: 'originalPosition',
title: '班组',
dataIndex: 'groups',
},
{
title: '岗位',
dataIndex: 'transferredPosition',
},
{
title: '调岗日期',
title: '起始时间',
dataIndex: 'transferDate',
},
{
@ -666,6 +672,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const promiseResolveRef: any = useRef(null);
const [loading, setLoading] = useState(false);
const [isEdit, setIsEdit] = useState(false);
const [imageUrl, setImageUrl] = useState<string>(props.values.employeeName && props.values.cardNo ? `http://localhost:8888/upload/${props.values.employeeName}_${props.values.cardNo}.jpg`:'');
const handleChange: UploadProps['onChange'] = (info: UploadChangeParam<UploadFile>) => {
@ -755,7 +762,14 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
}
}, [props.values.employeeNo]);
console.log(imageUrl)
console.log(getAuthority())
useEffect(() => {
const list = getAuthority()
if (list.includes('employeeSave')) {
setIsEdit(true)
}
}, [])
return (
<Drawer
@ -786,9 +800,10 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
Excel
</Button>
) : null}
<Button onClick={handleSubmit} type="primary">
{isEdit ? <Button onClick={handleSubmit} type="primary">
</Button>
</Button>: null}
</div>
}
>
@ -800,6 +815,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
listType="picture-card"
className="avatar-uploader"
fileList={fileList}
disabled={!isEdit}
action="http://localhost:8888/api/employee/uploadImage"
beforeUpload={beforeUpload}
onChange={handleChange}
@ -814,7 +830,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
</Upload>
</div>
<Form form={form} labelAlign="left" labelCol={{ span: 7 }} initialValues={formVals}>
<Form form={form} labelAlign="left" disabled={!isEdit} labelCol={{ span: 7 }} initialValues={formVals}>
<Row gutter={16}>
<Col span={12}>
<Form.Item
@ -960,7 +976,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
<div style={{ marginBottom: 10 }}>
<div style={{ fontSize: 16, marginBottom: 10, fontWeight: 'bold' }}>
{' '}
{isPrint ? null : <Button
{isPrint || !isEdit ? null : <Button
onClick={() => {
setOpen(true);
setType(1);
@ -986,7 +1002,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
<div style={{ marginBottom: 10 }}>
<div style={{ fontSize: 16, marginBottom: 10, fontWeight: 'bold' }}>
{' '}
{isPrint ? null : <Button
{isPrint || !isEdit ? null : <Button
onClick={() => {
setOpen(true);
setType(2);
@ -1009,7 +1025,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
<div style={{ marginBottom: 10 }}>
<div style={{ fontSize: 16, marginBottom: 10, fontWeight: 'bold' }}>
{' '}
{isPrint ? null : <Button
{isPrint || !isEdit ? null : <Button
onClick={() => {
setOpen(true);
setType(3);
@ -1032,7 +1048,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
<div>
<div style={{ fontSize: 16, marginBottom: 10, fontWeight: 'bold' }}>
{' '}
{isPrint ? null : <Button
{isPrint || !isEdit ? null : <Button
onClick={() => {
setOpen(true);
setType(4);

@ -23,6 +23,8 @@ const UpdateWorkExperienceForm: React.FC<UpdateFormProps> = (props) => {
transferredPosition: props.values.transferredPosition,
originalPosition: props.values.originalPosition,
transferDate: props.values.transferDate,
department: props.values.department,
groups: props.values.groups,
});
const [form] = Form.useForm();
@ -82,17 +84,22 @@ const UpdateWorkExperienceForm: React.FC<UpdateFormProps> = (props) => {
</Row>
<Row gutter={16}>
<Col span={12}>
<Form.Item name="transferredPosition" label="调入岗位">
<Input placeholder="请输入调入岗位" />
<Form.Item name="department" label="部门">
<Input placeholder="请输入部门" />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="originalPosition" label="原岗位">
<Input placeholder="请输入原岗位" />
<Form.Item name="groups" label="班组">
<Input placeholder="请输入班组" />
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={12}>
<Form.Item name="transferredPosition" label="岗位">
<Input placeholder="请输入岗位" />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item name="transferDate" label="调岗日期">
<Input placeholder="请输入调岗日期" />

@ -20,6 +20,8 @@ export interface TableListItem {
cardNo?: string,
mobile?: string,
highestEducation?: string,
degree?: string;
isEducation?: string;
highestEducationId?: number
}

@ -5,6 +5,7 @@ import { queryRule, updateRule, removeRule, addRule, getAllInfoSettingValueBySet
import UpdateForm, { FormValueType } from './components/UpdateForm';
import ProTable, { ActionType, ProColumns } from "@ant-design/pro-table";
import Import from "@/components/Import/Import";
import Authorized from "@/utils/Authorized";
/**
*
@ -414,12 +415,14 @@ const UserList: React.FC<{}> = () => {
handleUpdateModalVisible(true);
setCurrentRow(record);
}}></a>
<Popconfirm title="确定删除?" onConfirm={async () => {
const success = await handleRemove(record.id)
if (success) actionRef.current?.reload()
}}>
<a style={{color: 'red'}}></a>
</Popconfirm>
<Authorized authority="employeeSave" noMatch={<span />}>
<Popconfirm title="确定删除?" onConfirm={async () => {
const success = await handleRemove(record.id)
if (success) actionRef.current?.reload()
}}>
<a style={{color: 'red'}}></a>
</Popconfirm>
</Authorized>
</span>
)
}
@ -445,53 +448,65 @@ const UserList: React.FC<{}> = () => {
labelWidth: 'auto'
}}
toolBarRender={() => [
<Button
type="primary"
key="primary"
onClick={() => {
handleUpdateModalVisible(true);
setCurrentRow({
id: undefined,
});
}}
>
</Button>,
<Import
api={'/api/employee/importEmployee'}
text="批量导入员工基本信息"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Import
api={'/api/educationResume/importEducationResume'}
text="批量导入员工教育履历"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Import
api={'/api/familyMembers/importFamilyMembers'}
text="批量导入员工家庭成员"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Import
api={'/api/workExperience/importWorkExperience'}
text="批量导入员工工作经历记录"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Import
api={'/api/honor/importHonor'}
text="批量导入员工奖惩记录"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Authorized authority="employeeSave" noMatch={<span />}>
<Button
type="primary"
key="primary"
onClick={() => {
handleUpdateModalVisible(true);
setCurrentRow({
id: undefined,
});
}}
>
</Button>
</Authorized>,
<Authorized authority="employeeSave" noMatch={<span />}>
<Import
api={'/api/employee/importEmployee'}
text="批量导入员工基本信息"
uploaded={() => {
actionRef.current?.reload();
}}
/>
</Authorized>,
<Authorized authority="employeeSave" noMatch={<span />}>
<Import
api={'/api/educationResume/importEducationResume'}
text="批量导入员工教育履历"
uploaded={() => {
actionRef.current?.reload();
}}
/>
</Authorized>,
<Authorized authority="employeeSave" noMatch={<span />}>
<Import
api={'/api/familyMembers/importFamilyMembers'}
text="批量导入员工家庭成员"
uploaded={() => {
actionRef.current?.reload();
}}
/>
</Authorized>,
<Authorized authority="employeeSave" noMatch={<span />}>
<Import
api={'/api/workExperience/importWorkExperience'}
text="批量导入员工工作经历记录"
uploaded={() => {
actionRef.current?.reload();
}}
/>
</Authorized>,
<Authorized authority="employeeSave" noMatch={<span />}>
<Import
api={'/api/honor/importHonor'}
text="批量导入员工奖惩记录"
uploaded={() => {
actionRef.current?.reload();
}}
/>
</Authorized>,
<Button
key="export"
type="primary"

@ -0,0 +1,173 @@
import React, { useState } from 'react';
import { Form, Button, Input, Col, Drawer, Row, Checkbox } from 'antd';
import { TableListItem } from '../data.d';
export interface FormValueType extends Partial<TableListItem> {
id?: number,
userName?: string,
userNo?: string,
password?: string,
permission?: string
permissions?: string
}
export interface UpdateFormProps {
onCancel: (flag?: boolean, formVals?: FormValueType) => void;
onSubmit: (values: FormValueType) => void;
updateModalVisible: boolean;
values: Partial<TableListItem>;
}
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const [formVals, setFormVals] = useState<FormValueType>({
id: props.values.id,
userNo: props.values.userNo,
userName: props.values.userName,
password: props.values.password,
permissions: props.values.permission ? JSON.parse(props.values.permission) : []
});
const permissions = [
{
label: '员工信息',
item: [
{
code: 'employeeQuery',
name: '查询'
},
{
code: 'employeeSave',
name: '编辑'
}
]
},
{
label: '数据统计',
item: [
{
code: 'dataQuery',
name: '查询'
}
]
},
{
label: '基本信息设置',
item: [
{
code: 'settingSave',
name: '编辑'
}
]
},
{
label: '账号管理',
item: [
{
code: 'userSave',
name: '编辑'
}
]
},
]
const [form] = Form.useForm();
const {
onSubmit: handleUpdate,
onCancel: handleUpdateModalVisible,
updateModalVisible,
values,
} = props;
const handleSubmit = async () => {
const fieldsValue = await form.validateFields();
console.log(fieldsValue)
setFormVals({ ...formVals, ...fieldsValue });
handleUpdate({ ...formVals, ...fieldsValue, permission: fieldsValue.permissions ? JSON.stringify(fieldsValue.permissions) : undefined });
};
return (
<Drawer
title={values.id?`编辑用户`:`添加用户`}
width={520}
onClose={() => handleUpdateModalVisible(false, values)}
visible={updateModalVisible}
bodyStyle={{ paddingBottom: 80 }}
footer={
<div
style={{
textAlign: 'right',
}}
>
<Button onClick={() => handleUpdateModalVisible(false, values)} style={{ marginRight: 8 }}>
</Button>
<Button onClick={handleSubmit} type="primary">
</Button>
</div>
}
>
<Form layout="vertical" form={form} initialValues={formVals}>
<Row gutter={16}>
<Col span={12}>
<Form.Item
name="userNo"
label="账号"
rules={[{ required: true, message: '请输入账号' }]}
>
<Input placeholder="请输入账号" />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item
name="userName"
label="姓名"
rules={[{ required: true, message: '请输入姓名' }]}
>
<Input placeholder="请输入姓名" />
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={24}>
<Form.Item
name="password"
label="密码"
rules={[{ required: true, message: '请输入密码' }]}
>
<Input.Password placeholder="请输入密码" />
</Form.Item>
</Col>
</Row>
<Row gutter={16}>
<Col span={24}>
<Form.Item
name="permissions"
label="权限设置"
rules={[{ required: true, message: '请选择权限' }]}
>
<Checkbox.Group style={{ width: '100%' }}>
{permissions.map(e => <Row>
<Col span={5}>
{e.label}
</Col>
{e.item.map(item => <Col span={4}>
<Checkbox value={item.code} style={{ lineHeight: '32px' }}>
{item.name}
</Checkbox>
</Col>)}
</Row>)}
</Checkbox.Group>
</Form.Item>
</Col>
</Row>
</Form>
</Drawer>
);
};
export default UpdateForm;

@ -0,0 +1,13 @@
export interface TableListItem {
id?: number,
userNo?: string,
userName?: string,
password?: string,
permission?: string,
}
export interface TableListPagination {
total: number,
pageSize: number | undefined,
current: number | undefined,
}

@ -0,0 +1,6 @@
@import '~antd/es/style/themes/default.less';
.main {
width: 100%;
background: @component-background;
}

@ -0,0 +1,216 @@
import React, { useState, useEffect } from "react";
import { Table, Card, message, Button, Popconfirm, Row, Col } from "antd";
import { ColumnsType } from "antd/es/table";
import { PageHeaderWrapper } from "@ant-design/pro-layout";
import { PaginationProps } from "antd/lib/pagination";
import { TableListItem } from "./data";
import { queryRule, updateRule, removeRule, addRule } from "./service";
import UpdateForm, { FormValueType } from './components/UpdateForm';
/**
*
* @param fields
*/
const handleUpdate = async (fields: FormValueType) => {
const hide = message.loading('正在保存');
if (!fields.id) {
// eslint-disable-next-line no-param-reassign
delete fields.id
try {
const msg = await addRule({...fields});
hide();
if (msg.retcode) {
message.success('添加成功');
} else {
message.error(msg.retmsg);
return false;
}
return true;
} catch (error) {
hide();
message.error('添加失败请重试!');
return false;
}
} else {
try {
const msg = await updateRule({...fields});
hide();
if (msg.retcode) {
message.success('保存成功');
} else {
message.error(msg.retmsg);
return false;
}
return true;
} catch (error) {
hide();
message.error('保存失败请重试!');
return false;
}
}
};
/**
*
* @param id
*/
const handleRemove = async (id?: number) => {
const hide = message.loading('正在删除');
if (!id) return false;
try {
const msg = await removeRule({
id
});
hide();
if (msg.retcode) {
message.success('删除成功,即将刷新');
} else {
message.error('删除失败,请重试');
}
return true;
} catch (error) {
hide();
message.error('删除失败,请重试');
return false;
}
};
const handleTableChange = async (params: any) => {
const param = {
pageNum: params.current,
pageSize: params.pageSize
}
const msg = await queryRule(param);
return {
data: msg.data?.list,
total: msg.data?.total,
success: msg.retcode,
};
};
const UserList: React.FC<{}> = () => {
const [data, handleDataChange] = useState<TableListItem[]>([]);
const [loading, handleLoadChange] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [stepFormValues, setStepFormValues] = useState({});
const [page, handlePageChange] = useState<PaginationProps>({
total: 0,
pageSize: 20,
current: 1,
pageSizeOptions: ['20'],
showTotal: ((total:number) => {
return `${total}`;
}),
});
const handleChange = async (pagination: any) => {
handleLoadChange(true)
const res = await handleTableChange(pagination);
handleLoadChange(false)
handleDataChange(res.data)
handlePageChange({
total: res.total,
pageSize: pagination.pageSize,
current: pagination.current,
})
}
const columns: ColumnsType<TableListItem> = [
{
title: "账号",
dataIndex: "userNo",
key: "userNo",
},
{
title: "姓名",
dataIndex: "userName",
key: "userName"
},
{
title: "操作",
key: "action",
render: (text, record) => (
<span>
<a style={{ marginRight: 8 }} onClick={()=>{
handleUpdateModalVisible(true);
setStepFormValues(record);
}}></a>
<Popconfirm title="确定删除该用户?" onConfirm={async () => {
const success = await handleRemove(record.id)
if (success) handleChange(page)
}}>
<a style={{color: 'red'}}></a>
</Popconfirm>
</span>
)
}
];
useEffect(() => {
async function fetchData() {
handleLoadChange(true)
page.current = 1
const res = await handleTableChange(page)
handleLoadChange(false)
page.total = res.total
handleDataChange(res.data)
}
fetchData()
}, []);
return (
<PageHeaderWrapper>
<Card bordered={false}>
<div id="components-table-demo-basic">
<Row justify="space-between">
<Col span={14} />
<Col span={10}>
<div style={{textAlign: 'right'}}>
<Button style={{marginBottom: 15}} type="primary" onClick={() => {
handleUpdateModalVisible(true);
setStepFormValues({
id: undefined,
});
}}>
</Button>
</div>
</Col>
</Row>
<Table
columns={columns}
rowKey="id"
dataSource={data}
pagination={page}
loading={loading}
onChange={async pagination => {
handleChange(pagination)
}}
/>
</div>
</Card>
{stepFormValues && Object.keys(stepFormValues).length ? (
<UpdateForm
onSubmit={async value => {
const success = await handleUpdate(value);
if (success) {
handleUpdateModalVisible(false);
setStepFormValues({});
handleChange(page)
}
}}
onCancel={() => {
handleUpdateModalVisible(false);
setStepFormValues({});
}}
updateModalVisible={updateModalVisible}
values={stepFormValues}
/>
) : null}
</PageHeaderWrapper>
)
}
export default UserList;

@ -0,0 +1,30 @@
import request from 'umi-request';
import { TableListItem } from './data.d';
export async function queryRule(params?: object) {
return request('/api/users/users-list', {
method: 'POST',
data: params,
});
}
export async function addRule(params: TableListItem) {
return request('/api/users/save-users', {
method: 'POST',
data: params,
});
}
export async function updateRule(params: TableListItem) {
return request('/api/users/save-users', {
method: 'POST',
data: params,
});
}
export async function removeRule(params: TableListItem) {
return request('/api/users/del-users', {
method: 'POST',
data: params,
});
}
Loading…
Cancel
Save