增加权限
This commit is contained in:
parent
44c17194c8
commit
8925fd2d70
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
|
|
@ -1,13 +1,13 @@
|
|||
import styles from './index.less';
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {OrgChartComponent} from '@/components/orgChart'
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { OrgChartComponent } from '@/components/orgChart';
|
||||
import * as d3 from 'd3';
|
||||
import { TopBar } from '../components/topBar';
|
||||
import ToolBar from '../components/toolBar';
|
||||
import jsPDF from 'jspdf'
|
||||
import jsPDF from 'jspdf';
|
||||
import moment from 'moment';
|
||||
import qs from 'qs';
|
||||
|
||||
import { message } from 'antd';
|
||||
|
||||
export default function companyPage() {
|
||||
const [data, setData] = useState(null);
|
||||
|
|
@ -16,68 +16,78 @@ export default function companyPage() {
|
|||
let orgChart = null;
|
||||
|
||||
let topBarSearchRequest = null;
|
||||
const [hasRight, setHasRight] = useState('');
|
||||
|
||||
// 点击节点
|
||||
function onNodeClick(nodeId) {
|
||||
// alert('clicked ' + nodeId);
|
||||
}
|
||||
|
||||
|
||||
// 扩展按钮点击
|
||||
function onButtonClick(event, d) {
|
||||
if (d.children) {
|
||||
let idsList = []
|
||||
d.children.forEach(item => {
|
||||
let idsList = [];
|
||||
d.children.forEach((item) => {
|
||||
if (item.data.hasChildren && !item._children) {
|
||||
idsList.push(item.data.id);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
if (idsList.length == 0) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
let idsStr = idsList.join(",")
|
||||
let idsStr = idsList.join(',');
|
||||
|
||||
console.log("idsStr", idsStr);
|
||||
console.log('idsStr', idsStr);
|
||||
|
||||
let api = "";
|
||||
let api = '';
|
||||
if (topBarSearchRequest) {
|
||||
let request = {...topBarSearchRequest, ids: idsStr}
|
||||
api = "/api/bs/hrmorganization/orgchart/asyncCompanyData" + qs.stringify(request, {addQueryPrefix: true})
|
||||
let request = { ...topBarSearchRequest, ids: idsStr };
|
||||
api =
|
||||
'/api/bs/hrmorganization/orgchart/asyncCompanyData' +
|
||||
qs.stringify(request, { addQueryPrefix: true });
|
||||
} else {
|
||||
api = "/api/bs/hrmorganization/orgchart/asyncCompanyData?fclass=0&root=0&date=" + moment(new Date()).format("YYYY-MM-DD") + "&ids="+idsStr
|
||||
api =
|
||||
'/api/bs/hrmorganization/orgchart/asyncCompanyData?fclass=0&root=0&date=' +
|
||||
moment(new Date()).format('YYYY-MM-DD') +
|
||||
'&ids=' +
|
||||
idsStr;
|
||||
}
|
||||
|
||||
fetch(api).then(res => res.json()).then(data => {
|
||||
fetch(api)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
if (data.data) {
|
||||
data.data.forEach(item => {
|
||||
window.chart.addNode(item)
|
||||
})
|
||||
data.data.forEach((item) => {
|
||||
window.chart.addNode(item);
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 获取部门图片
|
||||
function getDepartmentImage() {
|
||||
let index = Math.floor(Math.random() * 8) + 1
|
||||
return `./img/department/${index}.png`
|
||||
let index = Math.floor(Math.random() * 8) + 1;
|
||||
return `./img/department/${index}.png`;
|
||||
}
|
||||
|
||||
// 获取部门图片
|
||||
function getSubcompanyImage() {
|
||||
let index = Math.floor(Math.random() * 3) + 1
|
||||
return `./img/subcompany/${index}.png`
|
||||
let index = Math.floor(Math.random() * 3) + 1;
|
||||
return `./img/subcompany/${index}.png`;
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
useEffect(() => {
|
||||
d3.json(
|
||||
// "/company/data"
|
||||
"/api/bs/hrmorganization/orgchart/companyData?fclass=0&root=0&date=" + moment(new Date()).format("YYYY-MM-DD")
|
||||
).then(data => {
|
||||
'/api/bs/hrmorganization/orgchart/companyData?fclass=0&root=0&date=' +
|
||||
moment(new Date()).format('YYYY-MM-DD'),
|
||||
).then((data) => {
|
||||
setData(data.data);
|
||||
setHasRight(data.hasRight);
|
||||
});
|
||||
}, [true]);
|
||||
|
||||
|
|
@ -86,13 +96,12 @@ export default function companyPage() {
|
|||
if (node.children) {
|
||||
return `<div style="border-radius:3px;padding:3px;font-size:10px;margin:auto auto;background-color:#66BAF5"> <div style="margin-top:0px;line-height:1.2;height:11px;font-size:25px; color: #fff;">ˆ</div> </div>`;
|
||||
} else {
|
||||
return `<div style="border-radius:3px;padding:1px;font-size:10px;margin:auto auto;background-color:#66BAF5"> <div style="margin-top:-22px;margin-bottom: 3px;font-size:25px; color: #fff;">ˬ</div> </div>`
|
||||
}
|
||||
return `<div style="border-radius:3px;padding:1px;font-size:10px;margin:auto auto;background-color:#66BAF5"> <div style="margin-top:-22px;margin-bottom: 3px;font-size:25px; color: #fff;">ˬ</div> </div>`;
|
||||
}
|
||||
};
|
||||
|
||||
// 节点宽度渲染
|
||||
const nodeWidthRender = d =>
|
||||
{
|
||||
const nodeWidthRender = (d) => {
|
||||
if (d.data.ftype == 0) {
|
||||
return 220;
|
||||
} else if (d.data.ftype == 1) {
|
||||
|
|
@ -101,9 +110,9 @@ export default function companyPage() {
|
|||
return 144;
|
||||
}
|
||||
return 200;
|
||||
}
|
||||
};
|
||||
|
||||
const nodeHeightRender = d => {
|
||||
const nodeHeightRender = (d) => {
|
||||
if (d.data.ftype == 0) {
|
||||
return 100;
|
||||
} else if (d.data.ftype == 1) {
|
||||
|
|
@ -112,17 +121,18 @@ export default function companyPage() {
|
|||
return 56;
|
||||
}
|
||||
return 120;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
const nodeContentRender = (d, i, arr, state) => {
|
||||
// 集团地址
|
||||
let companyUrl = "/spa/organization/static/index.html#/main/organization/group"
|
||||
let companyUrl =
|
||||
'/spa/organization/static/index.html#/main/organization/group';
|
||||
// 分部地址
|
||||
let subcompanyUrl = "/spa/organization/static/index.html#/main/organization/companyExtend/"
|
||||
let subcompanyUrl =
|
||||
'/spa/organization/static/index.html#/main/organization/companyExtend/';
|
||||
// 部门地址
|
||||
let departmentUrl = "/spa/organization/static/index.html#/main/organization/departmentExtend/"
|
||||
let departmentUrl =
|
||||
'/spa/organization/static/index.html#/main/organization/departmentExtend/';
|
||||
|
||||
if (d.data.ftype == 0) {
|
||||
return `<div onclick="window.open('${companyUrl}', '_blank')">
|
||||
|
|
@ -148,9 +158,11 @@ export default function companyPage() {
|
|||
margin-top: 10px;
|
||||
">COMPANY_GROUP</div>
|
||||
</div>
|
||||
</div>`
|
||||
</div>`;
|
||||
} else if (d.data.ftype == 1) {
|
||||
return `<div onclick="window.open('${subcompanyUrl + d.data.fnumber}', '_blank')">
|
||||
return `<div onclick="window.open('${
|
||||
subcompanyUrl + d.data.fnumber
|
||||
}', '_blank')">
|
||||
<div style="width: 85px; height: 85px; border: 1px solid #66BAF5; border-radius: 50%;text-align: center; line-height: 85px; margin: 0 auto;">
|
||||
<img src="${getSubcompanyImage()}" />
|
||||
</div>
|
||||
|
|
@ -164,10 +176,12 @@ export default function companyPage() {
|
|||
">
|
||||
${d.data.fname}
|
||||
</div>
|
||||
</div>`
|
||||
</div>`;
|
||||
} else if (d.data.ftype == 2) {
|
||||
return `
|
||||
<div style="width: 100%; height: 100%; background: url('./img/company_job_label.png');background-size: 100% 100%;" onclick="window.open('${departmentUrl + d.data.fnumber}')">
|
||||
<div style="width: 100%; height: 100%; background: url('./img/company_job_label.png');background-size: 100% 100%;" onclick="window.open('${
|
||||
departmentUrl + d.data.fnumber
|
||||
}')">
|
||||
<div style="padding-left: 8px; padding-top: 23px;">
|
||||
<img src="${getDepartmentImage()}"/>
|
||||
<span style="
|
||||
|
|
@ -179,49 +193,48 @@ export default function companyPage() {
|
|||
">${d.data.fname}</span>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
`;
|
||||
}
|
||||
return `<div>${d.data.fname}</div>`
|
||||
}
|
||||
|
||||
return `<div>${d.data.fname}</div>`;
|
||||
};
|
||||
|
||||
// tool bar start
|
||||
const handleTopLayoutClick = (progressBtn) => {
|
||||
progressBtn.current.style.top= 50 + "px";
|
||||
progressBtn.current.style.top = 50 + 'px';
|
||||
orgChart && orgChart.layout('top').render();
|
||||
}
|
||||
};
|
||||
|
||||
const handleLeftLayoutClick = (progressBtn) => {
|
||||
progressBtn.current.style.top= 50 + "px";
|
||||
progressBtn.current.style.top = 50 + 'px';
|
||||
orgChart && orgChart.layout('left').render();
|
||||
}
|
||||
};
|
||||
|
||||
const handleZoomIn = (progressBtn) => {
|
||||
if (progressBtn) {
|
||||
let top = (parseInt(progressBtn.current.style.top) - 10)
|
||||
let top = parseInt(progressBtn.current.style.top) - 10;
|
||||
if (top <= 0) {
|
||||
top = 30;
|
||||
}
|
||||
progressBtn.current.style.top = top + "px";
|
||||
progressBtn.current.style.top = top + 'px';
|
||||
}
|
||||
orgChart && orgChart.zoomIn();
|
||||
}
|
||||
};
|
||||
|
||||
const handleZoomOut = (progressBtn) => {
|
||||
if (progressBtn) {
|
||||
let top = (parseInt(progressBtn.current.style.top) + 10)
|
||||
let top = parseInt(progressBtn.current.style.top) + 10;
|
||||
if (top >= 100) {
|
||||
top = 70;
|
||||
}
|
||||
progressBtn.current.style.top = top + "px";
|
||||
progressBtn.current.style.top = top + 'px';
|
||||
}
|
||||
|
||||
orgChart && orgChart.zoomOut();
|
||||
}
|
||||
};
|
||||
|
||||
const handleZoomBehavior = (value) => {
|
||||
orgChart && orgChart.zoomBehavior(value - 50);
|
||||
}
|
||||
};
|
||||
|
||||
// tool bar end
|
||||
|
||||
|
|
@ -241,7 +254,7 @@ export default function companyPage() {
|
|||
5,
|
||||
5,
|
||||
595 / 3,
|
||||
((img.height / img.width) * 595) / 3
|
||||
((img.height / img.width) * 595) / 3,
|
||||
);
|
||||
pdf.save('chart.pdf');
|
||||
};
|
||||
|
|
@ -250,50 +263,71 @@ export default function companyPage() {
|
|||
}
|
||||
|
||||
const handleExport = (type) => {
|
||||
if(type == "png") {
|
||||
if (type == 'png') {
|
||||
orgChart && orgChart.exportImg({ full: true });
|
||||
} else {
|
||||
orgChart && downloadPdf(orgChart)
|
||||
}
|
||||
orgChart && downloadPdf(orgChart);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSearch = (requestData) => {
|
||||
topBarSearchRequest = requestData
|
||||
let api = "/api/bs/hrmorganization/orgchart/companyData" + qs.stringify(requestData, {addQueryPrefix: true})
|
||||
fetch(api).then(res => res.json()).then(data => {
|
||||
topBarSearchRequest = requestData;
|
||||
let api =
|
||||
'/api/bs/hrmorganization/orgchart/companyData' +
|
||||
qs.stringify(requestData, { addQueryPrefix: true });
|
||||
fetch(api)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setData(data.data);
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// top bar end
|
||||
|
||||
if (hasRight === false) {
|
||||
//return message.error("对不起,您暂时没有权限", 2);
|
||||
return (
|
||||
<div style={{ width: '100%', top: '40%', position: 'absolute' }}>
|
||||
<img
|
||||
style={{ display: 'block', margin: '0 auto' }}
|
||||
src="./img/permission.png"
|
||||
/>
|
||||
<p style={{ textAlign: 'center' }}>对不起,您暂时没有权限!</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
hasRight && (
|
||||
<div className={styles.contentWrapper}>
|
||||
<TopBar
|
||||
onExport={(type) => {handleExport(type)}}
|
||||
onSearch={(requestData) => {handleSearch(requestData)}}
|
||||
onExport={(type) => {
|
||||
handleExport(type);
|
||||
}}
|
||||
onSearch={(requestData) => {
|
||||
handleSearch(requestData);
|
||||
}}
|
||||
url="/api/bs/hrmorganization/orgchart/getCondition?type=company"
|
||||
/>
|
||||
<ToolBar
|
||||
onTopLayoutClick={(progressBtn) => handleTopLayoutClick(progressBtn)}
|
||||
onLeftLayoutClick={(progressBtn) => handleLeftLayoutClick(progressBtn)}
|
||||
onLeftLayoutClick={(progressBtn) =>
|
||||
handleLeftLayoutClick(progressBtn)
|
||||
}
|
||||
onZoomOut={(progressBtn) => handleZoomOut(progressBtn)}
|
||||
onZoomIn={(progressBtn) => handleZoomIn(progressBtn)}
|
||||
onZoomBehavior={(value) => handleZoomBehavior(value)}
|
||||
/>
|
||||
<OrgChartComponent
|
||||
setChart={(chart) => orgChart = chart}
|
||||
setClick={click => (addNodeChildFunc = click)}
|
||||
setChart={(chart) => (orgChart = chart)}
|
||||
setClick={(click) => (addNodeChildFunc = click)}
|
||||
onNodeClick={onNodeClick}
|
||||
data={data}
|
||||
buttonContent={
|
||||
buttonContentRender
|
||||
}
|
||||
buttonContent={buttonContentRender}
|
||||
nodeWidth={nodeWidthRender}
|
||||
nodeHeight={nodeHeightRender}
|
||||
nodeContent={nodeContentRender}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export default function userPage() {
|
|||
let orgChart = null;
|
||||
let progressBtnRef = null;
|
||||
let topBarSearchRequest = null;
|
||||
const [hasRight, setHasRight] = useState('');
|
||||
|
||||
// 点击节点
|
||||
function onNodeClick(nodeId) {
|
||||
|
|
@ -84,6 +85,7 @@ export default function userPage() {
|
|||
moment(new Date()).format('YYYY-MM-DD'),
|
||||
).then((data) => {
|
||||
setData(data.data);
|
||||
setHasRight(data.hasRight);
|
||||
});
|
||||
}, [true]);
|
||||
|
||||
|
|
@ -377,7 +379,20 @@ export default function userPage() {
|
|||
}
|
||||
};
|
||||
|
||||
if (hasRight === false) {
|
||||
return (
|
||||
<div style={{ width: '100%', top: '40%', position: 'absolute' }}>
|
||||
<img
|
||||
style={{ display: 'block', margin: '0 auto' }}
|
||||
src="./img/permission.png"
|
||||
/>
|
||||
<p style={{ textAlign: 'center' }}>对不起,您暂时没有权限!</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
hasRight && (
|
||||
<div className={styles.contentWrapper}>
|
||||
<TopBar
|
||||
onExport={(type) => {
|
||||
|
|
@ -390,7 +405,9 @@ export default function userPage() {
|
|||
/>
|
||||
<ToolBar
|
||||
onTopLayoutClick={(progressBtn) => handleTopLayoutClick(progressBtn)}
|
||||
onLeftLayoutClick={(progressBtn) => handleLeftLayoutClick(progressBtn)}
|
||||
onLeftLayoutClick={(progressBtn) =>
|
||||
handleLeftLayoutClick(progressBtn)
|
||||
}
|
||||
onZoomOut={(progressBtn) => handleZoomOut(progressBtn)}
|
||||
onZoomIn={(progressBtn) => handleZoomIn(progressBtn)}
|
||||
/>
|
||||
|
|
@ -406,5 +423,6 @@ export default function userPage() {
|
|||
nodeContent={nodeContentRender}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue