weaver_trunk_cli/pc4mobx/hrm/components/report/ReportChart.js

628 lines
19 KiB
JavaScript
Raw Normal View History

import { WeaInput, WeaEchart,WeaLocaleProvider } from 'ecCom'
2024-12-11 15:32:14 +08:00
import { Row, Col, message } from 'antd'
import { i18n } from '../../public/i18n'
const getLabel = WeaLocaleProvider.getLabel;
2024-12-11 15:32:14 +08:00
import React from 'react'
import { jumpToHrmDept } from '../../util/pulic-func'
2024-12-11 15:32:14 +08:00
class ReportChart extends React.Component {
constructor (props) {
super(props)
2024-12-11 15:32:14 +08:00
}
componentDidUpdate () {
if (this.refs.echart) this.refs.echart.paint()
if (this.refs.echart1) this.refs.echart1.paint()
2024-12-11 15:32:14 +08:00
}
componentWillReceiveProps (nextProps) {
2024-12-11 15:32:14 +08:00
if (this.props.winWidth !== nextProps.winWidth) {
if (this.refs.echart) this.refs.echart.chart.resize()
if (this.refs.echart1) this.refs.echart1.chart.resize()
2024-12-11 15:32:14 +08:00
}
}
getDOM (
interval,
key,
setGap,
getData,
isIntervalShow,
pathname,
tag,
isChartsShow,
chartTitle
) {
2024-12-11 15:32:14 +08:00
return (
<div style={{ position: 'absolute', right: 0 }}>
<div
style={
isIntervalShow
? { display: 'block', float: 'left' }
: { display: 'none' }
}
>
<div className='hrm-report-interval'>{this.getName(key) + ':'}</div>
<div
style={{ width: 70, paddingTop: 8, paddingLeft: 0 }}
className='hrm-report-interval hrm-report-input'
>
<WeaInput
ecId={`${
(this && this.props && this.props.ecId) || ''
}_WeaInput@f9l569`}
type='text'
viewAttr='2'
value={interval}
onChange={val => setGap(val)}
2024-12-11 15:32:14 +08:00
/>
</div>
<div className='hrm-report-interval' style={{ paddingLeft: 0 }}>
2024-12-11 15:32:14 +08:00
{this.getSuffix(key)}
</div>
<div className='hrm-report-interval' style={{ fontSize: 16 }}>
<a
onClick={() => getData()}
className='hrm-report-linkStyle'
title={i18n.button.refresh()}
>
2024-12-11 15:32:14 +08:00
<i className='icon-coms-Refresh' />
</a>
</div>
</div>
<div
style={
pathname !== 'basicConditionAnalysis'
? { display: 'block', float: 'left', padding: '10px 0' }
: { display: 'none' }
2024-12-11 15:32:14 +08:00
}
>
<a onClick={() => getData(tag)} className='hrm-report-linkStyle'>
{i18n.button.more()}
</a>
</div>
<div
className='hrm-report-interval'
style={{ padding: '8px 20px 10px 10px', fontSize: 16 }}
>
{isChartsShow ? (
<a
onClick={() => this.getImgSrc(tag, chartTitle)}
className='hrm-report-linkStyle'
title={i18n.button.saveAsImage()}
>
<i className='icon-coms-download2' />
</a>
) : (
<a
onClick={() => {
message.info(i18n.message.dataNone())
}}
className='hrm-report-linkStyle'
title={i18n.button.saveAsImage()}
>
<i className='icon-coms-download2' />
</a>
)}
2024-12-11 15:32:14 +08:00
</div>
</div>
)
}
getName (key) {
2024-12-11 15:32:14 +08:00
switch (key) {
case '1':
return i18n.label.ageRange()
2024-12-11 15:32:14 +08:00
case '3':
return getLabel('548321', "司龄区间")
2024-12-11 15:32:14 +08:00
case '7':
return i18n.label.rankingInterval()
2024-12-11 15:32:14 +08:00
}
}
getSuffix (key) {
2024-12-11 15:32:14 +08:00
switch (key) {
case '7':
return i18n.label.level()
2024-12-11 15:32:14 +08:00
default:
return i18n.label.year()
2024-12-11 15:32:14 +08:00
}
}
getImgSrc (tag, chartTitle) {
let cvs = document.getElementsByTagName('canvas')
2024-12-11 15:32:14 +08:00
if (tag !== 'right') {
this.downloadCvs2Img(cvs[0], chartTitle)
2024-12-11 15:32:14 +08:00
} else {
this.downloadCvs2Img(cvs[1], chartTitle)
2024-12-11 15:32:14 +08:00
}
}
downloadCvs2Img (cvs, chartTitle) {
let $a = document.createElement('a')
$a.download = chartTitle + '.jpg'
$a.target = '_blank'
let url
2024-12-11 15:32:14 +08:00
if (cvs) {
url = cvs.toDataURL('image/jpg')
2024-12-11 15:32:14 +08:00
} else {
message.info(i18n.message.dataNone())
2024-12-11 15:32:14 +08:00
}
if (url) $a.href = url
2024-12-11 15:32:14 +08:00
if (typeof MouseEvent === 'function') {
var evt = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: false
})
$a.dispatchEvent(evt)
2024-12-11 15:32:14 +08:00
} else {
if (window.navigator.msSaveOrOpenBlob) {
var bstr = atob(url.split(',')[1])
var n = bstr.length
var u8arr = new Uint8Array(n)
2024-12-11 15:32:14 +08:00
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
2024-12-11 15:32:14 +08:00
}
var blob = new Blob([u8arr])
window.navigator.msSaveOrOpenBlob(blob, chartTitle + '.jpg')
2024-12-11 15:32:14 +08:00
} else {
var html =
'' +
2024-12-11 15:32:14 +08:00
'<body style="margin:0;">' +
'<img src="' +
url +
'" style="max-width:100%;" title="" />' +
'</body>'
var tab = window.open()
tab.document.write(html)
2024-12-11 15:32:14 +08:00
}
}
}
chartAction (chart, ids, yAxisData, linkList) {
chart.off('click')
chart.on('click', params =>
this.handleClick(params, ids, yAxisData, linkList)
)
2024-12-11 15:32:14 +08:00
}
// #QC3421143# pie图增加点击事件,弹出框显示明细
basicChartAction = chart => {
chart.off("click");
chart.on("click", params => {
this.handleBasicClick(params);
});
};
handleBasicClick (params) {
const { pathname,cmd,showDialog } = this.props
if (pathname !== 'basicConditionAnalysis') return false;
if (cmd == 'AgeRp' || cmd == 'SexRp' || cmd == 'SeniorityRp' || cmd == 'EduRp' || cmd == "JobCallRp") {
2024-12-13 14:27:28 +08:00
showDialog(params.name);
}
}
handleClick (params, ids, yAxisData, linkList) {
const { pathname } = this.props
if (pathname !== 'departmentStatistics') return false
let anid = params.event.target.anid
2024-12-11 15:32:14 +08:00
if (!anid) {
return
}
let index = anid.split('_')[1]
2024-12-11 15:32:14 +08:00
jumpToHrmDept(ids[index])
}
render () {
2024-12-11 15:32:14 +08:00
const {
option,
isIntervalShow,
interval,
tabKey,
pathname,
setGap,
getData,
chartTitle,
isChartsShow,
ids,
yAxisData,
linkList,
tagName
} = this.props
2024-12-11 15:32:14 +08:00
return (
<div style={{ padding: '8px 16px' }}>
{pathname == 'basicConditionAnalysis' ? (
<div style={{ height: 500, position: 'relative' }}>
<Row
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Row@bk161k`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@tiem4w`}
span={24}
>
<div style={{ height: 50 }}>
{this.getDOM(
interval,
tabKey,
setGap,
getData,
isIntervalShow,
pathname,
pathname,
isChartsShow[0],
tagName
)}
</div>
</Col>
</Row>
<Row
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Row@yyxmps`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@r3yrz9`}
span={24}
>
{isChartsShow[0] ? (
<div style={{ height: 400 }}>
<WeaEchart
ecId={`${
(this && this.props && this.props.ecId) || ''
}_WeaEchart@94v101`}
ref='echart'
option={option[0]}
useDefault={false}
chartAction={chart =>
this.basicChartAction(chart)
}
/>
</div>
) : (
<div
style={{
position: 'absolute',
top: 100,
left: '50%',
marginLeft: -40,
textAlign: 'center'
}}
>
<div style={{ fontSize: 80 }}>
<i className='icon-coms-blank'></i>
</div>
<div style={{ fontSize: 20, color: '#B2B2B2' }}>
{i18n.message.dataNone()}
</div>
</div>
)}
</Col>
</Row>
</div>
) : (
''
)}
{pathname == 'departmentStatistics' || pathname == 'postStatistics' ? (
<div
style={{ height: 350, border: '1px solid #DDD', borderRadius: 3 }}
>
<Row
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Row@xs2v2c`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@e1wc91`}
span={24}
>
<div
style={{
height: 40,
backgroundColor: '#F9F9F9',
position: 'relative'
}}
>
<div
style={{
display: 'block',
width: '30%',
height: '100%',
float: 'left',
padding: '11px 0 12px 16px'
}}
>
{chartTitle[0]}
</div>
<div style={{ height: 50 }}>
{this.getDOM(
interval,
tabKey,
setGap,
getData,
isIntervalShow,
pathname,
pathname,
isChartsShow[0],
chartTitle[0]
)}
</div>
</div>
</Col>
</Row>
<Row
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Row@zdbixg`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@cpfhsg`}
span={20}
offset={2}
>
{isChartsShow[0] ? (
<div style={{ height: 300 }}>
<WeaEchart
ecId={`${
(this && this.props && this.props.ecId) || ''
}_WeaEchart@5ri10l`}
ref='echart'
option={option[0]}
useDefault={false}
chartAction={chart =>
this.chartAction(chart, ids, yAxisData, linkList)
}
/>
</div>
) : (
<div
style={{
position: 'absolute',
top: 100,
left: '50%',
marginLeft: -40,
textAlign: 'center'
}}
>
<div style={{ fontSize: 80 }}>
<i className='icon-coms-blank'></i>
</div>
<div style={{ fontSize: 20, color: '#B2B2B2' }}>
{i18n.message.dataNone()}
</div>
</div>
)}
</Col>
</Row>
</div>
) : (
''
)}
{pathname == 'jobStatusStatistics' ? (
<Row
ecId={`${(this && this.props && this.props.ecId) || ''}_Row@d50f92`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@4odteb`}
span={12}
>
<div
style={{
height: 350,
marginRight: 8,
border: '1px solid #DDD',
borderRadius: 3
}}
>
<Row
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Row@9vp3z8`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@j8v6ki`}
>
<div
style={{
height: 40,
backgroundColor: '#F9F9F9',
position: 'relative'
}}
>
<div
style={{
height: '100%',
padding: '11px 0 12px 16px',
float: 'left'
}}
>
{chartTitle[0]}
</div>
<div style={{ height: 50 }}>
{this.getDOM(
interval,
tabKey,
setGap,
getData,
isIntervalShow,
pathname,
'left',
isChartsShow[1],
chartTitle[0]
)}
</div>
</div>
</Col>
</Row>
<Row
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Row@z1e7gk`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@6gm6oz`}
>
{isChartsShow[1] ? (
<div style={{ height: 300 }}>
<WeaEchart
ecId={`${
(this && this.props && this.props.ecId) || ''
}_WeaEchart@mgu4rb`}
ref='echart'
option={option[0]}
useDefault={false}
/>
</div>
) : (
<div
style={{
position: 'absolute',
top: 100,
left: '50%',
marginLeft: -20,
textAlign: 'center'
}}
>
<div style={{ fontSize: 50 }}>
<i className='icon-coms-blank'></i>
</div>
<div style={{ fontSize: 15, color: '#B2B2B2' }}>
{i18n.message.dataNone()}
</div>
</div>
)}
</Col>
</Row>
</div>
</Col>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@j3wbd0`}
span={12}
>
<div
style={{
height: 350,
marginLeft: 8,
border: '1px solid #DDD',
borderRadius: 3
}}
>
<Row
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Row@kx8mey`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@d3qj2t`}
>
<div
style={{
height: 40,
backgroundColor: '#F9F9F9',
position: 'relative'
}}
>
<div
style={{
height: '100%',
padding: '11px 0 12px 16px',
float: 'left'
}}
>
{chartTitle[1]}
</div>
<div style={{ height: 50 }}>
{this.getDOM(
interval,
tabKey,
setGap,
getData,
isIntervalShow,
pathname,
'right',
isChartsShow[2],
chartTitle[1]
)}
</div>
</div>
</Col>
</Row>
<Row
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Row@i0dgsy`}
>
<Col
ecId={`${
(this && this.props && this.props.ecId) || ''
}_Col@svragf`}
>
{isChartsShow[2] ? (
<div style={{ height: 300 }}>
<WeaEchart
ecId={`${
(this && this.props && this.props.ecId) || ''
}_WeaEchart@ohcxa9`}
ref='echart1'
option={option[1]}
useDefault={false}
/>
</div>
) : (
<div
style={{
position: 'absolute',
top: 100,
left: '50%',
marginLeft: -20,
textAlign: 'center'
}}
>
<div style={{ fontSize: 50 }}>
<i className='icon-coms-blank'></i>
</div>
<div style={{ fontSize: 15, color: '#B2B2B2' }}>
{i18n.message.dataNone()}
</div>
</div>
)}
</Col>
</Row>
</div>
</Col>
</Row>
) : (
''
)}
</div>
2024-12-11 15:32:14 +08:00
)
}
}
export default ReportChart