update login index.vue

This commit is contained in:
macro 2019-10-06 16:34:45 +08:00
parent de33b5ac1f
commit dc76d42867
2 changed files with 38 additions and 11 deletions

View File

@ -7,3 +7,11 @@ export function getSupport() {
export function setSupport(isSupport) { export function setSupport(isSupport) {
return Cookies.set(SupportKey, isSupport,{ expires: 3 }) return Cookies.set(SupportKey, isSupport,{ expires: 3 })
} }
export function setCookie(key,value,expires) {
return Cookies.set(key, value,{ expires: expires})
}
export function getCookie(key) {
return Cookies.get(key)
}

View File

@ -36,10 +36,13 @@
</span> </span>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item style="margin-bottom: 60px"> <el-form-item style="margin-bottom: 60px;text-align: center">
<el-button style="width: 100%" type="primary" :loading="loading" @click.native.prevent="handleLogin"> <el-button style="width: 45%" type="primary" :loading="loading" @click.native.prevent="handleLogin">
登录 登录
</el-button> </el-button>
<el-button style="width: 45%" type="primary" @click.native.prevent="handleTry">
获取体验账号
</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
@ -51,7 +54,8 @@
:center="true" :center="true"
width="30%"> width="30%">
<div style="text-align: center"> <div style="text-align: center">
<span class="font-title-large">mall全套学习教程连载中<span class="color-main font-extra-large">关注公众号</span>第一时间获取</span> <span class="font-title-large"><span class="color-main font-extra-large">关注公众号</span>回复<span class="color-main font-extra-large">体验</span>获取体验账号</span>
<br>
<img src="http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/banner/qrcode_for_macrozheng_258.jpg" width="160" height="160" style="margin-top: 10px"> <img src="http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/banner/qrcode_for_macrozheng_258.jpg" width="160" height="160" style="margin-top: 10px">
</div> </div>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
@ -63,7 +67,7 @@
<script> <script>
import {isvalidUsername} from '@/utils/validate'; import {isvalidUsername} from '@/utils/validate';
import {setSupport,getSupport} from '@/utils/support'; import {setSupport,getSupport,setCookie,getCookie} from '@/utils/support';
import login_center_bg from '@/assets/images/login_center_bg.png' import login_center_bg from '@/assets/images/login_center_bg.png'
export default { export default {
@ -85,8 +89,8 @@
}; };
return { return {
loginForm: { loginForm: {
username: 'admin', username: '',
password: '123456', password: '',
}, },
loginRules: { loginRules: {
username: [{required: true, trigger: 'blur', validator: validateUsername}], username: [{required: true, trigger: 'blur', validator: validateUsername}],
@ -99,6 +103,16 @@
supportDialogVisible:false supportDialogVisible:false
} }
}, },
created() {
this.loginForm.username = getCookie("username");
this.loginForm.password = getCookie("password");
if(this.loginForm.username === undefined||this.loginForm.username==null||this.loginForm.username===''){
this.loginForm.username = 'admin';
}
if(this.loginForm.password === undefined||this.loginForm.password==null){
this.loginForm.password = '';
}
},
methods: { methods: {
showPwd() { showPwd() {
if (this.pwdType === 'password') { if (this.pwdType === 'password') {
@ -110,14 +124,16 @@
handleLogin() { handleLogin() {
this.$refs.loginForm.validate(valid => { this.$refs.loginForm.validate(valid => {
if (valid) { if (valid) {
let isSupport = getSupport(); // let isSupport = getSupport();
if(isSupport===undefined||isSupport==null){ // if(isSupport===undefined||isSupport==null){
this.dialogVisible =true; // this.dialogVisible =true;
return; // return;
} // }
this.loading = true; this.loading = true;
this.$store.dispatch('Login', this.loginForm).then(() => { this.$store.dispatch('Login', this.loginForm).then(() => {
this.loading = false; this.loading = false;
setCookie("username",this.loginForm.username,15);
setCookie("password",this.loginForm.password,15);
this.$router.push({path: '/'}) this.$router.push({path: '/'})
}).catch(() => { }).catch(() => {
this.loading = false this.loading = false
@ -128,6 +144,9 @@
} }
}) })
}, },
handleTry(){
this.dialogVisible =true
},
dialogConfirm(){ dialogConfirm(){
this.dialogVisible =false; this.dialogVisible =false;
setSupport(true); setSupport(true);