|
@@ -1,14 +1,86 @@
|
|
|
<script setup>
|
|
|
-import { ref } from 'vue';
|
|
|
-const userStore = useUserStore();
|
|
|
+import { ref, unref } from 'vue';
|
|
|
import { useUserStore } from '@/stores/modules/userStore';
|
|
|
-import { NModal, NForm, NFormItem, NInput, NButton } from "naive-ui";
|
|
|
+import { NModal, NForm, NFormItem, NInput, NButton, useMessage } from "naive-ui";
|
|
|
+import { userApi } from '@/api/user'
|
|
|
+
|
|
|
+const message = useMessage();
|
|
|
+const userStore = useUserStore();
|
|
|
+
|
|
|
+const formRef = ref(null);
|
|
|
+
|
|
|
const model = ref({
|
|
|
oldPassword: '',
|
|
|
newPassword: '',
|
|
|
- confirmPassword: ''
|
|
|
+ reenteredPassword: ''
|
|
|
})
|
|
|
|
|
|
+const rules = {
|
|
|
+ oldPassword: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '请输入旧密码'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ newPassword: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '请输入新密码'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ validator: (_, value) => (/^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z\d]{8,16}$/.test(value)),
|
|
|
+ message: '新密码需要8-16位, 且包含字母和数字'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ reenteredPassword: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: '请再次输入密码',
|
|
|
+ trigger: ['input', 'blur']
|
|
|
+ },
|
|
|
+ {
|
|
|
+ validator: (_, value) => {
|
|
|
+ return !!model.value.newPassword && model.value.newPassword.startsWith(value) && model.value.newPassword.length >= value.length;
|
|
|
+ },
|
|
|
+ message: "两次密码输入不一致",
|
|
|
+ trigger: "input"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 重置表单
|
|
|
+*/
|
|
|
+const resetForm = () => {
|
|
|
+ formRef.value?.restoreValidation();
|
|
|
+ model.value = {
|
|
|
+ oldPassword: '',
|
|
|
+ newPassword: '',
|
|
|
+ reenteredPassword: ''
|
|
|
+ }
|
|
|
+ userStore.dialogStatus = false;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 取消表单
|
|
|
+*/
|
|
|
+const onCancel = () => resetForm();
|
|
|
+
|
|
|
+/**
|
|
|
+ * 提交表单
|
|
|
+*/
|
|
|
+const onSubmit = event => {
|
|
|
+ event.preventDefault();
|
|
|
+ formRef.value?.validate((errors) => {
|
|
|
+ if (!errors) {
|
|
|
+ const { oldPassword, newPassword } = unref(model);
|
|
|
+ userApi.putPassword({ oldPassword, newPassword });
|
|
|
+ resetForm();
|
|
|
+ message.success('密码修改成功');
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -17,21 +89,21 @@ const model = ref({
|
|
|
<div class="edit-passWord">
|
|
|
<div class="title">修改密码</div>
|
|
|
<div class="main">
|
|
|
- <n-form ref="formRef" :model="model" label-placement="left" label-align="left" :label-width="64">
|
|
|
- <n-form-item label="旧密码" path="oldPassword">
|
|
|
+ <n-form ref="formRef" :model="model" :rules="rules" label-placement="left" label-align="left" :label-width="64" :show-require-mark="false">
|
|
|
+ <n-form-item label="旧密码" path="oldPassword" first>
|
|
|
<n-input v-model:value="model.oldPassword" class="input" placeholder="请输入登录密码" type="password" />
|
|
|
</n-form-item>
|
|
|
- <n-form-item label="新密码" path="newPassword">
|
|
|
+ <n-form-item label="新密码" path="newPassword" first>
|
|
|
<n-input v-model:value="model.newPassword" class="input" placeholder="请输入8~16位数字,字母" type="password" />
|
|
|
</n-form-item>
|
|
|
- <n-form-item label="确认密码" path="confirmPassword">
|
|
|
- <n-input v-model:value="model.confirmPassword" class="input" placeholder="请再次输入密码" type="password" />
|
|
|
+ <n-form-item label="确认密码" path="reenteredPassword" first>
|
|
|
+ <n-input v-model:value="model.reenteredPassword" class="input" placeholder="请再次输入密码" type="password" />
|
|
|
</n-form-item>
|
|
|
</n-form>
|
|
|
</div>
|
|
|
<div class="footer">
|
|
|
- <n-button class="cencel btn" @click="userStore.dialogStatus = false">取消</n-button>
|
|
|
- <n-button type="primary" class="ok btn" @click="userStore.dialogStatus = false">确定</n-button>
|
|
|
+ <n-button class="cencel btn" @click="onCancel">取消</n-button>
|
|
|
+ <n-button type="primary" class="ok btn" @click="onSubmit">确定</n-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</n-modal>
|
|
@@ -44,7 +116,9 @@ const model = ref({
|
|
|
padding: 20px 32px;
|
|
|
background: linear-gradient(180deg, #D6EEFF 0%, #F1F7FB 100%);
|
|
|
|
|
|
-
|
|
|
+ .n-form-item-feedback__line {
|
|
|
+ font-size: 12px;
|
|
|
+ }
|
|
|
|
|
|
.title {
|
|
|
color: #1A2029;
|
|
@@ -53,12 +127,10 @@ const model = ref({
|
|
|
font-weight: bold;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
.main {
|
|
|
background: #fff;
|
|
|
- padding: 20px 43px;
|
|
|
- height: 192px;
|
|
|
+ padding: 20px 43px 0 43px;
|
|
|
+ height: 200px;
|
|
|
|
|
|
.input {
|
|
|
border: 0.5px solid #D7D7D7;
|
|
@@ -92,4 +164,12 @@ const model = ref({
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+</style>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+.edit-passWord {
|
|
|
+ .n-form-item-feedback__line {
|
|
|
+ font-size: 12px;
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|