From 3f034f4b9ae7173e76bf41853bc73134ce59e896 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 17 Jul 2023 08:37:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.ts | 12 +- src/models/login.ts | 8 +- .../components/UpdateEducationResumeForm.tsx | 34 ++- .../components/UpdateFamilyMembersForm.tsx | 20 +- src/pages/Employee/components/UpdateForm.tsx | 136 ++++++----- .../components/UpdateWorkExperienceForm.tsx | 15 +- src/pages/Employee/data.d.ts | 2 + src/pages/Employee/index.tsx | 121 +++++----- src/pages/UserList/components/UpdateForm.tsx | 173 ++++++++++++++ src/pages/UserList/data.d.ts | 13 ++ src/pages/UserList/index.less | 6 + src/pages/UserList/index.tsx | 216 ++++++++++++++++++ src/pages/UserList/service.ts | 30 +++ 13 files changed, 643 insertions(+), 143 deletions(-) create mode 100644 src/pages/UserList/components/UpdateForm.tsx create mode 100644 src/pages/UserList/data.d.ts create mode 100644 src/pages/UserList/index.less create mode 100644 src/pages/UserList/index.tsx create mode 100644 src/pages/UserList/service.ts diff --git a/config/config.ts b/config/config.ts index ac7143a..81579d5 100644 --- a/config/config.ts +++ b/config/config.ts @@ -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', }, diff --git a/src/models/login.ts b/src/models/login.ts index 580e75d..6888d73 100644 --- a/src/models/login.ts +++ b/src/models/login.ts @@ -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, diff --git a/src/pages/Employee/components/UpdateEducationResumeForm.tsx b/src/pages/Employee/components/UpdateEducationResumeForm.tsx index 6dcb555..bf92eb2 100644 --- a/src/pages/Employee/components/UpdateEducationResumeForm.tsx +++ b/src/pages/Employee/components/UpdateEducationResumeForm.tsx @@ -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 { + degree?: string; + isEducation?: string; education?: string; school?: string; speciality?: string; @@ -32,6 +35,8 @@ const UpdateEducationResumeForm: React.FC = (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 = (props) => { - - + + - - + + - - + + - - - - - - - - - - - - diff --git a/src/pages/Employee/components/UpdateFamilyMembersForm.tsx b/src/pages/Employee/components/UpdateFamilyMembersForm.tsx index 15eb630..670dd4f 100644 --- a/src/pages/Employee/components/UpdateFamilyMembersForm.tsx +++ b/src/pages/Employee/components/UpdateFamilyMembersForm.tsx @@ -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 { 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 = (props) => { const [formVals, setFormVals] = useState({ id: props.values.id, @@ -23,6 +28,8 @@ const UpdateFamilyMembersForm: React.FC = (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 = (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 = (props) => { - - + + + + + + + diff --git a/src/pages/Employee/components/UpdateForm.tsx b/src/pages/Employee/components/UpdateForm.tsx index a677084..8ad32ab 100644 --- a/src/pages/Employee/components/UpdateForm.tsx +++ b/src/pages/Employee/components/UpdateForm.tsx @@ -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 { @@ -255,11 +254,22 @@ const UpdateForm: React.FC = (props) => { const educationResumeColumns: ColumnsType = [ { - 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 = (props) => { dataIndex: 'speciality', }, { - title: '就业学历', - dataIndex: 'education', - }, - { - title: '本科学历学校', - dataIndex: 'undergraduateSchools', + title: '毕业时间', + dataIndex: 'graduationTime' }, + ]; + const educationResumeColumns1: ColumnsType = [ { - 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 = [ { - 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 = (props) => { dataIndex: 'relation', }, { - title: '电话', - dataIndex: 'relationMobile', + title: '工作单位', + dataIndex: 'workUnit', + }, + { + title: '出生日期', + dataIndex: 'birthday', }, ]; const familyMembersColumns1: ColumnsType = [ @@ -370,8 +364,12 @@ const UpdateForm: React.FC = (props) => { dataIndex: 'relation', }, { - title: '电话', - dataIndex: 'relationMobile', + title: '工作单位', + dataIndex: 'workUnit', + }, + { + title: '出生日期', + dataIndex: 'birthday', }, { title: '操作', @@ -402,29 +400,37 @@ const UpdateForm: React.FC = (props) => { ]; const workExperienceColumns: ColumnsType = [ { - title: '现岗位', - dataIndex: 'transferredPosition', + title: '部门', + dataIndex: 'department', }, { - title: '原岗位', - dataIndex: 'originalPosition', + title: '班组', + dataIndex: 'groups', }, { - title: '调岗日期', + title: '岗位', + dataIndex: 'transferredPosition', + }, + { + title: '起始时间', dataIndex: 'transferDate', }, ]; const workExperienceColumns1: ColumnsType = [ { - 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 = (props) => { const promiseResolveRef: any = useRef(null); const [loading, setLoading] = useState(false); + const [isEdit, setIsEdit] = useState(false); const [imageUrl, setImageUrl] = useState(props.values.employeeName && props.values.cardNo ? `http://localhost:8888/upload/${props.values.employeeName}_${props.values.cardNo}.jpg`:''); const handleChange: UploadProps['onChange'] = (info: UploadChangeParam) => { @@ -755,7 +762,14 @@ const UpdateForm: React.FC = (props) => { } }, [props.values.employeeNo]); - console.log(imageUrl) + console.log(getAuthority()) + + useEffect(() => { + const list = getAuthority() + if (list.includes('employeeSave')) { + setIsEdit(true) + } + }, []) return ( = (props) => { 导出Excel ) : null} - + : null} + } > @@ -800,6 +815,7 @@ const UpdateForm: React.FC = (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 = (props) => { -
+ = (props) => {
教育履历{' '} - {isPrint ? null : , - { - actionRef.current?.reload(); - }} - />, - { - actionRef.current?.reload(); - }} - />, - { - actionRef.current?.reload(); - }} - />, - { - actionRef.current?.reload(); - }} - />, - { - actionRef.current?.reload(); - }} - />, + }> + + , + }> + { + actionRef.current?.reload(); + }} + /> + , + }> + { + actionRef.current?.reload(); + }} + /> + , + }> + { + actionRef.current?.reload(); + }} + /> + , + }> + { + actionRef.current?.reload(); + }} + /> + , + }> + { + actionRef.current?.reload(); + }} + /> + , + +
+ } + > + + + + + + + + + + + + + + + + + + + + + + + + + {permissions.map(e => + + {e.label} + + {e.item.map(item => + + {item.name} + + )} + )} + + + + + + + ); +}; + +export default UpdateForm; \ No newline at end of file diff --git a/src/pages/UserList/data.d.ts b/src/pages/UserList/data.d.ts new file mode 100644 index 0000000..f15641b --- /dev/null +++ b/src/pages/UserList/data.d.ts @@ -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, +} \ No newline at end of file diff --git a/src/pages/UserList/index.less b/src/pages/UserList/index.less new file mode 100644 index 0000000..7cca51e --- /dev/null +++ b/src/pages/UserList/index.less @@ -0,0 +1,6 @@ +@import '~antd/es/style/themes/default.less'; + +.main { + width: 100%; + background: @component-background; +} diff --git a/src/pages/UserList/index.tsx b/src/pages/UserList/index.tsx new file mode 100644 index 0000000..a696dc8 --- /dev/null +++ b/src/pages/UserList/index.tsx @@ -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([]); + const [loading, handleLoadChange] = useState(false); + const [updateModalVisible, handleUpdateModalVisible] = useState(false); + const [stepFormValues, setStepFormValues] = useState({}); + const [page, handlePageChange] = useState({ + 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 = [ + { + title: "账号", + dataIndex: "userNo", + key: "userNo", + }, + { + title: "姓名", + dataIndex: "userName", + key: "userName" + }, + { + title: "操作", + key: "action", + render: (text, record) => ( + + { + handleUpdateModalVisible(true); + setStepFormValues(record); + }}>编辑 + { + const success = await handleRemove(record.id) + if (success) handleChange(page) + }}> + 删除 + + + ) + } + ]; + 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 ( + + +
+ + + +
+ +
+ +
+ + { + handleChange(pagination) + }} + /> + + + {stepFormValues && Object.keys(stepFormValues).length ? ( + { + const success = await handleUpdate(value); + + if (success) { + handleUpdateModalVisible(false); + setStepFormValues({}); + + handleChange(page) + } + }} + onCancel={() => { + handleUpdateModalVisible(false); + setStepFormValues({}); + }} + updateModalVisible={updateModalVisible} + values={stepFormValues} + /> + ) : null} + + ) +} + +export default UserList; \ No newline at end of file diff --git a/src/pages/UserList/service.ts b/src/pages/UserList/service.ts new file mode 100644 index 0000000..5a38da2 --- /dev/null +++ b/src/pages/UserList/service.ts @@ -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, + }); +} \ No newline at end of file