From 874ae825083ee5576c6e6cacc7cb4bba15c0077a Mon Sep 17 00:00:00 2001
From: zhangyongtian <1181606322@qq.com>
Date: Sat, 14 Sep 2024 10:36:53 +0800
Subject: [PATCH] feat: 对接网格单点登录
---
gz-customerSystem/src/components/Layout/index.jsx | 87 +++++++++++++++++++++++++++++++++----------
1 files changed, 67 insertions(+), 20 deletions(-)
diff --git a/gz-customerSystem/src/components/Layout/index.jsx b/gz-customerSystem/src/components/Layout/index.jsx
index 6585e1c..36eca5f 100644
--- a/gz-customerSystem/src/components/Layout/index.jsx
+++ b/gz-customerSystem/src/components/Layout/index.jsx
@@ -2,7 +2,7 @@
* @Company: hugeInfo
* @Author: ldh
* @Date: 2022-03-11 14:22:43
- * @LastEditTime: 2023-12-25 16:10:51
+ * @LastEditTime: 2024-09-11 09:42:38
* @LastEditors: dminyi 1301963064@qq.com
* @Version: 1.0.0
* @Description: 外层layout
@@ -19,6 +19,17 @@
function getRolePowerApi(roleId) {
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() || {};
@@ -41,6 +52,9 @@
// 当前选中的角色 及其 权限
const [roleActive, setRoleActive] = useState({ id: null, powerMap: {} });
+ //网格跳转请求状态
+ const [gridStatus, setGridStatus] = useState(false)
+
// 切换头部menu
function handleClickHeaderMenu(values) {
function loop(value) {
@@ -60,7 +74,7 @@
// 切换角色
function handleChangeRole(roleName, roleId) {
- navigate('/mediate/workbench');
+ navigate('/mediate/visit/visitWorkBench');
setRoleActive({ ...roleActive, id: roleId, roleName });
}
@@ -97,17 +111,48 @@
}
}
+ //请求网格token
+ const getGridToken = async (token) => {
+ const res = await gridLogin({
+ token
+ })
+ if (res.type) {
+ $$.clearSessionStorage();
+ $$.setSessionStorage('customerSystemToken', res.data?.token);
+ $$.setLocal('customerSystemUser', res.data || {});
+ let ctUseroleList = res.data?.ctUseroleList || [];
+ console.log(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 result = await switchRoleApi({ roleCode: roleCode });
+ if (result.type) {
+ $$.setSessionStorage('customerSystemToken', result.data);
+ setGridStatus(true)
+ }
+ }
+ }
+
// 初始化 格式化数据适应菜单栏
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,28 +162,29 @@
async function getRolePower(roleId, roleName) {
global.setSpinning(true);
const res = await getRolePowerApi(roleId);
+ console.log(res, 'res1111')
global.setSpinning(false);
if (res.type) {
let resData = res.data?.roleTreeBOS || [];
let menu_data = [];
let power_data = [];
resData.forEach((x) => {
- if (x.appClient === '1' && x.powerTag !== 'pay') {
+ if (x.appClient === 1 && x.powerTag !== 'pay') {
menu_data.push(x);
}
- if (x.appClient === '1' || x.powerTag === 'pay') {
+ if (x.appClient === 1 || x.powerTag === 'pay') {
power_data.push(x);
}
});
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');
}
@@ -161,7 +207,7 @@
getRolePower(roleActive.id, roleActive.roleName);
}
}, [roleActive.id]);
-
+console.log(gridStatus);
return (
<>
<Header
@@ -172,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">
@@ -184,7 +230,8 @@
</main>
<SOP />
</main>
- )}
+ ) : <></>
+ }
</>
);
};
--
Gitblit v1.8.0