Browse Source

修改登录

zhangchuang 11 hours ago
parent
commit
a6df05a3f3
3 changed files with 35 additions and 19 deletions
  1. 7 3
      src/login/index.vue
  2. 9 6
      src/views/user/ChangePassword.vue
  3. 19 10
      src/views/user/ViewInfo.vue

+ 7 - 3
src/login/index.vue

@@ -37,7 +37,7 @@ import { sha256 } from "js-sha256";
 import { setLocalStorage } from "@/utils";
 
 const router = useRouter();
-const username = ref("admin");
+const username = ref("cus_user01");
 const password = ref("123456");
 const isRemember = ref(true);
 
@@ -47,8 +47,9 @@ const onLogin = async () => {
     return;
   }
   const data = {
-    username: "admin",
-    password: sha256("123456"),
+    username: username.value,
+    password: sha256(password.value),
+    clientType: "user",
   };
   const res = (await postLogin(data)) as unknown as any;
   if (res.code === 200) {
@@ -56,6 +57,9 @@ const onLogin = async () => {
     setLocalStorage("avatar", res.data.avatar);
     setLocalStorage("tokenName", res.data.tokenName);
     setLocalStorage("tokenValue", res.data.tokenValue);
+    setLocalStorage("phone", res.data.phone);
+    setLocalStorage("name", res.data.name);
+    setLocalStorage("avatar", res.data.avatar);
     router.push({
       path: "/dashboard",
     });

+ 9 - 6
src/views/user/ChangePassword.vue

@@ -20,7 +20,7 @@
 
       <el-form-item label="手机号码">
         <div style="display: flex; gap: 0.5rem">
-          <el-input v-model="form.phone" placeholder="请输入手机号码" />
+          <el-input v-model="form.phone" disabled placeholder="请输入手机号码" />
           <el-button :disabled="isCounting" @click="sendCode">{{
             isCounting ? `${count}秒` : "发送验证码"
           }}</el-button>
@@ -39,12 +39,15 @@
 </template>
 
 <script lang="ts" setup>
-import { reactive, ref } from "vue";
+import { ref } from "vue";
+import { getLocalStorage } from "@/utils";
 
-const form = reactive({
+const phone = getLocalStorage("phone")
+
+const form = ref({
   newPassword: "",
   confirmPassword: "",
-  phone: "",
+  phone: phone,
   code: "",
 });
 
@@ -56,7 +59,7 @@ const sendCode = () => {
   if (isCounting.value) return;
 
   // 这里可以添加发送验证码的API请求逻辑
-  console.log("验证码已发送到:", form.phone);
+  console.log("验证码已发送到:", form.value.phone);
 
   // 开始倒计时
   isCounting.value = true;
@@ -72,7 +75,7 @@ const sendCode = () => {
 };
 
 const onSubmit = () => {
-  if (form.newPassword !== form.confirmPassword) {
+  if (form.value.newPassword !== form.value.confirmPassword) {
     console.error("新密码与确认密码不匹配");
     return;
   }

+ 19 - 10
src/views/user/ViewInfo.vue

@@ -3,11 +3,11 @@
     <div class="page-title">基本信息</div>
     <el-form :model="form" label-width="100px" style="max-width: 400px">
       <el-form-item label="手机号码">
-        <el-input v-model="form.phone" placeholder="请输入手机号码" />
+        <el-input v-model="form.phone" disabled placeholder="请输入手机号码" />
       </el-form-item>
 
       <el-form-item label="用户名">
-        <el-input v-model="form.username" placeholder="请输入用户名" />
+        <el-input v-model="form.username" disabled placeholder="请输入用户名" />
       </el-form-item>
 
       <el-form-item label="地址">
@@ -26,16 +26,25 @@
 </template>
 
 <script lang="ts" setup>
-import { reactive } from "vue";
-
-const form = reactive({
-  avatar: "",
-  phone: "",
-  username: "",
-  address: "",
-  email: "",
+import { ref } from "vue";
+import { getLocalStorage } from "@/utils";
+
+const avatar = getLocalStorage("avatar")
+const phone = getLocalStorage("phone")
+const username = getLocalStorage("name")
+const address = getLocalStorage("address")
+const email = getLocalStorage("email")
+
+const form = ref({
+  avatar: avatar,
+  phone: phone,
+  username: username,
+  address: address,
+  email: email,
 });
 
+console.log("提交的表单数据:", form.value);
+
 const onSubmit = () => {
   console.log("提交的表单数据:", form);
 };