Browse Source

人员信息导入相关代码暂交

master
wuqun 2 years ago
parent
commit
d6e763f57c
  1. 12
      web/.vscode/launch.json
  2. 2
      web/client/src/layout/actions/webSocket.js
  3. 69
      web/client/src/sections/example/containers/example.jsx
  4. 70
      web/client/src/sections/example/containers/export-members-modal.jsx
  5. 1
      web/package.json
  6. 61
      web/routes/attachment/index.js

12
web/.vscode/launch.json

@ -7,12 +7,20 @@
"request": "launch",
"program": "${workspaceRoot}/server.js",
"args": [
"-u http://127.0.0.1:4000"
"-p 5700",
"-u http://127.0.0.1:4000",
"--apiHrUrl http://localhost:4700",
"--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5",
"--qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa",
"--qnbkt dev-hr",
"--qndmn http://rjkwed13l.hn-bkt.clouddn.com",
// "-v 0.2.0",
// "-h 22"
],
"outputCapture": "std",
"env": {
"NODE_ENV": "development"
}
}
}
]
}

2
web/client/src/layout/actions/webSocket.js

@ -12,7 +12,7 @@ export function initWebSocket ({ ioUrl, token, pomsUserId }) {
if (user) {
user = JSON.parse(user)
token = user.token
pomsUserId = user.pomsUserInfo.id
pomsUserId = user.pomsUserInfo?.id
}
}
if (!ioUrl || !token || !pomsUserId) {

69
web/client/src/sections/example/containers/example.jsx

@ -1,45 +1,48 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { connect } from 'react-redux';
import { Spin, Card } from '@douyinfe/semi-ui';
import { Spin, Card, Button } from '@douyinfe/semi-ui';
import ExportMembersModal from './export-members-modal'
import '../style.less'
const { Meta } = Card;
const Example = (props) => {
const { dispatch, actions, user, loading, socket } = props
const [exportModalVs, setExportModalVs] = useState(false);
useEffect(() => {
// ACTION
// dispatch(actions.example.getMembers(user.orgId))
// dispatch(actions.example.getMembers(user.orgId))
}, [])
// websocket 使
// useEffect(() => {
// console.log(socket)
// if (socket) {
// socket.on('TEST', function (msg) {
// console.info(msg);
// });
// return () => {
// socket.off("TEST");
// }
// }
// useEffect(() => {
// console.log(socket)
// if (socket) {
// socket.on('TEST', function (msg) {
// console.info(msg);
// });
// return () => {
// socket.off("TEST");
// }
// }
// }, [socket])
// }, [socket])
return (
<Spin tip="biubiubiu~" spinning={loading}>
<Spin tip="biubiubiu~" spinning={false}>
<div id='example'>
<div className="loader1">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div className='loader2'>
<div className="loader1">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div className='loader2'>
</div>
</div>
<p>STYLE EXAMPLE</p>
<Button type="primary" onClick={() => setExportModalVs(true)}>test上传</Button>
</div>
{/* <Card
style={{ maxWidth: 300 }}
@ -52,18 +55,22 @@ const Example = (props) => {
>
<Meta title="组件示例" />
</Card> */}
{
exportModalVs ? <ExportMembersModal user={user}
onCancel={() => setExportModalVs(false)} /> : ''
}
</Spin>
)
}
function mapStateToProps (state) {
function mapStateToProps(state) {
const { auth, global, members, webSocket } = state;
return {
// loading: members.isRequesting,
// user: auth.user,
// actions: global.actions,
// members: members.data,
// socket: webSocket.socket
// loading: members.isRequesting,
user: auth.user,
// actions: global.actions,
// members: members.data,
// socket: webSocket.socket
};
}

70
web/client/src/sections/example/containers/export-members-modal.jsx

@ -0,0 +1,70 @@
import React, { useEffect, useState } from 'react';
import { Modal, Form, Button, Upload } from '@douyinfe/semi-ui';
import { IconUpload } from '@douyinfe/semi-icons';
import ExportJsonExcel from 'js-export-excel';
const ExportMembersModal = (props) => {
const { onCancel, user } = props;
useEffect(() => {
}, []);
const handleOk = () => {
}
const download = () => {
dldTemplate();
dldText("填写说明.txt", "12121212121212");
}
const dldTemplate = () => {
let dataTable = [];
let option = {};
option.fileName = '人资系统人员信息导入模板';
option.datas = [
{
sheetData: dataTable,
sheetName: '人资系统人员信息导入模板',
sheetFilter: ['人员编号', '姓名', '证件号', '性别(男/女)', '出生年月日(例2022/02/01)', '籍贯', '婚育状态(已婚/未婚/已婚已育)', '政治面貌', '联系方式', '工作地点', '毕业院校', '学历', '专业', '毕业时间', '入职时间', '转试用期时间', '转正时间', '离职日期', '工作经验(年)', '历史工作经历与职务'], //excel
sheetHeader: ['人员编号', '姓名', '证件号', '性别(男/女)', '出生年月日(例2022/02/01)', '籍贯', '婚育状态(已婚/未婚/已婚已育)', '政治面貌', '联系方式', '工作地点', '毕业院校', '学历', '专业', '毕业时间', '入职时间', '转试用期时间', '转正时间', '离职日期', '工作经验(年)', '历史工作经历与职务'], //excel
}
]
let toExcel = new ExportJsonExcel(option); //excel
toExcel.saveExcel(); //excel
}
const dldText = (filename, text) => {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
const action = '/_file-server/upload?type=excel&token=' + user.token;
const fileLimit = '.xls,.xlsx,.csv';
return (
<Modal title="导入信息" visible={true} okText='完成'
onOk={() => handleOk(null)}
onCancel={onCancel}>
<Form>
<Form.Upload label={'员工信息'} labelPosition='left' action={action} accept={fileLimit} maxSize={200}>
<Button icon={<IconUpload />} theme="light">
请选择文件
</Button>
</Form.Upload>
<div style={{ color: '#ccc' }}>最大不超过200M导入文件需与
<span onClick={() => download()} style={{ cursor: 'pointer', color: '#0066FF' }}>导入模板</span>
一致</div>
</Form>
</Modal>
)
}
export default ExportMembersModal;

1
web/package.json

@ -63,6 +63,7 @@
"ezuikit-js": "^0.6.1",
"fs-attachment": "^1.0.0",
"fs-web-server-scaffold": "^1.0.6",
"js-export-excel": "^1.1.4",
"koa-better-http-proxy": "^0.2.5",
"koa-proxy": "^1.0.0-alpha.3",
"koa-view": "^2.1.4",

61
web/routes/attachment/index.js

@ -12,7 +12,8 @@ const ext = {
three: [".js"],
video: [".mp4"],
bpmn: [".bpmn", ".bpmn20.xml", ".zip", ".bar"],
app: [".apk"]
app: [".apk"],
excel: ['.xls', '.xlsx', '.csv'],
}
module.exports = {
@ -47,7 +48,65 @@ module.exports = {
}
}
let upload = async function (ctx, next) {
try {
const { token } = ctx.request.query
if (token) {
const { files } = await parse(ctx.req)
const file = files[0]
const extname = path.extname(file.filename).toLowerCase()
const ftype = ctx.query.type;
if (!(FILE_TYPE[ftype] || []).includes(extname)) {
ctx.status = 400
ctx.body = { error: '文件格式无效' }
return;
}
const fileInfo = await app.fs.attachment.upload(file, { uploadPath: ftype }) // uploadPath: 附件存放的文件夹
ctx.status = 200;
console.log(fileInfo);
console.log('0000000000000000000000');
ctx.body = { uploaded: fileInfo.key } // key: `${uploadPath}/${uuid}/${filename}`
} else {
ctx.status = 403
ctx.body = { name: 'Forbidden', message: 'token无效,禁止访问' }
}
} catch (err) {
ctx.status = 400
ctx.body = {
name: 'BadRequest',
message: 'error happened while uploading file to qiniu.'
}
}
}
let remove = async function (ctx, next) {
try {
const { token } = ctx.request.query
if (token) {
const { fkeys } = ctx.request.body
for (let index = 0; index < fkeys.length; index++) {
await app.fs.attachment.remove(fkeys[index])
}
ctx.status = 200
ctx.body = { fkeys }
} else {
ctx.status = 403
ctx.body = { name: 'Forbidden', message: 'token无效,禁止访问' }
}
} catch (err) {
ctx.status = 400
ctx.body = {
name: 'BadRequest',
message: 'error happened while removing file from qiniu.'
}
}
}
router.use(download);
router.get('/api/root', getApiRoot);
router.post('/_file-server/upload', upload);
router.post('/_file-server/remove', remove);
}
};

Loading…
Cancel
Save