yangg vor 1 Jahr
Ursprung
Commit
e82c7c39ee
1 geänderte Dateien mit 37 neuen und 4 gelöschten Zeilen
  1. 37 4
      src/views/auth/boxed-signin.vue

+ 37 - 4
src/views/auth/boxed-signin.vue

@@ -60,7 +60,8 @@
                             </div>
                             <div>
                                 <label class="flex cursor-pointer items-center">
-                                    <input type="checkbox" class="form-checkbox bg-white dark:bg-black" />
+                                    <input v-model="inputValue.checked" type="checkbox"
+                                        class="form-checkbox bg-white dark:bg-black" />
                                     <span class="text-white-dark">记住密码</span>
                                 </label>
                             </div>
@@ -118,8 +119,13 @@ const inputValue = reactive({
     password: '',
     uuid: '',
     scene: 'LOGIN',
-    captcha: ''
+    captcha: '',
+    checked: false
 });
+const loginForm = ref({
+    username: '',
+    password: "",
+})
 interface LoginResponse {
     data: any;
     response: {
@@ -128,19 +134,32 @@ interface LoginResponse {
         };
     }
 }
-
+const MixinClone = (obj) => {
+    return JSON.parse(JSON.stringify(obj))
+}
 const handleSubmit = async () => {
     try {
         inputValue.uuid = uuid;
-        const response = await UserService.login(inputValue) as LoginResponse
+        const params = MixinClone(inputValue)
+        const response = await UserService.login(params) as LoginResponse
         store.setUser({
             ...response.data,
             token: response.data.refresh_token
         });
+        // 判断是否记住密码
+        if (inputValue.checked) {
+            loginForm.value.username = inputValue.username
+            loginForm.value.password = inputValue.password
+            localStorage.setItem("loginForm", JSON.stringify(loginForm));
+        } else {
+            localStorage.setItem("loginForm", JSON.stringify({}));
+        }
+        // 路由跳转到首页
         router.replace({
             name: 'home'
         });
     } catch (error) {
+        changeValidcode()
         console.error('Login failed:', error);
     }
     /* try {
@@ -161,6 +180,20 @@ onMounted(() => {
     const _uuid = uuidv4()
     uuid = _uuid
     changeValidcode()
+    //在setup中,用来加载页面时,查看账户密码是否存在
+    if (localStorage.getItem("loginForm") != null && Object.keys(localStorage.getItem("loginForm") ?? 'null').length > 2) {
+
+        inputValue.checked = true;
+        var userPwdInfo = JSON.parse(localStorage.getItem("loginForm") ?? 'null');
+        console.log(userPwdInfo._value);
+        inputValue.username = userPwdInfo._value.username;
+        inputValue.password = userPwdInfo._value.password;
+
+    } else {
+        inputValue.checked = false;
+    }
+
+
 });
 const router = useRouter();