refer.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>授权登录</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. margin: 0;
  11. padding: 0;
  12. display: flex;
  13. justify-content: center;
  14. align-items: center;
  15. height: 100vh;
  16. background-color: #f0f0f0;
  17. }
  18. .container {
  19. text-align: center;
  20. }
  21. h1 {
  22. color: #333;
  23. }
  24. p {
  25. color: #666;
  26. }
  27. </style>
  28. </head>
  29. <body class="m-0 p-0">
  30. <div class="container">
  31. <h1>跳 转 中 ...</h1>
  32. <p>请等待浏览器跳转到新页面</p>
  33. </div>
  34. <script>
  35. const debug = localStorage.getItem('debug')
  36. const search = decodeURIComponent(location.search)
  37. const searchMap = new URLSearchParams(search)
  38. const apppath = decodeURIComponent(searchMap.get('apppath'))
  39. const js_code = searchMap.get('js_code')
  40. const appname = searchMap.get('appname')
  41. const appicon = searchMap.get('appicon')
  42. const token = searchMap.get('token')
  43. sessionStorage.setItem('js_code', js_code)
  44. sessionStorage.setItem('appname', appname)
  45. sessionStorage.setItem('appicon', appicon)
  46. console.groupCollapsed('searchMap')
  47. searchMap.forEach((value, key) => {
  48. console.log(key, value)
  49. })
  50. console.groupEnd()
  51. const origin = location.origin
  52. function login(data) {
  53. return new Promise((resolve, reject) => {
  54. const xhr = new XMLHttpRequest()
  55. xhr.open('POST', `http://10.100.101.120:90/user/main/detail`, true)
  56. xhr.onreadystatechange = function () {
  57. if (xhr.readyState === 4) {
  58. if (xhr.status === 200) {
  59. resolve(JSON.parse(xhr.responseText))
  60. } else {
  61. reject(xhr)
  62. }
  63. }
  64. }
  65. const formData = new FormData()
  66. Object.keys(data).forEach(key => formData.append(key, data[key]))
  67. xhr.send(formData)
  68. })
  69. }
  70. if (token) {
  71. fetch('http://10.100.101.120:90/jlt/set/detail', {
  72. method: 'POST',
  73. headers: {
  74. 'Content-Type': 'application/x-www-form-urlencoded'
  75. },
  76. body: JSON.stringify({
  77. js_code,
  78. token,
  79. client: 'web',
  80. api: 'json',
  81. site: 'qqyxt'
  82. })
  83. }).then(res => res.json()).then(res => {
  84. if (res.code === '1') {
  85. const data = res.data
  86. const _ = data.one_info
  87. sessionStorage.setItem('js_title', _.js_title)
  88. } else {
  89. // alert(res.msg)
  90. console.error('no data from /jlt/set/detail')
  91. }
  92. }).then(() => {
  93. return login({
  94. token,
  95. api: 'json'
  96. })
  97. }).then(res => {
  98. if (res.code === '1') {
  99. const userInfo = res.data
  100. localStorage.setItem('userInfo', JSON.stringify(res.data))
  101. // const role = parseInt(userInfo.user_role_id) < 72 ? 'ju' : 'xiao'
  102. const role = apppath.includes('ju') ? 'ju' : 'xiao'
  103. sessionStorage.setItem('role', role)
  104. console.log('jump to : ', apppath)
  105. if (debug) {
  106. alert('debug mode')
  107. }
  108. window.open(apppath, '_self')
  109. } else {
  110. alert(res.msg)
  111. }
  112. })
  113. // login({
  114. // token,
  115. // api: 'json'
  116. // }).then(res => {
  117. // if (res.code === '1') {
  118. // const userInfo = res.data
  119. // localStorage.setItem('userInfo', JSON.stringify(res.data))
  120. // const role = parseInt(userInfo.user_role_id) < 72 ? 'ju' : 'xiao'
  121. // sessionStorage.setItem('role', role)
  122. // console.log('jump to : ', origin + hrefMap[apppath][role])
  123. // window.open(origin + hrefMap[apppath][role], '_self')
  124. // } else {
  125. // alert(res.msg)
  126. // }
  127. // })
  128. } else {
  129. window.history.back()
  130. }
  131. </script>
  132. </body>
  133. </html>