This commit is contained in:
Pan
2017-04-18 15:09:13 +08:00
parent 304b17520c
commit d10370086e
145 changed files with 61322 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<script>
export default {
name: 'authredirect',
created() {
const hash = window.location.search.slice(1);
window.opener.location.href = window.location.origin + '/login#' + hash;
window.close();
}
}
</script>

188
src/views/login/index.vue Normal file
View File

@@ -0,0 +1,188 @@
<template>
<div class="login-container">
<el-form autoComplete="on" :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left"
label-width="0px"
class="card-box login-form">
<h3 class="title">系统登录</h3>
<el-form-item prop="email">
<span class="svg-container"><wscn-icon-svg icon-class="jiedianyoujian"/></span>
<el-input name="email" type="text" v-model="loginForm.email" autoComplete="on"
placeholder="邮箱"></el-input>
</el-form-item>
<el-form-item prop="password">
<span class="svg-container"><wscn-icon-svg icon-class="mima"/></span>
<el-input name="password" type="password" @keyup.enter.native="handleLogin" v-model="loginForm.password"
autoComplete="on" placeholder="密码"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" style="width:100%;" :loading="loading" @click.native.prevent="handleLogin">
登录
</el-button>
</el-form-item>
<router-link to="/sendpwd" class="forget-pwd">
忘记密码?(或首次登录)
</router-link>
</el-form>
<el-dialog title="第三方验证" v-model="showDialog">
邮箱登录成功,请选择第三方验证
<socialSign></socialSign>
</el-dialog>
</div>
</template>
<script>
import { mapGetters } from 'vuex';
import { isWscnEmail } from 'utils/validate';
import { getQueryObject } from 'utils';
import socialSign from './socialsignin';
export default {
components: { socialSign },
name: 'login',
data() {
const validateEmail = (rule, value, callback) => {
if (!isWscnEmail(value)) {
callback(new Error('请输入正确的合法邮箱'));
} else {
callback();
}
};
const validatePass = (rule, value, callback) => {
if (value.length < 6) {
callback(new Error('密码不能小于6位'));
} else {
callback();
}
};
return {
loginForm: {
email: '',
password: ''
},
loginRules: {
email: [
{ required: true, trigger: 'blur', validator: validateEmail }
],
password: [
{ required: true, trigger: 'blur', validator: validatePass }
]
},
loading: false,
showDialog: false
}
},
computed: {
...mapGetters([
'status',
'auth_type'
])
},
methods: {
handleLogin() {
this.$refs.loginForm.validate(valid => {
if (valid) {
this.loading = true;
this.$store.dispatch('LoginByEmail', this.loginForm).then(() => {
this.loading = false;
this.$router.push({ path: '/' });
// this.showDialog = true;
}).catch(err => {
this.$message.error(err);
this.loading = false;
});
} else {
console.log('error submit!!');
return false;
}
});
},
afterQRScan() {
const hash = window.location.hash.slice(1);
const hashObj = getQueryObject(hash);
const originUrl = window.location.origin;
history.replaceState({}, '', originUrl);
const codeMap = {
wechat: 'code',
tencent: 'code'
};
const codeName = hashObj[codeMap[this.auth_type]];
if (!codeName) {
alert('第三方登录失败');
} else {
this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
this.$router.push({ path: '/' });
});
}
}
},
created() {
window.addEventListener('hashchange', this.afterQRScan);
},
destroyed() {
window.removeEventListener('hashchange', this.afterQRScan);
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoprd>
@import "src/styles/mixin.scss";
.login-container {
@include relative;
height: 100vh;
background-color: #2d3a4b;
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
-webkit-text-fill-color: #fff !important;
}
input {
background: transparent;
border: 0px;
-webkit-appearance: none;
border-radius: 0px;
padding: 12px 5px 12px 15px;
color: #eeeeee;
height: 47px;
}
.el-input {
display: inline-block;
height: 47px;
width: 85%;
}
.svg-container {
padding: 6px 5px 6px 15px;
color: #889aa4;
}
.title {
font-size: 26px;
font-weight: 400;
color: #eeeeee;
margin: 0px auto 40px auto;
text-align: center;
font-weight: bold;
}
.login-form {
position: absolute;
left: 0;
right: 0;
width: 400px;
padding: 35px 35px 15px 35px;
margin: 120px auto;
}
.el-form-item {
border: 1px solid rgba(255, 255, 255, 0.1);
background: rgba(0, 0, 0, 0.1);
border-radius: 5px;
color: #454545;
}
.forget-pwd {
color: #fff;
}
}
</style>

178
src/views/login/reset.vue Normal file
View File

@@ -0,0 +1,178 @@
<template>
<div class="reset-container">
<el-form autoComplete="on" :model="resetForm" :rules="resetRules" ref="resetForm" label-position="left"
label-width="0px"
class="card-box reset-form">
<div>
<router-link to="/login" class="back-icon">
<i class="el-icon-arrow-left"></i>
</router-link>
<h3 class="title">重设密码</h3>
</div>
<el-form-item prop="email">
<el-input name="email" type="text" v-model="resetForm.email"
placeholder="邮箱"></el-input>
</el-form-item>
<el-form-item prop="code">
<el-input name="code" type="text" v-model="resetForm.code"
placeholder="验证码"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input name="password" :type="passwordType" v-model="resetForm.password"
placeholder="密码"></el-input>
</el-form-item>
<el-form-item prop="checkPass">
<el-input name="checkPass" :type="passwordType"
v-model="resetForm.checkPass"
placeholder="确认密码"></el-input>
<i @click="togglePasswordType" class="el-icon-information"></i>
</el-form-item>
<el-form-item style="width:100%;">
<el-button type="primary" style="width:100%;" :loading="loading" @click.native.prevent="setPWD">
修改密码
</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
import { isWscnEmail } from 'utils/validate';
// import { restPWD } from 'api/login';
export default {
name: 'reset',
data() {
const validateEmail = (rule, value, callback) => {
if (!isWscnEmail(value)) {
callback(new Error('邮箱错误'));
} else {
callback();
}
};
const validaePass = (rule, value, callback) => {
if (value.length < 6) {
callback(new Error('密码不能小于6位'));
} else {
callback();
}
};
const validatePass2 = (rule, value, callback) => {
if (value === '') {
callback(new Error('请再次输入密码'));
} else if (value !== this.resetForm.password) {
callback(new Error('两次输入密码不一致!'));
} else {
callback();
}
};
return {
resetForm: {
email: '',
password: '',
checkPass: '',
code: ''
},
passwordType: 'password',
resetRules: {
email: [
{ required: true, trigger: 'blur', validator: validateEmail }
],
password: [
{ required: true, trigger: 'blur', validator: validaePass }
],
checkPass: [
{ required: true, trigger: 'blur', validator: validatePass2 }
],
code: [
{ required: true, message: '必填项', trigger: 'blur' }
]
},
loading: false
}
},
methods: {
setPWD() {
this.loading = true;
const _this = this;
this.$refs.resetForm.validate(valid => {
if (valid) {
const data = {
email: this.resetForm.email,
code: this.resetForm.code,
new_password: this.resetForm.checkPass
};
// restPWD(data).then(() => {
// this.$message.success('密码设置成功,五秒后调整到登录页');
// setTimeout(() => {
// _this.$router.push({ path: '/login' })
// }, 5 * 1000)
// });
} else {
this.$message.error('error submit!!');
}
this.loading = false;
});
},
togglePasswordType() {
if (this.passwordType === 'text') {
this.passwordType = 'password'
} else {
this.passwordType = 'text'
}
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss">
@import "src/styles/mixin.scss";
.reset-container {
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
-webkit-text-fill-color: #3E3E3E !important;
}
@include relative;
height: 100vh;
background-color: #324057;
.back-icon {
float: left;
margin-top: 5px;
}
.el-icon-information {
position: absolute;
right: -18px;
top: 10px;
}
.reset-form {
position: absolute;
left: 0;
right: 0;
width: 350px;
padding: 35px 35px 15px 35px;
margin: 120px auto;
}
.card-box {
padding: 20px;
box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-border-radius: 5px;
background-clip: padding-box;
margin-bottom: 20px;
background-color: #F9FAFC;
width: 400px;
border: 2px solid #8492A6;
}
.title {
margin: 0px auto 40px auto;
text-align: center;
color: #505458;
}
}
</style>

117
src/views/login/sendpwd.vue Normal file
View File

@@ -0,0 +1,117 @@
<template>
<div class="sendpwd-container">
<el-form autoComplete="on" :model="resetForm" :rules="resetRules" ref="resetForm" label-position="left"
label-width="0px"
class="card-box reset-form">
<div>
<router-link to="/login" class="back-icon">
<i class="el-icon-arrow-left"></i>
</router-link>
<h3 class="title">发送验证码至邮箱</h3>
</div>
<el-form-item prop="email">
<el-input name="email" type="text" v-model="resetForm.email"
placeholder="邮箱"></el-input>
</el-form-item>
<el-form-item style="width:100%;">
<el-button type="primary" style="width:100%;" :loading="loading" @click.native.prevent="handleSendPWD">
发送验证码至邮箱
</el-button>
</el-form-item>
<router-link to="/reset">
<el-button type="info" style="width:100%;">
已收到验证码,去重设密码
</el-button>
</router-link>
</el-form>
</div>
</template>
<script>
import { isWscnEmail } from 'utils/validate';
// import { sendPWD2Email } from 'api/login';
export default {
name: 'reset',
data() {
const validateEmail = (rule, value, callback) => {
if (!isWscnEmail(value)) {
callback(new Error('请输入正确的邮箱'));
} else {
callback();
}
};
return {
resetForm: {
email: ''
},
resetRules: {
email: [
{ required: true, trigger: 'blur' },
{ validator: validateEmail }
]
},
loading: false
}
},
methods: {
handleSendPWD() {
this.loading = true;
this.$refs.resetForm.validate(valid => {
if (valid) {
// sendPWD2Email(this.resetForm.email).then(() => {
// this.$message.success('密码有发送至邮箱,请查收')
// });
} else {
this.$message.error('错误提交!!');
}
this.loading = false;
});
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss">
.sendpwd-container {
height: 100vh;
background-color: #2d3a4b;
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0px 1000px #293444 inset !important;
-webkit-text-fill-color: #3E3E3E !important;
}
.back-icon{
float: left;
margin-top: 5px;
}
.reset-form {
position: absolute;
left: 0;
right: 0;
width: 350px;
padding: 35px 35px 15px 35px;
margin: 120px auto;
}
.card-box {
padding: 20px;
box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-border-radius: 5px;
background-clip: padding-box;
margin-bottom: 20px;
background-color: #F9FAFC;
width: 400px;
border: 2px solid #8492A6;
}
.title {
margin: 0px auto 40px auto;
text-align: center;
color: #505458;
}
}
</style>

View File

@@ -0,0 +1,68 @@
<template>
<div class="social-signup-container">
<div class="sign-btn" @click="wechatHandleClick('wechat')">
<span class="wx-svg-container"><wscn-icon-svg icon-class="weixin" class="icon"/></span>
微信
</div>
<div class="sign-btn" @click="tencentHandleClick('tencent')">
<span class="qq-svg-container"><wscn-icon-svg icon-class="QQ" class="icon"/></span>
QQ
</div>
</div>
</template>
<script>
import openWindow from 'utils/openWindow';
export default {
name: 'social-signin',
methods: {
wechatHandleClick(thirdpart) {
this.$store.commit('SET_AUTH_TYPE', thirdpart);
const appid = 'wxff5aaaad72308d46';
const redirect_uri = encodeURIComponent('http://wallstreetcn.com/auth/redirect?redirect=' + window.location.origin + '/authredirect');
const url = 'https://open.weixin.qq.com/connect/qrconnect?appid=' + appid + '&redirect_uri=' + redirect_uri + '&response_type=code&scope=snsapi_login#wechat_redirect';
openWindow(url, thirdpart, 540, 540);
},
tencentHandleClick(thirdpart) {
this.$store.commit('SET_AUTH_TYPE', thirdpart);
const client_id = '101150108';
const redirect_uri = encodeURIComponent('http://wallstreetcn.com/auth/redirect?redirect=' + window.location.origin + '/authredirect');
const url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=' + client_id + '&redirect_uri=' + redirect_uri;
openWindow(url, thirdpart, 540, 540);
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.social-signup-container {
margin: 20px 0;
.sign-btn {
display: inline-block;
cursor: pointer;
}
.icon {
color: #fff;
font-size: 30px;
margin-top: 6px;
}
.wx-svg-container, .qq-svg-container {
display: inline-block;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
padding-top: 1px;
border-radius: 4px;
margin-bottom: 20px;
margin-right: 5px;
}
.wx-svg-container {
background-color: #8dc349;
}
.qq-svg-container {
background-color: #6BA2D6;
margin-left: 50px;
}
}
</style>