UnisKB/ui/src/layout/layout-header/avatar/ResetPassword.vue

210 lines
5.9 KiB
Vue
Raw Normal View History

2025-04-28 07:23:25 +00:00
<template>
<el-dialog
v-model="resetPasswordDialog"
:title="$t('views.login.resetPassword')"
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<el-form
class="reset-password-form"
ref="resetPasswordFormRef1"
:model="resetPasswordForm"
:rules="rules1"
>
<p class="mb-8 lighter">{{ $t('views.login.newPassword') }}</p>
<el-form-item prop="password" style="margin-bottom: 8px">
<el-input
type="password"
class="input-item"
v-model="resetPasswordForm.password"
:placeholder="$t('views.login.enterPassword')"
show-password
>
</el-input>
</el-form-item>
<el-form-item prop="re_password">
<el-input
type="password"
class="input-item"
v-model="resetPasswordForm.re_password"
2025-06-12 11:23:11 +00:00
:placeholder="$t('views.login.enterPassword')"
2025-04-28 07:23:25 +00:00
show-password
>
</el-input>
</el-form-item>
</el-form>
2025-06-12 11:23:11 +00:00
<!-- <el-form-->
<!-- class="reset-password-form mb-24"-->
<!-- ref="resetPasswordFormRef2"-->
<!-- :model="resetPasswordForm"-->
<!-- :rules="rules2"-->
<!-- >-->
<!-- <p class="mb-8 lighter">{{ $t('views.login.useEmail') }}</p>-->
<!-- <el-form-item style="margin-bottom: 8px">-->
<!-- <el-input-->
<!-- class="input-item"-->
<!-- :disabled="true"-->
<!-- v-bind:modelValue="user.userInfo?.email"-->
<!-- :placeholder="t('views.user.userForm.form.email.placeholder')"-->
<!-- >-->
<!-- </el-input>-->
<!-- </el-form-item>-->
<!-- <el-form-item prop="code">-->
<!-- <div class="flex-between w-full">-->
<!-- <el-input-->
<!-- class="code-input"-->
<!-- v-model="resetPasswordForm.code"-->
<!-- :placeholder="$t('views.login.verificationCode.placeholder')"-->
<!-- >-->
<!-- </el-input>-->
<!-- <el-button-->
<!-- :disabled="isDisabled"-->
<!-- class="send-email-button ml-8"-->
<!-- @click="sendEmail"-->
<!-- :loading="loading"-->
<!-- >-->
<!-- {{-->
<!-- isDisabled-->
<!-- ? `${$t('views.login.verificationCode.resend')}${time}s`-->
<!-- : $t('views.login.verificationCode.getVerificationCode')-->
<!-- }}-->
<!-- </el-button>-->
<!-- </div>-->
<!-- </el-form-item>-->
<!-- </el-form>-->
2025-04-28 07:23:25 +00:00
<template #footer>
<div class="dialog-footer">
<el-button @click="resetPasswordDialog = false">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="resetPassword">
{{ $t('common.save') }}
</el-button>
</div>
</template>
</el-dialog>
</template>
<script setup lang="ts">
2025-06-13 03:00:15 +00:00
import { ref } from 'vue'
import type { ResetCurrentUserPasswordRequest } from '@/api/type/user'
import type { FormInstance, FormRules } from 'element-plus'
2025-06-12 11:23:11 +00:00
import UserApi from '@/api/user/user-manage'
2025-04-28 07:23:25 +00:00
import useStore from '@/stores'
2025-06-13 03:00:15 +00:00
import { useRouter } from 'vue-router'
import { t } from '@/locales'
2025-06-12 11:23:11 +00:00
2025-04-28 07:23:25 +00:00
const router = useRouter()
2025-06-13 03:00:15 +00:00
const { login } = useStore()
2025-04-28 07:23:25 +00:00
const resetPasswordDialog = ref<boolean>(false)
const resetPasswordForm = ref<ResetCurrentUserPasswordRequest>({
code: '',
password: '',
2025-06-13 03:00:15 +00:00
re_password: '',
2025-04-28 07:23:25 +00:00
})
const resetPasswordFormRef1 = ref<FormInstance>()
const resetPasswordFormRef2 = ref<FormInstance>()
const loading = ref<boolean>(false)
const isDisabled = ref<boolean>(false)
const time = ref<number>(60)
const rules1 = ref<FormRules<ResetCurrentUserPasswordRequest>>({
password: [
{
required: true,
message: t('views.login.enterPassword'),
2025-06-13 03:00:15 +00:00
trigger: 'blur',
2025-04-28 07:23:25 +00:00
},
{
min: 6,
max: 20,
message: t('views.user.userForm.form.password.lengthMessage'),
2025-06-13 03:00:15 +00:00
trigger: 'blur',
},
2025-04-28 07:23:25 +00:00
],
re_password: [
{
required: true,
message: t('views.user.userForm.form.re_password.requiredMessage'),
2025-06-13 03:00:15 +00:00
trigger: 'blur',
2025-04-28 07:23:25 +00:00
},
{
min: 6,
max: 20,
message: t('views.user.userForm.form.password.lengthMessage'),
2025-06-13 03:00:15 +00:00
trigger: 'blur',
2025-04-28 07:23:25 +00:00
},
{
validator: (rule, value, callback) => {
if (resetPasswordForm.value.password != resetPasswordForm.value.re_password) {
callback(new Error(t('views.user.userForm.form.re_password.validatorMessage')))
} else {
callback()
}
},
2025-06-13 03:00:15 +00:00
trigger: 'blur',
},
],
2025-04-28 07:23:25 +00:00
})
2025-06-12 11:23:11 +00:00
// const rules2 = ref<FormRules<ResetCurrentUserPasswordRequest>>({
// // @ts-ignore
// code: [
// {
// required: true,
// message: t('views.login.verificationCode.placeholder'),
// trigger: 'blur'
// }
// ]
// })
// /**
// * 发送验证码
// */
// const sendEmail = () => {
// resetPasswordFormRef1.value?.validate().then(() => {
// UserApi.sendEmailToCurrent(loading).then(() => {
// MsgSuccess(t('views.login.verificationCode.successMessage'))
// isDisabled.value = true
// handleTimeChange()
// })
// })
// }
2025-04-28 07:23:25 +00:00
const handleTimeChange = () => {
if (time.value <= 0) {
isDisabled.value = false
time.value = 60
} else {
setTimeout(() => {
time.value--
handleTimeChange()
}, 1000)
}
}
const open = () => {
resetPasswordForm.value = {
2025-06-12 11:23:11 +00:00
//code: '',
2025-04-28 07:23:25 +00:00
password: '',
2025-06-13 03:00:15 +00:00
re_password: '',
2025-04-28 07:23:25 +00:00
}
resetPasswordDialog.value = true
resetPasswordFormRef1.value?.resetFields()
resetPasswordFormRef2.value?.resetFields()
}
const resetPassword = () => {
resetPasswordFormRef1.value?.validate().then(() => {
2025-06-13 03:00:15 +00:00
return UserApi.resetCurrentPassword(resetPasswordForm.value).then(() => {
login.logout()
router.push({ name: 'login' })
})
2025-04-28 07:23:25 +00:00
})
}
const close = () => {
resetPasswordDialog.value = false
}
2025-06-13 03:00:15 +00:00
defineExpose({ open, close })
2025-04-28 07:23:25 +00:00
</script>
<style lang="scss" scope></style>