tianyunperfect 2 سال پیش
والد
کامیت
b43f322336
2فایلهای تغییر یافته به همراه63 افزوده شده و 10 حذف شده
  1. 12 1
      simple-demo/js/util.js
  2. 51 9
      tmp/test.html

+ 12 - 1
simple-demo/js/util.js

@@ -92,6 +92,17 @@ const requestUtil = {
             xhr.onerror = () => reject(xhr.statusText);
         });
     },
+    /**
+     * 拼接 url
+     */
+    buildUrl: function (url, params) {
+        const urlObj = new URL(url);
+        params.forEach(param => {
+            urlObj.searchParams.set(param[0], param[1]);
+        });
+        return urlObj.toString();
+    },
+
 
     /**
      * 同步请求 let a = request.sync("https://httpbin.tianyunperfect.cn/ip","GET",null,null)
@@ -347,4 +358,4 @@ const copyUtil = {
             console.error('复制失败', err);
         }
     }
-}
+}

+ 51 - 9
tmp/test.html

@@ -1,18 +1,60 @@
 <!DOCTYPE html>
-<html lang="en">
+<html>
 <head>
     <meta charset="UTF-8">
-    <title>Title</title>
-    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Login and Registration</title>
+    <link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.2/css/bootstrap.min.css">
     <style>
+        html, body {
+            height: 100%;
+        }
+        body {
+            display: flex;
+            justify-content: center;
+            align-items: center;
+        }
+        .container {
+            width: 100%;
+            max-width: 400px;
+        }
     </style>
 </head>
 <body>
-<iframe src="https://news.cnblogs.com/" height="300px" width="300px">
-</iframe>
-<script type="module">
-
+<div class="container">
+    <h1 class="text-center my-5">Login and Registration</h1>
+    <form id="auth-form">
+        <div class="mb-3">
+            <label for="email" class="form-label">Email address</label>
+            <input type="email" class="form-control" id="email">
+        </div>
+        <div class="mb-3">
+            <label for="password" class="form-label">Password</label>
+            <input type="password" class="form-control" id="password">
+        </div>
+        <div class="mb-3 form-check">
+            <input type="checkbox" class="form-check-input" id="register-checkbox">
+            <label class="form-check-label" for="register-checkbox">Register</label>
+        </div>
+        <button type="submit" class="btn btn-primary">Submit</button>
+    </form>
+</div>
+<script src="//cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
+<script>
+    const form = document.getElementById('auth-form');
+    const registerCheckbox = document.getElementById('register-checkbox');
+    form.addEventListener('submit', async (e) => {
+        e.preventDefault();
+        const email = document.getElementById('email').value;
+        const password = document.getElementById('password').value;
+        const url = registerCheckbox.checked ? '/register' : '/login';
+        try {
+            const response = await axios.post(url, { email, password });
+            console.log(response);
+        } catch (error) {
+            console.error(error);
+        }
+    });
 </script>
-
 </body>
-</html>
+</html>