From 221546808c11df777199def992e4abbf1fc31b5a Mon Sep 17 00:00:00 2001 From: liuwh <964324856@qq.com> Date: Sat, 14 Sep 2024 10:03:47 +0800 Subject: [PATCH] Merge branch 'master' of http://120.79.193.119:9090/r/gzzfw/frontEnd/gzDyh into master --- gz-customerSystem/src/components/Layout/index.jsx | 78 +++++++++++++++++++++++++++++++-------- 1 files changed, 62 insertions(+), 16 deletions(-) diff --git a/gz-customerSystem/src/components/Layout/index.jsx b/gz-customerSystem/src/components/Layout/index.jsx index 85e1209..92aec73 100644 --- a/gz-customerSystem/src/components/Layout/index.jsx +++ b/gz-customerSystem/src/components/Layout/index.jsx @@ -20,6 +20,17 @@ return $$.ax.request({ url: `ctRole/getById?id=${roleId}`, type: 'get', service: 'cust' }); } +//对接单点登录,获取token +function gridLogin(data) { + return $$.ax.request({ url: `ctAccount/gridLogin`, type: 'post', service: 'cust', isGrid: true, data }); +} + +// 角色选择 +function switchRoleApi(data) { + return $$.ax.request({ url: 'ctAccount/switchRole', type: 'get', data, service: 'cust' }); +} + + const Layout = ({ isNotNav, headerUserChange }) => { const location = useLocation() || {}; @@ -40,6 +51,9 @@ // 当前选中的角色 及其 权限 const [roleActive, setRoleActive] = useState({ id: null, powerMap: {} }); + + //网格跳转请求状态 + const [gridStatus, setGridStatus] = useState(false) // 切换头部menu function handleClickHeaderMenu(values) { @@ -97,17 +111,48 @@ } } + //请求网格token + const getGridToken = async (token) => { + const res = await gridLogin({ + token + }) + if (res.type) { + setGridStatus(true) + $$.setSessionStorage('gridToken', '') + $$.setSessionStorage('customerSystemToken', res.data?.token); + $$.setLocal('customerSystemUser', res.data || {}); + let ctUseroleList = res.data?.ctUseroleList || []; + const roleId = ctUseroleList[0]?.roleId + const roleName = ctUseroleList[0]?.roleName + const roleCode = ctUseroleList[0]?.roleCode + $$.setSessionStorage('role', { roleId: roleId, roleName: roleName }); + setRoleActive({ id: roleId, roleName: roleName, powerMap: {} }); + const res = await switchRoleApi({ roleCode: roleCode }); + if (res.type) { + $$.setSessionStorage('customerSystemToken', res.data); + navigate('/mediate/visit/visitWorkBench'); + } + } + } + // 初始化 格式化数据适应菜单栏 useEffect(() => { - let role = $$.getSessionStorage('role'); - if (role) { - setRoleActive({ id: role.roleId, roleName: role.roleName, powerMap: {} }); - return; - } - let customerSystemUser = $$.getLocal('customerSystemUser'); - let ctUseroleList = customerSystemUser?.ctUseroleList || []; - if (ctUseroleList[0]?.roleId) { - setRoleActive({ id: ctUseroleList[0]?.roleId, roleName: ctUseroleList[0]?.roleName, powerMap: {} }); + //单点登录,网格传一个token在session,如果有就请求接口 + const gridToken = $$.getSessionStorage('gridToken'); + if (gridToken) { + getGridToken(gridToken) + } else { + setGridStatus(true) + let role = $$.getSessionStorage('role'); + if (role) { + setRoleActive({ id: role.roleId, roleName: role.roleName, powerMap: {} }); + return; + } + let customerSystemUser = $$.getLocal('customerSystemUser'); + let ctUseroleList = customerSystemUser?.ctUseroleList || []; + if (ctUseroleList[0]?.roleId) { + setRoleActive({ id: ctUseroleList[0]?.roleId, roleName: ctUseroleList[0]?.roleName, powerMap: {} }); + } } }, []); @@ -117,7 +162,7 @@ async function getRolePower(roleId, roleName) { global.setSpinning(true); const res = await getRolePowerApi(roleId); - console.log(res,'res1111') + console.log(res, 'res1111') global.setSpinning(false); if (res.type) { let resData = res.data?.roleTreeBOS || []; @@ -132,14 +177,14 @@ } }); let powerMap = setPowerDataMap(power_data); - + function loop(data, arr) { data.forEach((x) => { if (x.powerUrl && powerMap[x.powerUrl]?.show) { arr.push(x.powerUrl); - + } - if ( x.powerUrl && powerMap[x.powerUrl]?.update) { + if (x.powerUrl && powerMap[x.powerUrl]?.update) { arr.push(x.powerUrl); console.log(powerMap[x.powerUrl]?.update, 'res111111111'); } @@ -173,11 +218,11 @@ headerUserChange={headerUserChange} handleChangeRole={handleChangeRole} /> - {isNotNav ? ( + {gridStatus && isNotNav ? ( <main className="layout-main" id="layoutMain"> <Outlet /> </main> - ) : ( + ) : gridStatus ? ( <main className="layout-main" id="layoutMain" ref={layoutRef}> <Navigation powerMap={roleActive.powerMap} roleActive={roleActive} sideMenu={sideMenu} /> <main id="layoutChild" className="layout-child"> @@ -185,7 +230,8 @@ </main> <SOP /> </main> - )} + ) : <></> + } </> ); }; -- Gitblit v1.8.0