diff --git a/dist.zip b/dist.zip new file mode 100644 index 0000000..7c4c28f Binary files /dev/null and b/dist.zip differ diff --git a/package.json b/package.json index 7f0d301..abd3425 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@types/d3": "^7.4.0", "d3": "7.4.4", "d3-org-chart": "2.6.0", + "js-export-excel": "^1.1.4", "jspdf": "^2.5.1", "moment": "^2.29.3", "qs": "^6.11.0", diff --git a/public/img/user-card/avatar-outer-green.png b/public/img/user-card/avatar-outer-green.png new file mode 100644 index 0000000..aee791f Binary files /dev/null and b/public/img/user-card/avatar-outer-green.png differ diff --git a/public/img/user-card/jobicon-orange.png b/public/img/user-card/jobicon-orange.png new file mode 100644 index 0000000..3c5da8e Binary files /dev/null and b/public/img/user-card/jobicon-orange.png differ diff --git a/public/img/user-card/user-card-blue.png b/public/img/user-card/user-card-blue.png new file mode 100644 index 0000000..5a67581 Binary files /dev/null and b/public/img/user-card/user-card-blue.png differ diff --git a/public/img/user-card/user-card-green.png b/public/img/user-card/user-card-green.png new file mode 100644 index 0000000..13bae55 Binary files /dev/null and b/public/img/user-card/user-card-green.png differ diff --git a/public/img/user-card/user-card-orange.png b/public/img/user-card/user-card-orange.png new file mode 100644 index 0000000..d11807c Binary files /dev/null and b/public/img/user-card/user-card-orange.png differ diff --git a/public/img/user-card/绿色-虚线.png b/public/img/user-card/绿色-虚线.png new file mode 100644 index 0000000..a8a0f01 Binary files /dev/null and b/public/img/user-card/绿色-虚线.png differ diff --git a/src/components/drawer/index.jsx b/src/components/drawer/index.jsx index e434c86..d7437d4 100644 --- a/src/components/drawer/index.jsx +++ b/src/components/drawer/index.jsx @@ -1,11 +1,11 @@ import React from 'react'; -import { Drawer, Space, Button, Dropdown, Menu, Table } from 'antd'; +import { Drawer, Space, Button, Dropdown, Menu, Table, Spin } from 'antd'; import { OrgChartComponent } from '@/components/orgChart'; import * as d3 from 'd3'; import qs from 'qs'; import { message } from 'antd'; import jsPDF from 'jspdf'; -import styles from './index.less'; +import ExportJsonExcel from 'js-export-excel'; let addNodeChildFunc = null; let orgChart = null; @@ -18,12 +18,13 @@ export default class DrawerComponents extends React.Component { data: [], detailType: 'chart', rootId: '', + dataSource: [], + columns: [], + spinning: true, }; } - componentDidMount() { - //this.getDeatilDatas(); - } + componentDidMount() {} // 点击节点 onNodeClick(node) {} @@ -39,34 +40,29 @@ export default class DrawerComponents extends React.Component { if (idsList.length == 0) { return; } - let idsStr = idsList.join(','); - let api = '/api/bs/hrmorganization/orgchart/asyncUserData?ids=' + idsStr; - fetch(api) - .then((res) => res.json()) - .then((data) => { - if (data.data) { - data.data.forEach((item) => { - window.chart.addNode(item); - }); - } - }); } } // 获取部门图片 - getDepartmentImage() { - let index = Math.floor(Math.random() * 8) + 1; - return `./img/department/${index}.png`; + getDepartmentImage(fisvitual) { + return fisvitual == '0' + ? `./img/user-card/user-card.png` + : `./img/user-card/user-card-blue.png`; } //获取数据 - getDeatilDatas(rootId) { - const { detailType } = this.state; + getDeatilDatas(rootId, type = 'chart') { + this.setState({ spinning: true }); d3.json( - '/api/bs/hrmorganization/orgchart/userData?' + - qs.stringify({ detauleType: detailType, rootId: rootId }), + '/api/bs/hrmorganization/orgchart/getDepartmentDetail?' + + qs.stringify({ detauleType: type, rootId: rootId }), ).then((data) => { - this.setState(data.data); + // + if (type == 'chart') { + this.setState({ data: data.data, spinning: false }); + } else { + this.setState({ dataSource: data.dataSource, columns: data.columns }); + } }); } @@ -133,7 +129,7 @@ export default class DrawerComponents extends React.Component { orgChart && orgChart.zoomOut(); }; - downloadPdf(chart) { + downloadPdf = (chart) => { chart.exportImg({ save: false, full: true, @@ -154,14 +150,64 @@ export default class DrawerComponents extends React.Component { }; }, }); - } + }; handleExport = (e) => { - let type = e.key == '1' ? 'png' : 'pdf'; + let type = e.key == '1' ? 'png' : e.key == '1' ? 'pdf' : 'excel'; if (type == 'png') { orgChart && orgChart.exportImg({ full: true }); + } else if (type == 'pdf') { + orgChart && this.downloadPdf(orgChart); } else { - orgChart && downloadPdf(orgChart); + let { dataSource } = this.state; + var option = {}; + let dataTable = []; + if (dataSource) { + for (let i in dataSource) { + if (dataSource) { + let obj = { + 序号: dataSource[i].id, + 工号: dataSource[i].workCode, + 姓名: dataSource[i].lastName, + 性别: dataSource[i].sex, + 部门: dataSource[i].departmentId, + 分部: dataSource[i].subcompanyid1, + 岗位: dataSource[i].jobTitle, + 手机号: dataSource[i].mobile, + }; + dataTable.push(obj); + } + } + } + option.fileName = '组织信息'; + option.datas = [ + { + sheetData: dataTable, + sheetName: 'sheet', + sheetFilter: [ + '序号', + '工号', + '姓名', + '性别', + '部门', + '分部', + '岗位', + '手机号', + ], + sheetHeader: [ + '序号', + '工号', + '姓名', + '性别', + '部门', + '分部', + '岗位', + '手机号', + ], + }, + ]; + var toExcel = new ExportJsonExcel(option); + toExcel.saveExcel(); } }; @@ -173,40 +219,41 @@ export default class DrawerComponents extends React.Component { return `