loginJump.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. <script src="./axios.min.js"></script>
  8. <style>
  9. body {
  10. font-family: Arial, sans-serif;
  11. display: flex;
  12. justify-content: center;
  13. align-items: center;
  14. height: 100vh;
  15. margin: 0;
  16. background-color: #f0f2f5;
  17. }
  18. .login-container {
  19. text-align: center;
  20. background: white;
  21. padding: 2rem;
  22. border-radius: 8px;
  23. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  24. }
  25. .login-btn {
  26. display: block;
  27. width: 200px;
  28. padding: 12px;
  29. margin: 20px auto;
  30. border: none;
  31. border-radius: 4px;
  32. color: white;
  33. font-size: 16px;
  34. cursor: pointer;
  35. transition: background-color 0.3s;
  36. }
  37. .student-btn {
  38. background-color: #1890ff;
  39. }
  40. .teacher-btn {
  41. background-color: #52c41a;
  42. }
  43. .login-btn:hover {
  44. opacity: 0.9;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <!--<div class="login-container">-->
  50. <!-- <h1>在线教育平台</h1>-->
  51. <!-- <button class="login-btn student-btn" onclick="login()">登录</button>-->
  52. <!--</div>-->
  53. <!--http://localhost:63342/onlineEducation-front/public/html/loginJump.html?_ijt=eqdbr9d1k5uh8if53et5u8j8su&_ij_reload=RELOAD_ON_SAVE&code=126345&type=1&id=1958766027408039938-->
  54. <script>
  55. let baseUrl = 'http://192.168.1.213:9003'
  56. let baseUrlt = 'http://192.168.1.202:9000'
  57. let baseUrls = 'http://192.168.1.202:9000'
  58. // 创建axios实例,参考request.js中的配置
  59. const service = axios.create({
  60. baseURL: '/api',
  61. timeout: 5000
  62. });
  63. // 登录函数
  64. const login = async () => {
  65. const urlParams = new URLSearchParams(window.location.search);
  66. let code = urlParams.get('code');
  67. let type = urlParams.get('type');
  68. let id = urlParams.get('id');
  69. if (code == undefined || type == undefined) {
  70. alert('数据参数不对');
  71. return
  72. }
  73. if (type == 1 && id == undefined) {
  74. alert('数据参数不对 没有id');
  75. return
  76. }
  77. console.log('什么数值呢', code)
  78. // 这里需要替换为实际的登录接口URL
  79. const loginUrl = baseUrl+'/api/webapp/disk/CollegeUser/getUser';
  80. let res = await service.get(loginUrl, {
  81. params: {
  82. code
  83. },
  84. headers: {
  85. 'account': 'admin',
  86. }
  87. })
  88. console.log('登录状况:', res.data);
  89. if (res.data.code === 200) {
  90. let url = baseUrl+'/api/webapp/auth/b/getLoginUser'
  91. let ress = await service.get(url, {
  92. headers: {
  93. 'token': res.data.msg,
  94. }
  95. })
  96. console.log('获取人员信息:', ress);
  97. if(ress.data.code == 200 && ress.data.data.eduIdentity == 1){
  98. //去教师段
  99. // 构建带参数的URL
  100. const params = new URLSearchParams({
  101. token: res.data.msg,
  102. type,
  103. id
  104. });
  105. const redirectUrl = `${baseUrlt}/jump?${params.toString()}`;
  106. window.location.href = redirectUrl;
  107. }
  108. }
  109. // .then(response => {
  110. //
  111. // // alert('登录成功');
  112. // // // 保存token等操作
  113. // // console.log('登录成功:', response.data);
  114. // // } else {
  115. // // alert(`登录失败: ${response.data.msg}`);
  116. // // }
  117. // })
  118. // .catch(error => {
  119. // console.error('登录请求失败:', error);
  120. // alert('登录请求失败,请检查网络连接');
  121. // });
  122. // // 发送登录请求
  123. // service.post(loginUrl, loginData)
  124. // .then(response => {
  125. // if (response.data.code === 200) {
  126. // alert(`${userType === 'student' ? '学生' : '教师'}端登录成功`);
  127. // // 保存token等操作
  128. // console.log('登录成功:', response.data);
  129. // } else {
  130. // alert(`登录失败: ${response.data.msg}`);
  131. // }
  132. // })
  133. // .catch(error => {
  134. // console.error('登录请求失败:', error);
  135. // alert('登录请求失败,请检查网络连接');
  136. // });
  137. }
  138. // 在<script>标签内添加
  139. window.onload = function() {
  140. console.log('页面加载完成');
  141. login()
  142. // 在这里可以执行初始化操作
  143. // 比如自动登录等
  144. // login(); // 如果需要自动执行登录
  145. };
  146. </script>
  147. </body>
  148. </html>