UNIVPLMDataIntegration/Web/src/views/system/user/component/changePassword.vue

108 lines
3.9 KiB
Vue
Raw Normal View History

2024-09-01 13:07:42 +08:00
<template>
<div class="changePassword-container">
<el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" :close-on-press-escape="false" width="700px" :show-close="false">
2024-09-01 13:07:42 +08:00
<template #header>
<div style="color: #fff">
<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-View /> </el-icon>
2025-02-28 17:54:01 +08:00
<span> {{ t('message.list.changePassword') }} </span>
2024-09-01 13:07:42 +08:00
</div>
</template>
<div style="color: red; padding: 10px 10px; background: #faecd8; margin-bottom: 30px">
<el-icon style="transform: translateY(2px)"><ele-Bell /></el-icon>
2025-02-28 17:54:01 +08:00
<span> {{ t('message.list.passwordPolicy') }} </span>
2024-09-01 13:07:42 +08:00
</div>
<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto">
<el-row :gutter="10">
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
2025-02-28 17:54:01 +08:00
<el-form-item :label="t('message.list.currentPassword')" prop="passwordOld" :rules="[{ required: true, message: t('message.list.currentPasswordRequired'), trigger: 'blur' }]">
2024-09-01 13:07:42 +08:00
<el-input v-model="state.ruleForm.passwordOld" type="password" autocomplete="off" show-password />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
2025-02-28 17:54:01 +08:00
<el-form-item :label="t('message.list.newPassword')" prop="passwordNew" :rules="[{ required: true, message: t('message.list.newPasswordRequired'), trigger: 'blur' }]">
2024-09-01 13:07:42 +08:00
<el-input v-model="state.ruleForm.passwordNew" type="password" autocomplete="off" show-password />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
2025-02-28 17:54:01 +08:00
<el-form-item :label="t('message.list.confirmPassword')" prop="passwordNew2" :rules="[{ validator: validatePassword, required: true, trigger: 'blur' }]">
2024-09-01 13:07:42 +08:00
<el-input v-model="state.passwordNew2" type="password" autocomplete="off" show-password />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
2025-02-28 17:54:01 +08:00
<el-button type="danger" plain @click="logout">{{ t('message.list.cancelButtonText') }}</el-button>
<el-button type="primary" icon="ele-CircleCheckFilled" @click="submit">{{ t('message.list.confirmButtonText') }}</el-button>
2024-09-01 13:07:42 +08:00
</span>
</template>
</el-dialog>
</div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { ElMessage } from 'element-plus';
2024-09-01 13:07:42 +08:00
import { sm2 } from 'sm-crypto-v2';
import { clearAccessTokens, getAPI } from '/@/utils/axios-utils';
import { SysUserApi } from '/@/api-services/api';
import { ChangePwdInput } from '/@/api-services/models';
2025-02-28 17:54:01 +08:00
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
2024-09-01 13:07:42 +08:00
const ruleFormRef = ref();
const state = reactive({
isShowDialog: false,
ruleForm: {} as ChangePwdInput,
passwordNew2: '',
});
// 打开弹窗
const openDialog = () => {
state.isShowDialog = true;
ruleFormRef.value?.resetFields();
};
// // 取消
// const cancel = () => {
// state.isShowDialog = false;
// };
// 提交
const submit = () => {
ruleFormRef.value?.validate(async (valid: boolean) => {
if (!valid) return;
// SM2加密密码
const cpwd: ChangePwdInput = { passwordOld: '', passwordNew: '' };
const publicKey = window.__env__.VITE_SM_PUBLIC_KEY;
cpwd.passwordOld = sm2.doEncrypt(state.ruleForm.passwordOld, publicKey, 1);
cpwd.passwordNew = sm2.doEncrypt(state.ruleForm.passwordNew, publicKey, 1);
await getAPI(SysUserApi).apiSysUserChangePwdPost(cpwd);
2025-02-28 17:54:01 +08:00
ElMessage.success(t('message.list.passwordChangedNeedRelogin'));
state.isShowDialog = false;
clearAccessTokens();
2024-09-01 13:07:42 +08:00
});
};
// 密码验证
const validatePassword = (_rule: any, value: any, callback: any) => {
if (state.passwordNew2 != state.ruleForm.passwordNew) {
2025-02-28 17:54:01 +08:00
callback(new Error(t('message.list.passwordNotMatch')));
2024-09-01 13:07:42 +08:00
} else {
callback();
}
};
// 退出
const logout = () => {
clearAccessTokens();
};
2024-09-01 13:07:42 +08:00
// 导出对象
defineExpose({ openDialog });
</script>