代码调整

This commit is contained in:
joylink_cuiweidong 2022-10-13 11:14:33 +08:00
parent a6a806c218
commit b5fd00fdcb
4 changed files with 296 additions and 7 deletions

View File

@ -0,0 +1,262 @@
<template>
<el-dialog
:title="title"
:visible.sync="dialogShow"
width="500px"
:before-close="doClose"
:z-index="9000"
:show-close="false"
:close-on-click-modal="false"
top="25vh"
>
<el-form ref="ruleForm" :model="form" :rules="rules" label-width="110px" class="demo-ruleForm">
<el-form-item prop="type">
<template slot="label">
<span>找回途径</span>
</template>
<el-radio-group v-model="form.type" size="small">
<el-radio label="phone" border>手机号找回</el-radio>
<el-radio label="email" border>邮箱找回</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="form.type === 'email'" prop="email">
<template slot="label">
<span>&emsp;&emsp;</span>
</template>
<el-input v-model="form.email" size="small" style="width: 200px;" />
</el-form-item>
<el-form-item v-if="form.type === 'phone'" prop="phone">
<template slot="label">
<span>手机号</span>
</template>
<el-input v-model="form.phone" size="small" style="width: 200px;" />
</el-form-item>
<el-form-item label="密码:" prop="password">
<template slot="label">
<span>&emsp;&emsp;</span>
</template>
<el-input v-model="form.password" size="small" autocomplete="new-password" show-password style="width: 200px;" />
</el-form-item>
<el-form-item label="密码确认:" prop="repeatPassword">
<el-input v-model="form.repeatPassword" size="small" autocomplete="new-password" show-password style="width: 200px;" />
</el-form-item>
<el-form-item prop="vfCode">
<template slot="label">
<span>验证码</span>
</template>
<el-input v-model="form.vfCode" size="small" style="display: inline-block;width: 200px" />
<el-button
size="small"
type="primary"
style="margin-top: 10px; margin-right: 10px;"
:disabled="passWordCodeTime != 0"
@click="sendVfcode"
>
{{ $t('global.sendCode') }}
<span
v-if="passWordCodeTime"
>{{ passWordCodeTime }}</span>
</el-button>
</el-form-item>
<div style="display: flex;justify-content: space-around;">
<el-button type="primary" size="small" @click="submitForm()">找回</el-button>
<el-button size="small" @click="doClose()">返回登录</el-button>
</div>
</el-form>
</el-dialog>
</template>
<script>
import { findPassword, sendPhoneVfcode, sendEmailVfcode } from '@/api/management/user';
import md5 from 'js-md5';
import {clearInterval, setInterval} from 'timers';
export default {
name: 'ForgetPassword',
data() {
var validateEmail = (rule, value, callback) => {
const regu = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
const re = new RegExp(regu);
if (!re.test(value) ) {
callback(new Error('邮箱格式不正确'));
} else {
callback();
}
};
var validatePhone = (rule, value, callback) => {
const regu = /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$/;
const re = new RegExp(regu);
if (!re.test(value)) {
callback(new Error('手机号格式不正确'));
} else {
callback();
}
};
var validatePassword = (rule, value, callback) => {
if (this.form.repeatPassword) {
this.$refs.ruleForm.validateField('repeatPassword');
}
callback();
};
var validateRepeatPassword = (rule, value, callback) => {
if (value !== this.form.password) {
callback(new Error('两次密码不相同,请确认密码'));
} else {
callback();
}
};
var validateVfCode = (rule, value, callback) => {
if (this.form.vfCode.length !== 4) {
callback(new Error('验证码长度错误'));
} else {
callback();
}
};
return {
dialogShow: false,
message: '',
operation: '',
title: '密码找回',
passWordTime: null,
form: {
type: 'phone',
phone: '',
email: '',
password: '',
repeatPassword: '',
vfCode: ''
},
passWordCodeTime: 0,
rules: {
phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' },
{ validator: validatePhone, trigger: 'blur' }
],
email: [
{ required: true, message: '请输入邮箱', trigger: 'blur' },
{ validator: validateEmail, trigger: 'blur' }
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ validator: validatePassword, trigger: 'blur' },
{ min: 5, max: 20, message: '长度在 5 到 20 个字符', trigger: 'blur' }
],
repeatPassword: [
{ required: true, message: '请重复输入密码', trigger: 'blur' },
{ validator: validateRepeatPassword, trigger: 'blur' },
{ min: 5, max: 20, message: '长度在 5 到 20 个字符', trigger: 'blur' }
],
vfCode: [
{ required: true, message: '请输入验证码', trigger: 'blur' },
{ validator: validateVfCode, trigger: 'blur' }
]
}
};
},
computed: {
},
mounted() {
},
methods: {
doShow() {
this.form = {
type: 'phone',
phone: '',
email: '',
password: '',
repeatPassword: '',
vfCode: ''
};
this.dialogShow = true;
},
doClose() {
this.dialogShow = false;
this.form = {
type: 'phone',
phone: '',
email: '',
password: '',
repeatPassword: '',
vfCode: ''
};
this.$refs.ruleForm.clearValidate();
},
async sendVfcode() {
const reguEmail = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
const reguPhone = /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$/;
const rePhone = new RegExp(reguPhone);
const reEmail = new RegExp(reguEmail);
if (this.form.type === 'phone' && this.form.phone && rePhone.test(this.form.phone)) {
const random = Math.floor(Math.random() * 10000 + 1);
const timeCount = Date.parse(new Date()) / 1000;
const pass = `${timeCount}86${this.form.phone}${random}`;
const param = {
mobile: this.form.phone,
nationCode: '86',
rd: random + '',
time: timeCount + '',
token: md5(pass)
};
try {
this.passWordCodeTime = 60;
this.passWordTime = setInterval(() => {
this.passWordCodeTime--;
if (this.passWordCodeTime <= 0) {
this.passWordCodeTime = 0;
clearInterval(this.mobileTime);
this.passWordTime = null;
}
}, 1000);
await sendPhoneVfcode(param);
} catch (error) {
this.$message.info(this.$t('global.codeFaile'));
}
} else if (this.form.type === 'email' && this.form.email && reEmail.test(this.form.email)) {
const param = { email: this.form.email };
try {
this.passWordCodeTime = 60;
this.passWordTime = setInterval(() => {
this.passWordCodeTime--;
if (this.passWordCodeTime <= 0) {
this.passWordCodeTime = 0;
clearInterval(this.mobileTime);
this.passWordTime = null;
}
}, 1000);
await sendEmailVfcode(param);
} catch (error) {
this.$message.info(this.$t('global.codeFaile'));
}
} else {
this.$refs.ruleForm.validateField('email');
this.$refs.ruleForm.validateField('phone');
}
},
submitForm() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
const data = { email: this.form.email, mobile: this.form.phone, newPwd: md5(this.form.password), vfCode: this.form.vfCode };
findPassword(data).then(resp => {
this.$message.success('设置密码成功!' );
this.doClose();
}).catch(error => {
this.$message.error('设置密码失败:' + error.message);
});
}
});
}
}
};
</script>
<style scoped>
.confirm-control-speed .context {
padding-bottom: 40px !important;
border: 1px solid lightgray;
}
.ningbo-01__systerm .el-dialog .el-button{
display: block;
margin: 0 auto;
}
</style>

View File

@ -3,7 +3,7 @@
<div v-if="syncLogin">
{{}}
</div>
<div v-else class="login-container" :style="{ 'background-image': showBackPic?'url(' + bgImg + ')':'none' }">
<div v-else v-show="loadedConfig" class="login-container" :style="{ 'background-image': showBackPic?'url(' + bgImg + ')':'none' }">
<div class="language_box">
<el-tooltip effect="dark" :content="this.$t('login.clickSwitchLanguage')" placement="bottom-end">
<el-button class="language_btn" type="text" @click="handleLanguage">{{ language }}</el-button>
@ -18,13 +18,14 @@
<!-- 微信登陆 -->
<wechat-login v-if="wechatLogin" ref="wechatLogin" :project="backProject" :sync-login="syncLogin" />
<!-- 默认登陆 -->
<normal-login ref="normalLogin" :project="backProject" />
<normal-login ref="normalLogin" :project="backProject" :local-project="localProject" @forgetPassword="forgetPassword" />
</div>
<base-development v-if="baseDevelopment" ref="baseDevelopment" />
<div class="bottomInfo">
<span>{{ aboutSystem }}</span>
</div>
</div>
<forget-password ref="forgetPassword" />
</div>
</template>
<script>
@ -35,15 +36,18 @@ import { getFrontProjectConfigByLogin} from '@/api/projectConfig';
import WechatLogin from './wechatLogin';
import NormalLogin from './normalLogin';
import BaseDevelopment from './baseDevelopment';
import ForgetPassword from './forgetPassword';
export default {
name:'LoginNew',
components: { WechatLogin, NormalLogin, BaseDevelopment },
components: { WechatLogin, NormalLogin, BaseDevelopment, ForgetPassword },
data() {
return {
backProject:'',
language: '中文',
lang: 'zh',
loginProtitle:'',
localProject:false,
loadedConfig:false,
showBackPic:true,
wechatLogin:true,
loginProLogoWidth:0,
@ -75,7 +79,7 @@ export default {
if (response.data) {
this.backProject = response.data.project;
// loginProLogoHeight
const {showBackPic, wechatLogin, aboutSystem, baseDevelopment, browserTitle, homeTitle, caseShow, loginProtitle, loginProLogoWidth, loginOrgTitle, homeProLogoWidth, loginProLogo} = response.data.viewSetting;
const {showBackPic, wechatLogin, aboutSystem, baseDevelopment, browserTitle, homeTitle, caseShow, loginProtitle, loginProLogoWidth, loginOrgTitle, localProject, homeProLogoWidth, loginProLogo} = response.data.viewSetting;
this.showBackPic = showBackPic;
this.wechatLogin = wechatLogin;
this.loginProtitle = loginProtitle;
@ -85,12 +89,14 @@ export default {
this.loginProLogo = loginProLogo ? this.$store.state.user.ossUrl + '/logo/' + loginProLogo : '';
this.aboutSystem = aboutSystem;
this.baseDevelopment = baseDevelopment;
this.localProject = localProject;
document.title = browserTitle;
document.querySelector("link[rel*='icon']").href = this.loginProLogo;
this.$store.dispatch('setHomeProLogoWidth', homeProLogoWidth);
this.$store.dispatch('setLoginProLogo', this.loginProLogo);
this.$store.dispatch('setHomeTitle', homeTitle);
this.$store.dispatch('setCaseShow', caseShow);
this.loadedConfig = true;
// helpShow
// loginContectInformation false
setSessionStorage('project', this.project);
@ -103,6 +109,9 @@ export default {
handleLanguage() {
this.$i18n.locale = this.lang;
LangStorage.setLang(this.lang);
},
forgetPassword() {
this.$refs.forgetPassword.doShow();
}
}
};

View File

@ -43,6 +43,7 @@
<!-- <el-checkbox v-if="project === 'cgy'" v-model="teacherLogin">教师登录</el-checkbox> -->
</div>
<el-popover
v-if="!localProject"
placement="right"
title=""
width="200"
@ -68,11 +69,11 @@
{{ $t('login.login') }}
</el-button>
</el-form-item>
<!-- <div style="display: inline-block;width: 100%;">
<div v-if="!localProject" style="display: inline-block;width: 100%;">
<div class="popover_box active" style="bottom: 50px;" @click="forgetPassword">
忘记密码
</div>
</div> -->
</div>
</el-form>
</template>
<script>
@ -82,7 +83,6 @@ import md5 from 'js-md5';
import Cookies from 'js-cookie';
// getLoginWmurl, checkLoginStatus, getLoginInfo,
import { getOrgList, selectOrgnization } from '@/api/login';
// import ForgetPassword from './forgetPassword';
export default {
name:'NormalLogin',
// Register,
@ -93,6 +93,12 @@ export default {
default: () => {
return '';
}
},
localProject:{
type: Boolean,
default: () => {
return false;
}
}
// syncLogin:{
// type: Boolean,
@ -200,6 +206,8 @@ export default {
} else {
// this.showOrgSelect(orgList).then(this.handleLoginSucessRoute());
}
}).catch(()=>{
this.loading = false;
});
},
handleLoginSucessRoute() {
@ -230,6 +238,9 @@ export default {
return false;
}
});
},
forgetPassword() {
this.$emit('forgetPassword');
}
}
};

View File

@ -49,6 +49,9 @@
<el-form-item label="帮助展示:" prop="helpShow" class="inlineBlock">
<el-switch v-model="formModel.helpShow" />
</el-form-item>
<el-form-item label="本地项目:" prop="localProject" class="inlineBlock">
<el-switch v-model="formModel.localProject" />
</el-form-item>
<br>
<el-form-item label="登陆后跳转路径:" prop="judgeRoute" class="inlineBlock">
<el-input v-model="formModel.judgeRoute" style="width: 210px;" size="small" />
@ -96,6 +99,7 @@ export default {
navLogoHeight:'', // Logo
caseShow:true, //
helpShow:true, //
localProject:false, //
judgeRoute:'', //
baseApiUrl:'', // api
@ -153,11 +157,13 @@ export default {
this.formModel.navLogoHeight = viewSetting.navLogoHeight || '';
this.formModel.caseShow = viewSetting.caseShow || false;
this.formModel.helpShow = viewSetting.helpShow || false;
this.formModel.localProject = viewSetting.localProject || false;
this.formModel.judgeRoute = viewSetting.judgeRoute || '';
this.formModel.baseApiUrl = viewSetting.baseApiUrl || '';
this.formModel.baseSite = viewSetting.baseSite || '';
this.formModel.ossUrl = viewSetting.ossUrl || '';
}
},
handleClose() {
@ -179,6 +185,7 @@ export default {
navLogoHeight:'', // Logo
caseShow:true, //
helpShow:true, //
localProject:false, //
judgeRoute:'', //
baseApiUrl:'', // api