Browse Source

钉钉换人登录问题

shaogen1995 1 month ago
parent
commit
8f32e9e89d
1 changed files with 28 additions and 1 deletions
  1. 28 1
      src/pages/Layout/index.tsx

+ 28 - 1
src/pages/Layout/index.tsx

@@ -9,7 +9,7 @@ import history from '@/utils/history'
 import { Button, Form, Input, Modal } from 'antd'
 import { Button, Form, Input, Modal } from 'antd'
 import { Base64 } from 'js-base64'
 import { Base64 } from 'js-base64'
 import encodeStr from '@/utils/pass'
 import encodeStr from '@/utils/pass'
-import { API_getRoleArr, passWordEditAPI } from '@/store/action/layout'
+import { API_ddLogin, API_getRoleArr, passWordEditAPI } from '@/store/action/layout'
 import { changSetFu, getTokenInfo, removeTokenInfo, setTokenInfo } from '@/utils/storage'
 import { changSetFu, getTokenInfo, removeTokenInfo, setTokenInfo } from '@/utils/storage'
 import { MessageFu } from '@/utils/message'
 import { MessageFu } from '@/utils/message'
 import logoImg from '@/assets/img/logo2.png'
 import logoImg from '@/assets/img/logo2.png'
@@ -27,8 +27,35 @@ import baseTouXiangImg from '@/assets/img/user.png'
 import { Z5_APIgetInfo } from '@/store/action/Z5role'
 import { Z5_APIgetInfo } from '@/store/action/Z5role'
 import { getUserInfoByIdAPI } from '@/store/action/Z6user'
 import { getUserInfoByIdAPI } from '@/store/action/Z6user'
 import { maiDianFu } from '@/components/ZmaiDian'
 import { maiDianFu } from '@/components/ZmaiDian'
+import dd from 'gdt-jsapi'
 
 
 function Layout() {
 function Layout() {
+  useEffect(() => {
+    if (isDing) {
+      const userInfo = getTokenInfo().user
+      if (userInfo && userInfo.id) {
+        dd.ready(function () {
+          dd.getAuthCode({
+            corpId: ''
+          })
+            .then(async res1 => {
+              const code = res1.auth_code
+              const res = await API_ddLogin(code!)
+              if (res.code === 0) {
+                if (res.data.user.id !== userInfo.id) {
+                  removeTokenInfo()
+                  history.replace('/login')
+                }
+              }
+            })
+            .catch(err => {
+              MessageFu.error(err)
+            })
+        })
+      }
+    }
+  }, [])
+
   // 字典加载完毕才加载别的
   // 字典加载完毕才加载别的
   const [isLoding, setIsLoding] = useState(false)
   const [isLoding, setIsLoding] = useState(false)