zouzs vor 21 Stunden
Ursprung
Commit
2466402d84

+ 15 - 1
src/api/user.ts

@@ -75,7 +75,7 @@ export const getLogin = (data?: object) => {
   });
 };
 
-/** 登录 */
+/** 短信登录 */
 export const verifySmsLogin = (data?: object) => {
   return http.request<UserResult>("post", baseUrlApi("crmAccount/smsLogin"), {
     data
@@ -89,6 +89,20 @@ export const refreshTokenApi = (data?: object) => {
   });
 };
 
+/**
+ * 更改密码
+ * @param data
+ */
+export const updatePassword = (data?: object) => {
+  return http.request<BasicResponseModel>(
+    "post",
+    baseUrlApi("merchantUserInfo/updatePassword"),
+    {
+      data
+    }
+  );
+};
+
 /**
  * 获取用户信息
  */

+ 9 - 0
src/router/modules/changePwd.ts

@@ -0,0 +1,9 @@
+export default {
+  path: "/changePwd",
+  meta: {
+    title: "更改密码",
+    showLink: false
+  },
+  name: "ChangePwd",
+  component: () => import("@/views/changePwd/index.vue")
+} as RouteConfigsTable;

+ 0 - 3
src/router/modules/childAccount.ts

@@ -1,6 +1,3 @@
-// 最简代码,也就是这些字段必须有
-import { useUserStoreHook } from "@/store/modules/user";
-
 export default {
   path: "/childAccount",
   meta: {

+ 9 - 0
src/router/modules/remaining.ts

@@ -44,5 +44,14 @@ export default [
         component: () => import("@/layout/redirect.vue")
       }
     ]
+  },
+  {
+    path: "/changePwd",
+    meta: {
+      title: "更改密码",
+      showLink: false
+    },
+    name: "ChangePwd",
+    component: () => import("@/views/changePwd/index.vue")
   }
 ] satisfies Array<RouteConfigsTable>;

+ 144 - 0
src/views/changePwd/index.vue

@@ -0,0 +1,144 @@
+<script setup lang="ts">
+import { type PlusColumn, PlusForm } from "plus-pro-components";
+import { onMounted, reactive, toRefs } from "vue";
+import { useRoute } from "vue-router";
+import { updatePassword } from "@/api/user";
+import { ElMessage } from "element-plus";
+import { md5 } from "js-md5";
+import { useUserStoreHook } from "@/store/modules/user";
+
+defineOptions({
+  name: "ChangePwd"
+});
+
+const route = useRoute();
+
+const defaultValues = {
+  account: route.query.account as string
+};
+
+onMounted(() => {
+  form.value = defaultValues;
+});
+
+interface State {
+  form: {
+    account: string;
+    oldPassword: string;
+    password: string;
+    confirmPassword: string;
+  };
+}
+
+const state = reactive<State>({
+  form: {
+    account: "",
+    oldPassword: "",
+    password: "",
+    confirmPassword: ""
+  }
+});
+
+const { form } = toRefs(state);
+
+const submit = async () => {
+  try {
+    let params = {
+      account: form.value.account,
+      oldPassword: md5(form.value.oldPassword).toUpperCase(),
+      password: md5(form.value.password).toUpperCase(),
+      confirmPassword: md5(form.value.confirmPassword).toUpperCase()
+    };
+    let res = await updatePassword(params);
+    if (res.code === 0) {
+      ElMessage.success("修改成功");
+      setTimeout(() => {
+        useUserStoreHook().logOut();
+      }, 1000);
+    } else {
+      ElMessage.error(res.msg);
+    }
+  } catch (error) {
+    console.log(error);
+  }
+};
+
+const rules = {
+  oldPassword: [{ required: true, message: "请输入旧密码", trigger: "blur" }],
+  password: [
+    { required: true, message: "请输入新密码", trigger: "blur" },
+    // 输入8到16位密码,须包括大小写字母、数字和特殊符号
+    {
+      pattern:
+        /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,./]).{8,16}$/,
+      message: "输入8到16位密码,须包括大小写字母、数字和特殊符号",
+      trigger: "blur"
+    }
+  ],
+  confirmPassword: [
+    { required: true, message: "请输入确认密码", trigger: "blur" },
+    {
+      validator: (rule, value, callback) => {
+        console.log("value", value, form.value.password);
+        if (value !== form.value.password) {
+          callback(new Error("两次输入的密码不一致"));
+        } else {
+          callback();
+        }
+      },
+      trigger: "blur"
+    }
+  ]
+};
+
+const columns: PlusColumn[] = [
+  {
+    label: "账号",
+    prop: "account",
+    fieldProps: {
+      disabled: true
+    }
+  },
+  {
+    label: "旧密码",
+    prop: "oldPassword",
+    valueType: "input",
+    fieldProps: {
+      type: "password"
+    }
+  },
+  {
+    label: "新密码",
+    prop: "password",
+    valueType: "input",
+    fieldProps: {
+      type: "password"
+    }
+  },
+  {
+    label: "确认密码",
+    prop: "confirmPassword",
+    valueType: "input",
+    fieldProps: {
+      type: "password"
+    }
+  }
+];
+</script>
+
+<template>
+  <div class="p-5">
+    <el-card header="更改密码">
+      <PlusForm
+        v-model="form"
+        :columns="columns"
+        :defaultValues="defaultValues"
+        label-width="120"
+        :rules="rules"
+        @submit="submit"
+      />
+    </el-card>
+  </div>
+</template>
+
+<style scoped lang="scss"></style>

+ 5 - 3
src/views/login/index.vue

@@ -155,9 +155,11 @@ const onLogin = async (formEl: FormInstance | undefined) => {
                     /*initRouter().then(() => {
                       router.push(getTopMenu(true).path);
                     });*/
-                    console.log("getTopMenu", getTopMenu(true).path);
-                    router.push(getTopMenu(true).path);
-                    message("登录成功", { type: "success" });
+                    router.replace({
+                      name: "ChangePwd",
+                      query: { account: res.data.loginName }
+                    });
+                    // message("登录成功", { type: "success" });
                   } else router.replace(toPath);
                 } else {
                   const toPath = decodeURIComponent(