Files
xiaozhi-esp32-server/main/manager-web/src/components/ChangePasswordDialog.vue
T

129 lines
3.5 KiB
Vue
Raw Normal View History

2025-03-24 18:08:05 +08:00
<template>
2025-04-01 10:59:35 +08:00
<form>
<CustomDialog
:title="$t('changePassword.title')"
:visible.sync="dialogVisible"
width="600px"
@cancel="cancel"
@confirm="confirm">
<div class="password-form">
<div class="form-label">
<span class="required">*</span>
{{ $t('changePassword.oldPasswordLabel') }}
2025-04-01 10:59:35 +08:00
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input :placeholder="$t('changePassword.oldPasswordPlaceholder')" v-model="oldPassword" type="password" show-password />
2025-04-01 10:59:35 +08:00
</div>
<div class="form-label" style="margin-top: 12px;">
<span class="required">*</span>
{{ $t('changePassword.newPasswordLabel') }}
2025-04-01 10:59:35 +08:00
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input :placeholder="$t('changePassword.newPasswordPlaceholder')" v-model="newPassword" type="password" show-password />
2025-04-01 10:59:35 +08:00
</div>
<div class="form-label" style="margin-top: 12px;">
<span class="required">*</span>
{{ $t('changePassword.confirmPasswordLabel') }}
2025-04-01 10:59:35 +08:00
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input :placeholder="$t('changePassword.confirmPasswordPlaceholder')" v-model="confirmNewPassword" type="password" show-password />
2025-04-01 10:59:35 +08:00
</div>
2025-03-24 18:08:05 +08:00
</div>
</CustomDialog>
2025-04-01 10:59:35 +08:00
</form>
2025-03-24 18:08:05 +08:00
</template>
<script>
import userApi from '@/apis/module/user';
2025-04-01 10:59:35 +08:00
import { mapActions } from 'vuex';
import CustomDialog from '@/components/CustomDialog.vue';
2025-03-24 18:08:05 +08:00
export default {
name: 'ChangePasswordDialog',
props: {
2025-04-01 10:59:35 +08:00
value: {
type: Boolean,
required: true
}
2025-03-24 18:08:05 +08:00
},
data() {
return {
2025-05-08 17:57:11 +08:00
dialogVisible: this.value,
2025-03-24 18:08:05 +08:00
oldPassword: "",
newPassword: "",
confirmNewPassword: ""
}
},
components: {
CustomDialog
},
2025-05-08 17:57:11 +08:00
watch: {
value(val) {
this.dialogVisible = val;
},
dialogVisible(val) {
this.$emit('input', val);
}
},
2025-03-24 18:08:05 +08:00
methods: {
2025-04-01 10:59:35 +08:00
...mapActions(['logout']), // 引入Vuex的logout action
2025-03-24 18:08:05 +08:00
confirm() {
if (!this.oldPassword.trim() || !this.newPassword.trim() || !this.confirmNewPassword.trim()) {
this.$message.error(this.$t('changePassword.allFieldsRequired'));
2025-03-24 18:08:05 +08:00
return;
}
if (this.newPassword !== this.confirmNewPassword) {
this.$message.error(this.$t('changePassword.passwordsNotMatch'));
2025-03-24 18:08:05 +08:00
return;
}
if (this.newPassword === this.oldPassword) {
this.$message.error(this.$t('changePassword.newPasswordSameAsOld'));
2025-03-24 18:08:05 +08:00
return;
}
2025-04-01 10:59:35 +08:00
// 修改后的接口调用
2025-03-24 18:08:05 +08:00
userApi.changePassword(this.oldPassword, this.newPassword, (res) => {
2025-04-01 10:59:35 +08:00
if (res.data.code === 0) {
this.$message.success({
message: this.$t('changePassword.passwordChangedSuccessfully'),
showClose: true
});
2025-04-01 10:59:35 +08:00
this.logout().then(() => {
this.$router.push('/login');
});
} else {
this.$message.error(res.data.msg || this.$t('changePassword.changeFailed'));
2025-03-24 18:08:05 +08:00
}
}, (err) => {
this.$message.error(err.msg || this.$t('changePassword.changeFailed'));
2025-03-24 18:08:05 +08:00
});
this.dialogVisible = false;
2025-03-24 18:08:05 +08:00
},
cancel() {
this.resetForm();
},
resetForm() {
this.oldPassword = "";
this.newPassword = "";
this.confirmNewPassword = "";
}
}
}
</script>
<style scoped>
.form-label {
text-align: left;
}
.required {
color: red;
display: inline-block;
}
2025-03-24 18:08:05 +08:00
.input-46 {
background: #f6f8fb;
border-radius: 15px;
}
</style>