前言
项目地址
本项目是为开发一套容器化的开发、运行、测试环境,用以支持Web开发、程序设计等课程的实验教学。
任务
实现登出和忘记密码功能
登出
function goto_codingview() {
ElMessageBox.confirm(
'是否确认退出?',
'退出提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
}
)
.then(() => {
//点击确认
let param = new FormData();
request('/weblab/user/logout', param,store.getToken)
.then(res=>{
if(res.status==200&&res.data.msg=='success'){
store.userLogout();
router.push({ path: '/' });
}
})
.catch(error=>{
console.log(error);
})
})
.catch(() => {
//点击取消
router.push({ path: '/login_home' });
})
}
登出时将本地存储的相关信息删除掉
userLogout() {
this.isLogin = 0;
this.userId='';
this.userPassword='';
this.token='';
localStorage.removeItem('isLogin');
localStorage.removeItem('userId');
localStorage.removeItem('userPassword');
localStorage.removeItem('token');
},
忘记密码
输入邮箱获取验证码
const getCheckCode = async () => {
//发送邮箱验证码
const form = unref(emailRef);
if (!form) return
try {
await form.validate();
let param = new FormData();
param.append('email', emailForm.email);
showEmail.value = 2;
request('/weblab/user/forget_password', param)
.then(res => {
if (res.status == 200 && res.data.msg == 'success') {
}
})
.catch(error => {
console.log(error.code, error.message);
if (error.code == 'ECONNABORTED') {
// showEmail.value = 2;
ElMessage({
showClose: true,
message: '网络超时,请稍后再试',
type: 'error',
center: true,
grouping: true
})
}
})
} catch (error: any) {
ElMessage({
showClose: true,
message: '输入格式不正确',
type: 'error',
center: true,
grouping: true,
})
}
}
输入验证码
const next = async () => {
const form = unref(emailCheckFormRef);
if (!form) return
try {
await form.validate();
showEmail.value = 3;
} catch (error) {
ElMessage({
showClose: true,
message: '验证码错误',
type: 'error',
center: true,
grouping: true
})
}
};
更改密码
const goHome = async () => {
const form = unref(resetFormRef);
if (!form) return
try {
await form.validate();
//todo 发送修改密码请求
let param = new FormData();
param.append('code', emailCheckForm.checkCode);
param.append('password', resetForm.newPass);
request('/weblab/user/reset_password', param)
.then(res => {
console.log(emailCheckForm.checkCode);
console.log(resetForm.newPass);
if (res.status == 200 && res.data.msg == 'success') {
btnDisabled.value = true;
ElMessage({
showClose: true,
message: '修改密码成功',
type: 'success',
center: true,
grouping: true,
onClose: () => { router.push({ path: '/login' }) }
})
}
})
.catch(error => {
showEmail.value = 2;
ElMessage({
showClose: true,
message: '验证码错误',
type: 'error',
center: true,
grouping: true
})
})
} catch (error) {
ElMessage({
showClose: true,
message: '密码格式错误',
type: 'error',
center: true,
grouping: true
})
}