Commit 682e9879 by liangjianmin

js

parent 3997be88
...@@ -32,15 +32,11 @@ export const http = (method, url, param) => { ...@@ -32,15 +32,11 @@ export const http = (method, url, param) => {
method: method, method: method,
transformRequest: [function (param) { transformRequest: [function (param) {
return qs.stringify(param); return qs.stringify(param);
}], }]
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
}; };
// post请求时需要设定Content-Type // post请求时需要设定Content-Type
if (method === 'post') { if (method === 'post') {
config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
config.data = param; config.data = param;
} else if (method === 'get') { } else if (method === 'get') {
config.params = param; config.params = param;
......
...@@ -22,45 +22,46 @@ Vue.use(directive); ...@@ -22,45 +22,46 @@ Vue.use(directive);
//处理顶部导航TAB //处理顶部导航TAB
router.afterEach((to, from, next) => { router.afterEach((to, from, next) => {
if(to.path=="/"){return} if (to.path == "/") {
let tabOldArr=sessionStorage.getItem('tabs'); return
}
let tabOldArr = sessionStorage.getItem('tabs');
let tabOldJson; let tabOldJson;
let tabNewJson=[]; let tabNewJson = [];
if(tabOldArr){ if (tabOldArr) {
tabOldJson=JSON.parse(tabOldArr); tabOldJson = JSON.parse(tabOldArr);
for(var i=0;i<tabOldJson.length;i++){ for (var i = 0; i < tabOldJson.length; i++) {
tabNewJson.push(JSON.stringify(tabOldJson[i])) tabNewJson.push(JSON.stringify(tabOldJson[i]))
} }
if(tabNewJson.indexOf(JSON.stringify({ if (tabNewJson.indexOf(JSON.stringify({
path:to.path, path: to.path,
title:to.meta.title title: to.meta.title
}))==-1){ })) == -1) {
tabOldJson.push({ tabOldJson.push({
path:to.path, path: to.path,
title:to.meta.title title: to.meta.title
}) })
} }
}else{ } else {
tabOldJson=[ tabOldJson = [
{ {
path:to.path, path: to.path,
title:to.meta.title title: to.meta.title
} }
] ]
} }
if(tabOldJson){ if (tabOldJson) {
sessionStorage.setItem('tabs', JSON.stringify(tabOldJson)); sessionStorage.setItem('tabs', JSON.stringify(tabOldJson));
} }
}); });
axios.interceptors.response.use(res => { axios.interceptors.response.use(res => {
return res; return res;
}, error => { }, error => {
console.log('error'); Message('网络出现问题,请检查网络');
return Promise.reject(new Error(error)) return Promise.reject(new Error(error))
}) })
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<div class="bar"> <div class="bar">
<div class="input-box lbBox"> <div class="input-box lbBox">
<i class="iconfont iconuser va-m"></i> <i class="iconfont iconuser va-m"></i>
<input type="text" placeholder="请输入手机号" class="inp va-m" v-model="form.username"/> <input type="text" placeholder="请输入手机号" class="inp va-m" v-model="form.mobile"/>
<b class="lineBlock emptys"></b> <b class="lineBlock emptys"></b>
</div> </div>
<div class="input-box lbBox"> <div class="input-box lbBox">
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
</div> </div>
<div class="code-box clr"> <div class="code-box clr">
<div class="fl l"> <div class="fl l">
<input type="text" placeholder="请输入验证码" v-model="form.code"/> <input type="text" placeholder="请输入验证码" v-model="form.captcha"/>
</div> </div>
<a class="fr r" href="javascript:;"> <a class="fr r" href="javascript:;" title="换一张" @click="updateCp()">
<img src="https://www.ichunt.com/v3/public/verify" alt=""> <img :src="imgSrc" alt="">
</a> </a>
</div> </div>
<p class="text"> <p class="text">
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</template> </template>
<script> <script>
import Vue from 'vue'; import Vue from 'vue';
import {Loading} from 'element-ui'; import {Loading, Message} from 'element-ui';
export default { export default {
name: "index", name: "index",
...@@ -62,10 +62,12 @@ ...@@ -62,10 +62,12 @@
status1: false, status1: false,
status2: false, status2: false,
loading: true, loading: true,
imgSrc: '',
form: { form: {
username: '', mobile: '',
password: '', password: '',
code: '' captcha: '',
captcha_key: ''
} }
}; };
}, },
...@@ -74,11 +76,11 @@ ...@@ -74,11 +76,11 @@
deep: true, deep: true,
handler: function (newV, oldV) { handler: function (newV, oldV) {
let obj = newV; let obj = newV;
if (obj.code || obj.password || obj.username) { if (obj.captcha || obj.password || obj.mobile) {
this.errror_text = ''; this.errror_text = '';
} }
if (obj.code && obj.password && obj.username) { if (obj.captcha && obj.password && obj.mobile) {
this.active = true; this.active = true;
} else { } else {
this.active = false; this.active = false;
...@@ -87,24 +89,29 @@ ...@@ -87,24 +89,29 @@
} }
}, },
created() { created() {
this.$http('get', "/auth/cp", {}).then(res => { this.updateCp();
console.log(res) Message('2121');
},
computed: {},
methods: {
updateCp() {
this.$http('get', "/auth/cp").then(res => {
this.imgSrc = res.data.data.url.img;
this.form.captcha_key = res.data.data.url.key;
}).catch(err => { }).catch(err => {
console.log(err.message); console.log(err.message);
}) })
}, },
computed: {},
methods: {
changePwd: function () { changePwd: function () {
this.pwdFlag = !this.pwdFlag; this.pwdFlag = !this.pwdFlag;
}, },
submit() { submit() {
var myreg = /^[1][3,4,5,7,8][0-9]{9}$/; var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
if (!this.form.username) { if (!this.form.mobile) {
this.errror_text = '请输入手机号'; this.errror_text = '请输入手机号';
return false; return false;
} }
if (!myreg.test(this.form.username)) { if (!myreg.test(this.form.mobile)) {
this.errror_text = '请输入正确的手机号'; this.errror_text = '请输入正确的手机号';
return false; return false;
} }
...@@ -113,7 +120,7 @@ ...@@ -113,7 +120,7 @@
this.errror_text = '请输入登录密码'; this.errror_text = '请输入登录密码';
return false; return false;
} }
if (!this.form.code) { if (!this.form.captcha) {
this.errror_text = '请输入验证码'; this.errror_text = '请输入验证码';
return false; return false;
} }
...@@ -122,9 +129,23 @@ ...@@ -122,9 +129,23 @@
background: 'rgba(0, 0, 0, 0)' background: 'rgba(0, 0, 0, 0)'
}); });
setTimeout(() => { this.$http('post', "/auth/login", {
mobile: this.form.mobile,
password: this.form.password,
captcha: this.form.captcha,
captcha_key: this.form.captcha_key
}).then(data => {
loadingInstance.close();
let res = data.data;
if (res.err_code === 0) {
} else {
Message(res.err_msg);
}
}).catch(err => {
loadingInstance.close(); loadingInstance.close();
}, 2000); });
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment