From dfbe28b1ebcb18d4cc427e432b78cda0464883c0 Mon Sep 17 00:00:00 2001
From: zhangyongtian <1181606322@qq.com>
Date: Fri, 13 Sep 2024 22:35:31 +0800
Subject: [PATCH] feat: 单点对接

---
 gz-customerSystem/src/components/Layout/index.jsx            |   78 +++++++++++++++++++++++++++++++--------
 gz-customerSystem/src/views/register/closingReview/index.jsx |    5 ++
 gz-customerSystem/src/api/appUrl.js                          |    4 +-
 gz-customerSystem/src/api/apiHandler.js                      |    5 +-
 4 files changed, 72 insertions(+), 20 deletions(-)

diff --git a/gz-customerSystem/src/api/apiHandler.js b/gz-customerSystem/src/api/apiHandler.js
index a38d6fc..6cadc03 100644
--- a/gz-customerSystem/src/api/apiHandler.js
+++ b/gz-customerSystem/src/api/apiHandler.js
@@ -52,10 +52,11 @@
 export const ax = axios;
 
 export function request(value = {}) {
+  console.log(value);
   let token = getSessionStorage("customerSystemToken");
 
-  // 无token时
-  if (!token && value.url !== "ctAccount/login") {
+  // 无token、非登录、非网格单点跳转时
+  if (!value.isGrid && !token && value.url !== "ctAccount/login") {
     catchApiError({
       content: "抱歉!登录状态已失效请重新登录",
       loginStatus: "lose",
diff --git a/gz-customerSystem/src/api/appUrl.js b/gz-customerSystem/src/api/appUrl.js
index 4bf7b10..96074c9 100644
--- a/gz-customerSystem/src/api/appUrl.js
+++ b/gz-customerSystem/src/api/appUrl.js
@@ -10,11 +10,11 @@
 export const debug = {
   // web服务
   // baseUrl: 'http://gz.hugeinfo.com.cn',
-  baseUrl: "http://933ymn.natappfree.cc",
+  baseUrl: "http://6vynrg.natappfree.cc",
   // baseUrl: 'http://mdqgnh.natappfree.cc',
 
   // 附件服务
-  fileUrl: "http://933ymn.natappfree.cc",
+  fileUrl: "http://6vynrg.natappfree.cc",
   // fileUrl: 'http://gz.hugeinfo.com.cn',
 
   // 文件查看url 后面接附件编号
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>
-			)}
+			) : <></>
+			}
 		</>
 	);
 };
diff --git a/gz-customerSystem/src/views/register/closingReview/index.jsx b/gz-customerSystem/src/views/register/closingReview/index.jsx
index c692ec3..3664b7e 100644
--- a/gz-customerSystem/src/views/register/closingReview/index.jsx
+++ b/gz-customerSystem/src/views/register/closingReview/index.jsx
@@ -18,6 +18,11 @@
 const myTab = [
 	{
 		img: Matter,
+		label: '详情',
+		key: 'dslxq',
+	},
+	{
+		img: Matter,
 		label: '事项详情',
 		key: 'sxxq',
 	},

--
Gitblit v1.8.0