Commit 682e9879 by liangjianmin

js

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