zhuf 6 meses atrás
pai
commit
c0cbb0dab7
1 arquivos alterados com 162 adições e 0 exclusões
  1. 162 0
      public/refer2.html

+ 162 - 0
public/refer2.html

@@ -0,0 +1,162 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>授权登录</title>
+  <style>
+    body {
+      font-family: Arial, sans-serif;
+      margin: 0;
+      padding: 0;
+      display: flex;
+      justify-content: center;
+      align-items: center;
+      height: 100vh;
+      background-color: #f0f0f0;
+    }
+
+    .container {
+      text-align: center;
+    }
+
+    h1 {
+      color: #333;
+    }
+
+    p {
+      color: #666;
+    }
+  </style>
+</head>
+
+<body class="m-0 p-0">
+  <div class="container">
+    <h1>跳 转 中 ...</h1>
+    <p>请等待浏览器跳转到新页面</p>
+  </div>
+  <script>
+    const debug = localStorage.getItem('debug')
+
+    const hrefMap = {
+      // 公文管理
+      'gwgl': { ju: '/ju/#/gwglxt', xiao: '/xiao/#/gwglxt' },
+      // 设备采购
+      'sbcg': { ju: '/ju/#/sbcgsq', xiao: '/xiao/#/sbcgsq' },
+      // 组织机构
+      'zzjg': { ju: '/ju/#/zzjgyqx', xiao: '/xiao/#/zzjgyqx' },
+      // 教师档案
+      'jsda': { ju: '/xiao/#/jzggl', xiao: '/xiao/#/jzggl' },
+    }
+
+    const search = decodeURIComponent(location.search)
+    const searchMap = new URLSearchParams(search)
+
+    const apppath = searchMap.get('apppath')
+    const js_code = searchMap.get('js_code')
+    const appname = searchMap.get('appname')
+    const appicon = searchMap.get('appicon')
+
+    const token = searchMap.get('token')
+
+    sessionStorage.setItem('js_code', js_code)
+    sessionStorage.setItem('appname', appname)
+    sessionStorage.setItem('appicon', appicon)
+
+    console.groupCollapsed('searchMap')
+    searchMap.forEach((value, key) => {
+      console.log(key, value)
+    })
+    console.groupEnd()
+
+    const origin = location.origin
+
+
+
+    function login(data) {
+      return new Promise((resolve, reject) => {
+        const xhr = new XMLHttpRequest()
+        xhr.open('POST', `https://openapi.bozedu.net/user/main/detail`, true)
+        xhr.onreadystatechange = function () {
+          if (xhr.readyState === 4) {
+            if (xhr.status === 200) {
+              resolve(JSON.parse(xhr.responseText))
+            } else {
+              reject(xhr)
+            }
+          }
+        }
+        const formData = new FormData()
+        Object.keys(data).forEach(key => formData.append(key, data[key]))
+        xhr.send(formData)
+      })
+    }
+
+    if (token) {
+      fetch('https://openapi.bozedu.net/jlt/set/detail', {
+        method: 'POST',
+        headers: {
+          'Content-Type': 'application/x-www-form-urlencoded'
+        },
+        body: JSON.stringify({
+          js_code,
+          token,
+          client: 'web',
+          api: 'json',
+          site: 'qqyxt'
+        })
+      }).then(res => res.json()).then(res => {
+        if (res.code === '1') {
+          const data = res.data
+          const _ = data.one_info
+          sessionStorage.setItem('js_title', _.js_title)
+        } else {
+          // alert(res.msg)
+          console.error('no data from /jlt/set/detail')
+        }
+      }).then(() => {
+        return login({
+          token,
+          api: 'json'
+        })
+      }).then(res => {
+        if (res.code === '1') {
+          const userInfo = res.data
+          localStorage.setItem('userInfo', JSON.stringify(res.data))
+
+          const role = parseInt(userInfo.user_role_id) < 72 ? 'ju' : 'xiao'
+          sessionStorage.setItem('role', role)
+          if (debug) {
+            alert('debug mode')
+          }
+
+          window.open(apppath, '_self')
+
+        } else {
+          alert(res.msg)
+        }
+      })
+      // login({
+      //   token,
+      //   api: 'json'
+      // }).then(res => {
+      //   if (res.code === '1') {
+      //     const userInfo = res.data
+      //     localStorage.setItem('userInfo', JSON.stringify(res.data))
+
+      //     const role = parseInt(userInfo.user_role_id) < 72 ? 'ju' : 'xiao'
+      //     sessionStorage.setItem('role', role)
+      //     console.log('jump to : ', origin + hrefMap[apppath][role])
+      //     window.open(origin + hrefMap[apppath][role], '_self')
+      //   } else {
+      //     alert(res.msg)
+      //   }
+      // })
+    } else {
+      window.history.back()
+    }
+  </script>
+</body>
+
+</html>