From 8925fd2d70604c6afc7c723ce29bba71941f8fb3 Mon Sep 17 00:00:00 2001 From: Chengliang <1546584672@qq.com> Date: Thu, 18 Aug 2022 17:43:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/img/permission.png | Bin 0 -> 2257 bytes src/pages/company.jsx | 436 ++++++++++++++++++++------------------ src/pages/user.jsx | 74 ++++--- 3 files changed, 281 insertions(+), 229 deletions(-) create mode 100644 public/img/permission.png diff --git a/public/img/permission.png b/public/img/permission.png new file mode 100644 index 0000000000000000000000000000000000000000..dd2cbfaec6d2e9d91d114292fcf574aeb4d9456a GIT binary patch literal 2257 zcmV;?2rl=DP)&q?z#b}Q8xfJ>IR@j-2l|68-N;h15l&P)iywuAPDU5@3X(ZPc#}O7K?Fqc1BH2 z4Yjqk*zI;YIy!JVofr&;YMZObP;E#0`1qJ_-@dWCyNlE5q@$w)yWNh>X2WW=l1Lg~7#bR)x3?Fwx$uOD$K!ZB z9y}fo_wL9*tS*E9_GddfK#aLNcVQ+7b*49=W4hJnQEi^VZa&mG) zC=?FDTSaBz^Cni}PLpU;Qe?Pg|XhT7WNN_7XQAi!8G#+x^97#|;}y}ey& z-`d(@Zf=gDp&+9>RuC6jZKAtgxJsuC6o146R`Ld#GV#NTy zfB&Agwl?nHzpu0{FE8Ws`IwlPpt-p@>vb}`be*1_;&!{~>FMFYg9l3c+}s>Cn~jGL zAC{*RSyT~6`tb0Ou)wY4<@fdDfzGeyAzXlQ6)dU~3@y*)NJH({SJTVG!v zUayyOtxSR-C?83Z$`8=z^JOgdUauFM%|>r;Z`SkG!ZVxA7z_sfx&03oi-oah@=2vq~=e6XJ^1Uz(gXU$!<093Xtfb))tqFAz>YT=p9=IUjn z^@OLVih&1JO6jYGXEK?tG(4yhK(+94MJeS_De#~Q0M$eY*99KvSX4?R68QK09EFZD zg84)u!SeDlaGphuMx(gh?!1PUGHp*!Px=1+I~I$DR4PR{9Om=q&&u}=4GlOP4%*w> zGyXVQ;DJu*tgWpr78Vxh?(W9vbY_il)l6GJReE2NBt%g>cOz7e)JP;kAP^uJ4D$5p zQ<|HbHNyiP0IsjE^W(=4o;`@oQ8u~>3`m#f3YO!=duBR+iiz~tm4b#--` z;DJVf;c%GOuV3@()vHT6Jy8^uky4EEfyi~QVy3;(Xe1a6GCx1h)YMeY>(syljccIS z>!qisCj*|EX^~H*IKYx5ss24t6lrX1#A>w?iA1QcufKGTT6mh%S-*b$qP4X(qfHCE zO3LAIaD04xsl6C@f*@!E7>!1;*=)-3b%6&^TU$#!9?xhi7M>(YnNv6&fYE5Is4rG+ zl>!ga)%}=7N`gVIlpk@Boa3 z02T7DE{c~D*+F<QAo4JrLn5}1FI3I!67-{H>b8~hFM)cCT6qLr)w{|0z!q$bq61n>sl zxk^gutA%%!_NtXbYT-c|K(+AFpV-Be6^qfuT}O5H%I%3O1|IyL!fN4}&E`wM$^p^k zaw%`Ix?C>W|JPpN3Vl>8JOFbs@N!LEqtU2)HhOY$l4LTOw@$35N`VJp)C#Yhy6W&i zMM6~#JV}zS?Sn-NJSdP*RXg(Jw-EG{Z`a3{FJIW*-PQHJ>Cy@h@&K$RyhtR%zwiHL zV`GDN@7{5GdaCRF^;A}XYNu_v()zJjEaSdcCAFWmDtGZ@HLul{JEiY*I=OrIE+&(S z-rinZE?3!ptB~X!N$IfxoAeDeY#I*z{Noy!3u*O6hlYcCx*_t<-I= z3&2Pu!pX@AO-)Te>F_{9O5b2GaO>7B`uh6#`0?ZU?(J*vQf4xl#O-$TY-OQH8wWV+S*Ege?K;xP1Q@GYJv*|pdPz+WU0NEn#f0M-8Pp5LCBi~ zR%@T?lzuTr>IF}ax@{>^YajehsOkx?(1 { - if(item.data.hasChildren && !item._children) { - idsList.push(item.data.id); - } - }) - - if(idsList.length == 0) { - return + // 扩展按钮点击 + function onButtonClick(event, d) { + if (d.children) { + let idsList = []; + d.children.forEach((item) => { + if (item.data.hasChildren && !item._children) { + idsList.push(item.data.id); } - - let idsStr = idsList.join(",") - - console.log("idsStr", idsStr); - - let api = ""; - if(topBarSearchRequest) { - 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 - } - - fetch(api).then(res => res.json()).then(data => { - if(data.data) { - data.data.forEach(item => { - window.chart.addNode(item) - }) - } - }) - } - } - - // 获取部门图片 - function getDepartmentImage() { - 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` - } - - // 获取数据 - useEffect(() => { - d3.json( - // "/company/data" - "/api/bs/hrmorganization/orgchart/companyData?fclass=0&root=0&date=" + moment(new Date()).format("YYYY-MM-DD") - ).then(data => { - setData(data.data); }); - }, [true]); - // ButtonContent渲染 - const buttonContentRender = ({ node, state }) => { - if(node.children) { - return `
ˆ
`; + if (idsList.length == 0) { + return; + } + + let idsStr = idsList.join(','); + + console.log('idsStr', idsStr); + + let api = ''; + if (topBarSearchRequest) { + let request = { ...topBarSearchRequest, ids: idsStr }; + api = + '/api/bs/hrmorganization/orgchart/asyncCompanyData' + + qs.stringify(request, { addQueryPrefix: true }); } else { - return `
ˬ
` + 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) => { + if (data.data) { + data.data.forEach((item) => { + window.chart.addNode(item); + }); + } + }); } + } - // 节点宽度渲染 - const nodeWidthRender = d => - { - if(d.data.ftype == 0) { - return 220; - } else if(d.data.ftype == 1) { - return 160; - } else if(d.data.ftype == 2) { - return 144; - } - return 200; + // 获取部门图片 + function getDepartmentImage() { + 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`; + } + + // 获取数据 + useEffect(() => { + d3.json( + // "/company/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]); + + // ButtonContent渲染 + const buttonContentRender = ({ node, state }) => { + if (node.children) { + return `
ˆ
`; + } else { + return `
ˬ
`; } + }; - const nodeHeightRender = d => { - if(d.data.ftype == 0) { - return 100; - } else if(d.data.ftype == 1) { - return 160; - }else if(d.data.ftype == 2) { - return 56; - } - return 120; + // 节点宽度渲染 + const nodeWidthRender = (d) => { + if (d.data.ftype == 0) { + return 220; + } else if (d.data.ftype == 1) { + return 160; + } else if (d.data.ftype == 2) { + return 144; } + return 200; + }; + const nodeHeightRender = (d) => { + if (d.data.ftype == 0) { + return 100; + } else if (d.data.ftype == 1) { + return 160; + } else if (d.data.ftype == 2) { + return 56; + } + return 120; + }; + const nodeContentRender = (d, i, arr, state) => { + // 集团地址 + let companyUrl = + '/spa/organization/static/index.html#/main/organization/group'; + // 分部地址 + let subcompanyUrl = + '/spa/organization/static/index.html#/main/organization/companyExtend/'; + // 部门地址 + let departmentUrl = + '/spa/organization/static/index.html#/main/organization/departmentExtend/'; - const nodeContentRender = (d, i, arr, state) => { - // 集团地址 - let companyUrl = "/spa/organization/static/index.html#/main/organization/group" - // 分部地址 - let subcompanyUrl = "/spa/organization/static/index.html#/main/organization/companyExtend/" - // 部门地址 - let departmentUrl = "/spa/organization/static/index.html#/main/organization/departmentExtend/" - - if(d.data.ftype == 0) { - return `
+ if (d.data.ftype == 0) { + return `
@@ -148,9 +158,11 @@ export default function companyPage() { margin-top: 10px; ">COMPANY_GROUP
- ` - } else if(d.data.ftype == 1) { - return `
+
`; + } else if (d.data.ftype == 1) { + return `
@@ -164,10 +176,12 @@ export default function companyPage() { "> ${d.data.fname}
- ` - } else if(d.data.ftype == 2) { - return ` -
+
`; + } else if (d.data.ftype == 2) { + return ` +
${d.data.fname}
- ` + `; + } + return `
${d.data.fname}
`; + }; + + // tool bar start + const handleTopLayoutClick = (progressBtn) => { + progressBtn.current.style.top = 50 + 'px'; + orgChart && orgChart.layout('top').render(); + }; + + const handleLeftLayoutClick = (progressBtn) => { + progressBtn.current.style.top = 50 + 'px'; + orgChart && orgChart.layout('left').render(); + }; + + const handleZoomIn = (progressBtn) => { + if (progressBtn) { + let top = parseInt(progressBtn.current.style.top) - 10; + if (top <= 0) { + top = 30; } - return `
${d.data.fname}
` + progressBtn.current.style.top = top + 'px'; } + orgChart && orgChart.zoomIn(); + }; - - // tool bar start - const handleTopLayoutClick = (progressBtn) => { - progressBtn.current.style.top= 50 + "px"; - orgChart && orgChart.layout('top').render(); - } - - const handleLeftLayoutClick = (progressBtn) => { - progressBtn.current.style.top= 50 + "px"; - orgChart && orgChart.layout('left').render(); - } - - const handleZoomIn = (progressBtn) => { - if(progressBtn) { - let top = (parseInt(progressBtn.current.style.top) - 10) - if(top <= 0) { - top = 30; - } - progressBtn.current.style.top = top + "px"; + const handleZoomOut = (progressBtn) => { + if (progressBtn) { + let top = parseInt(progressBtn.current.style.top) + 10; + if (top >= 100) { + top = 70; } - orgChart && orgChart.zoomIn(); + progressBtn.current.style.top = top + 'px'; } - const handleZoomOut = (progressBtn) => { - if(progressBtn) { - let top = (parseInt(progressBtn.current.style.top) + 10) - if(top >= 100) { - top = 70; - } - progressBtn.current.style.top = top + "px"; - } - - orgChart && orgChart.zoomOut(); + orgChart && orgChart.zoomOut(); + }; + + const handleZoomBehavior = (value) => { + orgChart && orgChart.zoomBehavior(value - 50); + }; + + // tool bar end + + // top bar start + + function downloadPdf(chart) { + chart.exportImg({ + save: false, + 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'); + }; + }, + }); + } + + const handleExport = (type) => { + if (type == 'png') { + orgChart && orgChart.exportImg({ full: true }); + } else { + orgChart && downloadPdf(orgChart); } + }; - const handleZoomBehavior = (value) => { - orgChart && orgChart.zoomBehavior(value - 50); - } - - // tool bar end - - // top bar start - - function downloadPdf(chart) { - chart.exportImg({ - save: false, - 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'); - }; - }, - }); - } - - const handleExport = (type) => { - if(type == "png") { - orgChart && orgChart.exportImg({full:true}); - } else { - 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 => { + 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) => { setData(data.data); - }) - } - - // top bar end - + }); + }; + // top bar end + if (hasRight === false) { + //return message.error("对不起,您暂时没有权限", 2); return ( +
+ +

对不起,您暂时没有权限!

+
+ ); + } + + return ( + hasRight && (
- {handleExport(type)}} - onSearch={(requestData) => {handleSearch(requestData)}} + { + handleExport(type); + }} + onSearch={(requestData) => { + handleSearch(requestData); + }} url="/api/bs/hrmorganization/orgchart/getCondition?type=company" /> - handleTopLayoutClick(progressBtn)} - onLeftLayoutClick={(progressBtn) => handleLeftLayoutClick(progressBtn)} + onLeftLayoutClick={(progressBtn) => + handleLeftLayoutClick(progressBtn) + } onZoomOut={(progressBtn) => handleZoomOut(progressBtn)} onZoomIn={(progressBtn) => handleZoomIn(progressBtn)} onZoomBehavior={(value) => handleZoomBehavior(value)} /> 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} />
- ); + ) + ); } diff --git a/src/pages/user.jsx b/src/pages/user.jsx index 2542c1e..1dc6615 100644 --- a/src/pages/user.jsx +++ b/src/pages/user.jsx @@ -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,34 +379,50 @@ export default function userPage() { } }; + if (hasRight === false) { + return ( +
+ +

对不起,您暂时没有权限!

+
+ ); + } + return ( -
- { - handleExport(type); - }} - onSearch={(requestData) => { - handleSearch(requestData); - }} - url="/api/bs/hrmorganization/orgchart/getCondition?type=user" - /> - handleTopLayoutClick(progressBtn)} - onLeftLayoutClick={(progressBtn) => handleLeftLayoutClick(progressBtn)} - onZoomOut={(progressBtn) => handleZoomOut(progressBtn)} - onZoomIn={(progressBtn) => handleZoomIn(progressBtn)} - /> - (orgChart = chart)} - setClick={(click) => (addNodeChildFunc = click)} - onNodeClick={onNodeClick} - onButtonClick={onButtonClick} - data={data} - buttonContent={buttonContentRender} - nodeWidth={nodeWidthRender} - nodeHeight={nodeHeightRender} - nodeContent={nodeContentRender} - /> -
+ hasRight && ( +
+ { + handleExport(type); + }} + onSearch={(requestData) => { + handleSearch(requestData); + }} + url="/api/bs/hrmorganization/orgchart/getCondition?type=user" + /> + handleTopLayoutClick(progressBtn)} + onLeftLayoutClick={(progressBtn) => + handleLeftLayoutClick(progressBtn) + } + onZoomOut={(progressBtn) => handleZoomOut(progressBtn)} + onZoomIn={(progressBtn) => handleZoomIn(progressBtn)} + /> + (orgChart = chart)} + setClick={(click) => (addNodeChildFunc = click)} + onNodeClick={onNodeClick} + onButtonClick={onButtonClick} + data={data} + buttonContent={buttonContentRender} + nodeWidth={nodeWidthRender} + nodeHeight={nodeHeightRender} + nodeContent={nodeContentRender} + /> +
+ ) ); }