2023-06-30 16:39:00 +08:00
import React from 'react' ;
2023-07-07 16:37:05 +08:00
import {
Drawer ,
Space ,
Button ,
Dropdown ,
Menu ,
Table ,
Spin ,
Checkbox ,
} from 'antd' ;
2023-06-30 16:39:00 +08:00
import { OrgChartComponent } from '@/components/orgChart' ;
import * as d3 from 'd3' ;
import qs from 'qs' ;
import { message } from 'antd' ;
import jsPDF from 'jspdf' ;
2023-07-06 16:23:45 +08:00
import ExportJsonExcel from 'js-export-excel' ;
2023-07-07 16:37:05 +08:00
import './index.less' ;
2024-06-05 16:01:37 +08:00
import { getLabel } from '../../util/i18n.js' ;
2023-06-30 16:39:00 +08:00
let addNodeChildFunc = null ;
let orgChart = null ;
let active = 'top' ;
export default class DrawerComponents extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
open : false ,
data : [ ] ,
detailType : 'chart' ,
2023-07-14 14:46:14 +08:00
params : { } ,
2023-07-06 16:23:45 +08:00
dataSource : [ ] ,
columns : [ ] ,
spinning : true ,
2024-05-08 16:31:15 +08:00
showJob : false ,
2023-06-30 16:39:00 +08:00
} ;
}
2023-07-06 16:23:45 +08:00
componentDidMount ( ) { }
2023-06-30 16:39:00 +08:00
// 点击节点
2024-05-08 16:31:15 +08:00
onNodeClick ( node ) {
if ( node . ftype == '4' ) {
window . open (
` /spa/hrm/index_mobx.html#/main/hrm/card/cardInfo/ ${ node . id } ` ,
'_blank' ,
) ;
}
}
2023-06-30 16:39:00 +08:00
onButtonClick ( event , d ) {
if ( d . children ) {
let idsList = [ ] ;
d . children . forEach ( ( item ) => {
if ( item . data . hasChildren && ! item . _children ) {
idsList . push ( item . data . id ) ;
}
} ) ;
if ( idsList . length == 0 ) {
return ;
}
}
}
// 获取部门图片
2023-07-06 16:23:45 +08:00
getDepartmentImage ( fisvitual ) {
return fisvitual == '0'
? ` ./img/user-card/user-card.png `
: ` ./img/user-card/user-card-blue.png ` ;
2023-06-30 16:39:00 +08:00
}
//获取数据
2024-06-17 11:07:10 +08:00
getDeatilDatas ( params , type = 'chart' , showJob = '0' ) {
2024-05-08 16:31:15 +08:00
this . setState ( { spinning : true , data : [ ] , dataSource : [ ] } ) ;
2023-06-30 16:39:00 +08:00
d3 . json (
2023-07-06 16:23:45 +08:00
'/api/bs/hrmorganization/orgchart/getDepartmentDetail?' +
2023-07-14 14:46:14 +08:00
qs . stringify ( { detauleType : type , ... params , showJob } ) ,
2023-06-30 16:39:00 +08:00
) . then ( ( data ) => {
2023-07-06 16:23:45 +08:00
//
if ( type == 'chart' ) {
this . setState ( { data : data . data , spinning : false } ) ;
} else {
2024-05-08 16:31:15 +08:00
this . setState ( {
dataSource : data . dataSource ,
columns : data . columns ,
spinning : false ,
} ) ;
2023-07-06 16:23:45 +08:00
}
2023-06-30 16:39:00 +08:00
} ) ;
}
// ButtonContent渲染
buttonContentRender = ( { node , state } ) => {
return `
< div style = "margin-left: 16px; margin-top: 10px;" >
< img src = "./img/button_content.png" / >
< / div >
` ;
} ;
// 节点宽度渲染
nodeWidthRender = ( d ) => {
return 280 ;
} ;
nodeHeightRender = ( d ) => {
return 160 ;
} ;
// tool bar start
handleTopLayoutClick = ( progressBtn ) => {
progressBtn . current . style . top = 50 + 'px' ;
orgChart &&
orgChart
. setCentered ( orgChart . getChartState ( ) . root . id )
. layout ( 'top' )
. render ( ) ;
active = 'top' ;
} ;
handleLeftLayoutClick = ( progressBtn ) => {
progressBtn . current . style . top = 50 + 'px' ;
orgChart &&
orgChart
. layout ( 'left' )
. setCentered ( orgChart . getChartState ( ) . root . id )
. render ( ) ;
active = 'left' ;
} ;
handleZoomIn = ( progressBtn ) => {
if ( progressBtn ) {
let top = parseInt ( progressBtn . current . style . top ) - 10 ;
if ( top >= 0 ) {
progressBtn . current . style . top = top + 'px' ;
} else {
return ;
}
}
orgChart && orgChart . zoomIn ( ) ;
} ;
handleZoomOut = ( progressBtn ) => {
if ( progressBtn ) {
let top = parseInt ( progressBtn . current . style . top ) + 10 ;
if ( top <= 100 ) {
progressBtn . current . style . top = top + 'px' ;
} else {
return ;
}
}
orgChart && orgChart . zoomOut ( ) ;
} ;
2023-07-06 16:23:45 +08:00
downloadPdf = ( chart ) => {
2023-06-30 16:39:00 +08:00
chart . exportImg ( {
save : false ,
full : true ,
onLoad : ( base64 ) => {
var pdf = new jsPDF ( ) ;
var img = new Image ( ) ;
img . src = base64 ;
img . onload = function ( ) {
pdf . addImage (
img ,
'JPEG' ,
5 ,
5 ,
595 / 3 ,
( ( img . height / img . width ) * 595 ) / 3 ,
) ;
pdf . save ( 'chart.pdf' ) ;
} ;
} ,
} ) ;
2023-07-06 16:23:45 +08:00
} ;
2023-06-30 16:39:00 +08:00
handleExport = ( e ) => {
2024-06-05 16:01:37 +08:00
const { labelData } = this . props ;
2023-07-06 16:23:45 +08:00
let type = e . key == '1' ? 'png' : e . key == '1' ? 'pdf' : 'excel' ;
2023-06-30 16:39:00 +08:00
if ( type == 'png' ) {
orgChart && orgChart . exportImg ( { full : true } ) ;
2023-07-06 16:23:45 +08:00
} else if ( type == 'pdf' ) {
orgChart && this . downloadPdf ( orgChart ) ;
2023-06-30 16:39:00 +08:00
} else {
2023-07-06 16:23:45 +08:00
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 ,
2023-08-25 14:08:17 +08:00
部门 : dataSource [ i ] . departmentName ,
分部 : dataSource [ i ] . subcompanyName ,
2023-07-06 16:23:45 +08:00
岗位 : dataSource [ i ] . jobTitle ,
手机号 : dataSource [ i ] . mobile ,
} ;
dataTable . push ( obj ) ;
}
}
}
2024-06-05 16:01:37 +08:00
option . fileName = ` ${ getLabel ( 547468 , labelData ) } ` ;
2023-07-06 16:23:45 +08:00
option . datas = [
{
sheetData : dataTable ,
sheetName : 'sheet' ,
sheetFilter : [
2024-06-05 16:01:37 +08:00
` ${ getLabel ( 547327 , labelData ) } ` ,
` ${ getLabel ( 547328 , labelData ) } ` ,
` ${ getLabel ( 547329 , labelData ) } ` ,
` ${ getLabel ( 547330 , labelData ) } ` ,
` ${ getLabel ( 547331 , labelData ) } ` ,
` ${ getLabel ( 547332 , labelData ) } ` ,
` ${ getLabel ( 547333 , labelData ) } ` ,
` ${ getLabel ( 547334 , labelData ) } ` ,
2023-07-06 16:23:45 +08:00
] ,
sheetHeader : [
2024-06-05 16:01:37 +08:00
` ${ getLabel ( 547327 , labelData ) } ` ,
` ${ getLabel ( 547328 , labelData ) } ` ,
` ${ getLabel ( 547329 , labelData ) } ` ,
` ${ getLabel ( 547330 , labelData ) } ` ,
` ${ getLabel ( 547331 , labelData ) } ` ,
` ${ getLabel ( 547332 , labelData ) } ` ,
` ${ getLabel ( 547333 , labelData ) } ` ,
` ${ getLabel ( 547334 , labelData ) } ` ,
2023-07-06 16:23:45 +08:00
] ,
} ,
] ;
var toExcel = new ExportJsonExcel ( option ) ;
toExcel . saveExcel ( ) ;
2023-06-30 16:39:00 +08:00
}
} ;
/ * *
* 节点渲染
* /
nodeContentRender = ( d , i , arr , state ) => {
2024-06-05 16:01:37 +08:00
const { labelData } = this . props ;
2023-06-30 16:39:00 +08:00
if ( d . data . ftype == 2 ) {
return ` <div style="position: relative;">
< div style = " height: 152px;background-size: 100% 100%;box-sizing: border-box;padding-top: 30px;position:relative;z-index:2" >
< div style = 'position:absolute;z-index:-1;top:0' >
2023-07-06 16:23:45 +08:00
< img style = 'width: 295px;height: 163px;' src = " $ { this.getDepartmentImage (
d . data . fisvitual ,
) } " >
2023-06-30 16:39:00 +08:00
< / div >
< div style = "display: inline-block; background-size: 100% 100%; width: 35%; height: 90px; text-align:center; vertical-align: top; margin-left: 11px;box-sizing: border;" >
< img src = './img/user-card/avatar-outer.png' style = 'position:absolute;width:90px;height:90px;left:11px' / >
< img src = "./img/department.png" style = "width: 58px; height: 58px;position:absolute;left:29px; border-radius: 50%; margin-top: 16px;position:absolute;left:29px;z-index:999" / >
< / div >
< div style = "display: inline-block; margin-left: 6px;width: 55%" >
2023-07-24 16:58:41 +08:00
< div class = "dept-box" style = "font-size: 15px;font-family: Microsoft YaHei-Regular, Microsoft YaHei;font-weight: 900;color: #333333;height: 25px;line-height: 25px;width:110px,white-space:nowrap;overflow:hidden;text-overflow:ellipsis;" >
2023-07-06 16:23:45 +08:00
$ { d . data . fname }
< / div >
2024-06-17 11:07:10 +08:00
< div style = "font-size: 13px;font-family: Microsoft YaHei-Bold, Microsoft YaHei;color: #333333;line-height: 25px;" >
$ { getLabel ( 547190 , labelData ) } : $ { d . data . fleader }
2023-06-30 16:39:00 +08:00
< / div >
2023-07-06 16:23:45 +08:00
< div style = "display:flex" >
< div style = "height: 25px; line-height: 25px; min-width: 80px;" >
2024-06-05 16:01:37 +08:00
$ { getLabel ( 547323 , labelData ) } : $ {
d . data . fonjob
} $ { getLabel ( 547525 , labelData ) }
2023-07-06 16:23:45 +08:00
< / div >
2023-06-30 16:39:00 +08:00
< / div >
< / div >
2023-07-06 16:23:45 +08:00
2023-06-30 16:39:00 +08:00
< / div >
< / div > ` ;
} else if ( d . data . ftype == 3 ) {
return ` <div style="position: relative;">
< div style = " height: 152px;background-size: 100% 100%;box-sizing: border-box;padding-top: 40px;" >
2023-07-06 16:23:45 +08:00
< div style = 'position:absolute;z-index:-1;top:0' >
< img style = 'width: 295px;height: 163px;' src = './img/user-card/user-card-orange.png' >
2023-06-30 16:39:00 +08:00
< / div >
2023-07-06 16:23:45 +08:00
< img src = "./img/user-card/jobicon-orange.png" style = "margin-left: 20px; vertical-align: top;" / >
2023-06-30 16:39:00 +08:00
< div style = "display: inline-block; margin-left: 15px;" >
2024-06-05 16:01:37 +08:00
< div style = "font-size: 15px;height: 25px;line-height: 25px;font-family: Microsoft YaHei-Bold, Microsoft YaHei;font-weight: bold;color: #333333;" > $ {
d . data . fname
} < / div >
2023-07-06 16:23:45 +08:00
< div style = "font-size: 13px;font-family: Microsoft YaHei-Regular, Microsoft YaHei;font-weight: 400;color: #333333;display: flex;height: 25px;line-height: 25px;" >
2024-06-05 16:01:37 +08:00
< span > $ { getLabel ( 547323 , labelData ) } : $ {
d . data . fonjob
} $ { getLabel ( 547525 , labelData ) } < / span >
2023-06-30 16:39:00 +08:00
< / div >
< / div >
< / div >
< / div > ` ;
} else if ( d . data . ftype == 4 ) {
return ` <div style="position: relative;" >
< div style = "height: 152px;background-size: 100% 100%;box-sizing: border-box;padding-top: 30px;" >
2023-07-06 16:23:45 +08:00
< div style = 'position:absolute;z-index:-1;top:0px' >
< img style = 'width: 295px;height: 163px;' src = './img/user-card/user-card-green.png' >
2023-06-30 16:39:00 +08:00
< / div >
2023-07-06 16:23:45 +08:00
< div style = "display: inline-block; background-size: 100% 100%; width: 35%; height: 90px; text-align:center; vertical-align: top; margin-left: 11px;box-sizing: border;" >
< img src = './img/user-card/avatar-outer-green.png' style = 'position:absolute;width:90px;height:90px;left:11px;z-index:-1' / >
< img src = " $ {
d . data . fleaderimg
? d . data . fleaderimg
: './img/default_avator.png'
} " style=" width : 58 px ; height : 58 px ; border - radius : 50 % ; margin - top : 16 px ; margin - left : - 6 px ; z - index : 999 " / >
< / div >
< div style = "display: inline-block; margin-left: 6px;width: 55%;height:100%" >
2024-06-05 16:01:37 +08:00
< div style = 'display:flex;align-items:center;height: 25px;line-height: 25px;margin-top:2px' >
2023-07-06 16:23:45 +08:00
< div style = "font-weight: bold;font-size: 15px;ont-family: Microsoft YaHei-Bold, Microsoft YaHei;color: #333333;" > $ {
d . data . fname
} < / div >
2023-06-30 16:39:00 +08:00
< / div >
2024-06-17 11:07:10 +08:00
< div style = "font-size: 13px;font-family: Microsoft YaHei-Regular, Microsoft YaHei;font-weight: 400;color: #333333;display: flex;line-height: 25px;" >
2024-06-05 16:01:37 +08:00
< span > $ { getLabel ( 547324 , labelData ) } : $ {
d . data . companyWorkYear
} $ { getLabel ( 547526 , labelData ) } < / span >
2023-06-30 16:39:00 +08:00
< / div >
2024-06-17 11:07:10 +08:00
< div style = "font-size: 13px;font-family: Microsoft YaHei-Regular, Microsoft YaHei;font-weight: 400;color: #333333;display: flex;line-height: 25px;" >
< span > $ { getLabel ( 547333 , labelData ) } : $ {
d . data . jobName
} < / span >
< / div >
2023-06-30 16:39:00 +08:00
< / div >
2023-07-06 16:23:45 +08:00
< / div >
2023-06-30 16:39:00 +08:00
< / div > ` ;
}
} ;
2023-07-14 14:46:14 +08:00
showDrawer = ( params ) => {
2024-05-08 16:31:15 +08:00
this . getDeatilDatas ( params , 'chart' , '0' ) ;
2023-07-14 14:46:14 +08:00
this . setState ( { open : true , params : params } ) ;
2023-06-30 16:39:00 +08:00
} ;
onClose = ( ) => {
2024-05-08 16:31:15 +08:00
this . setState ( { open : false , detailType : 'chart' , showJob : false } ) ;
2023-06-30 16:39:00 +08:00
} ;
changeDetail = ( ) => {
2023-07-14 14:46:14 +08:00
const { detailType , params } = this . state ;
2023-07-06 16:23:45 +08:00
let type = detailType == 'chart' ? 'table' : 'chart' ;
2024-06-17 11:07:10 +08:00
const showJob = '0' ;
2023-06-30 16:39:00 +08:00
this . setState ( {
2023-07-06 16:23:45 +08:00
detailType : type ,
2023-06-30 16:39:00 +08:00
} ) ;
2023-07-14 14:46:14 +08:00
this . getDeatilDatas ( params , type , showJob ) ;
2023-06-30 16:39:00 +08:00
} ;
render ( ) {
2023-07-07 16:37:05 +08:00
const {
2023-07-14 14:46:14 +08:00
params ,
2023-07-07 16:37:05 +08:00
open ,
data ,
detailType ,
dataSource ,
columns ,
spinning ,
showJob ,
} = this . state ;
2023-07-06 16:23:45 +08:00
let arr = [ ] ;
2024-06-05 16:01:37 +08:00
const { labelData } = this . props ;
2023-07-06 16:23:45 +08:00
if ( detailType == 'chart' ) {
2024-06-05 16:01:37 +08:00
arr . push ( { label : ` ${ getLabel ( 547315 , labelData ) } ` , key : '1' } ) ;
2023-07-14 14:46:14 +08:00
//arr.push({ label: '导出PDF', key: '2' });
2023-07-06 16:23:45 +08:00
} else {
2024-06-21 15:39:06 +08:00
arr . push ( { label : ` ${ getLabel ( 547448 , labelData ) } ` , key : '3' } ) ;
2023-07-06 16:23:45 +08:00
}
2023-06-30 16:39:00 +08:00
2023-07-06 16:23:45 +08:00
const menu = < Menu onClick = { this . handleExport . bind ( this ) } items = { arr } / > ;
2023-06-30 16:39:00 +08:00
return (
< Drawer
2024-06-05 16:01:37 +08:00
title = { getLabel ( 547321 , labelData ) }
2023-09-15 17:14:01 +08:00
width = { 1100 }
2023-06-30 16:39:00 +08:00
onClose = { this . onClose }
open = { open }
bodyStyle = { {
paddingBottom : 80 ,
} }
extra = {
< Space >
< Dropdown overlay = { menu } >
2024-06-05 16:01:37 +08:00
< Button type = "primary" > { getLabel ( 547314 , labelData ) } < / Button >
2023-06-30 16:39:00 +08:00
< / Dropdown >
2024-05-08 16:31:15 +08:00
< Button type = "primary" onClick = { this . changeDetail } >
2024-06-05 16:01:37 +08:00
{ getLabel ( 547326 , labelData ) }
2024-05-08 16:31:15 +08:00
< / Button >
2023-06-30 16:39:00 +08:00
< / Space >
}
>
{ detailType == 'chart' ? (
2024-05-08 16:31:15 +08:00
< div className = "svg-container" >
< Spin
size = "large"
spinning = { spinning }
2024-06-05 16:01:37 +08:00
tip = { getLabel ( 547320 , labelData ) }
2024-05-08 16:31:15 +08:00
className = "loading-center"
/ >
{ data . length > 0 && (
2023-07-06 16:23:45 +08:00
< OrgChartComponent
setChart = { ( chart ) => ( orgChart = chart ) }
setClick = { ( click ) => ( addNodeChildFunc = click ) }
onNodeClick = { this . onNodeClick }
onButtonClick = { this . onButtonClick }
data = { data }
buttonContent = { this . buttonContentRender }
nodeWidth = { this . nodeWidthRender }
nodeHeight = { this . nodeHeightRender }
nodeContent = { this . nodeContentRender }
/ >
2024-05-08 16:31:15 +08:00
) }
< / div >
2023-06-30 16:39:00 +08:00
) : (
2023-09-15 17:14:01 +08:00
< div style = { { padding : '0 20px' } } >
< Table
dataSource = { dataSource }
columns = { columns }
2024-05-08 16:31:15 +08:00
loading = { spinning }
2023-09-15 17:14:01 +08:00
pagination = { {
2024-06-05 16:01:37 +08:00
showSizeChanger : false ,
showTotal : ( total ) =>
` ${ getLabel ( 547523 , labelData ) } ${
dataSource . length
} $ { getLabel ( 547524 , labelData ) } ` ,
2023-09-15 17:14:01 +08:00
} }
/ >
< / div >
2023-06-30 16:39:00 +08:00
) }
< / Drawer >
) ;
}
}