|
@@ -24,6 +24,8 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
|
+import getUrlParams from "./../../../utils/getUrlParams.js";
|
|
|
|
+import { config } from '@/common/config.js';
|
|
export default {
|
|
export default {
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
@@ -33,7 +35,7 @@ export default {
|
|
messageDisable: false,
|
|
messageDisable: false,
|
|
codelength: 4,
|
|
codelength: 4,
|
|
show: false,
|
|
show: false,
|
|
- second:10,
|
|
|
|
|
|
+ second:60,
|
|
toastMsg:'',
|
|
toastMsg:'',
|
|
toastUrl:'',
|
|
toastUrl:'',
|
|
toastType:'',
|
|
toastType:'',
|
|
@@ -85,7 +87,7 @@ export default {
|
|
// this.messageError = true;
|
|
// this.messageError = true;
|
|
}
|
|
}
|
|
clearInterval(interval);
|
|
clearInterval(interval);
|
|
- that.second=10;
|
|
|
|
|
|
+ that.second=60;
|
|
}
|
|
}
|
|
}, 1000);
|
|
}, 1000);
|
|
console.log('getcode res',res);
|
|
console.log('getcode res',res);
|
|
@@ -123,24 +125,13 @@ export default {
|
|
userId:this.userId,
|
|
userId:this.userId,
|
|
code:value
|
|
code:value
|
|
};
|
|
};
|
|
- console.log('params',params);
|
|
|
|
this.$u.api.phoneLoginAuth(params)
|
|
this.$u.api.phoneLoginAuth(params)
|
|
.then(res =>{
|
|
.then(res =>{
|
|
if(res.code=='200'){
|
|
if(res.code=='200'){
|
|
// console.log('finish res',res);
|
|
// console.log('finish res',res);
|
|
this.$u.vuex('vuex_user', res.data);
|
|
this.$u.vuex('vuex_user', res.data);
|
|
this.$u.vuex('vuex_hasLogin', true);
|
|
this.$u.vuex('vuex_hasLogin', true);
|
|
- let storage = window.sessionStorage;
|
|
|
|
- let backUrl = storage.getItem('backUrl');
|
|
|
|
- let switchTabList = ['/pages/use/use'];
|
|
|
|
- if(switchTabList.includes(res.data)){}
|
|
|
|
- console.log('backUrl',backUrl);
|
|
|
|
- const local = window.location.href
|
|
|
|
- if (backUrl) {
|
|
|
|
- location.href = backUrl;
|
|
|
|
- } else {
|
|
|
|
- location.href = 'http://h5.pdzhtc.com/'
|
|
|
|
- }
|
|
|
|
|
|
+ this.wechatLogin()
|
|
// location.href = backUrl;
|
|
// location.href = backUrl;
|
|
// this.$refs.uToast.show({
|
|
// this.$refs.uToast.show({
|
|
// title: '操作成功',
|
|
// title: '操作成功',
|
|
@@ -173,7 +164,51 @@ export default {
|
|
this.toastMsg = err.msg;
|
|
this.toastMsg = err.msg;
|
|
this.showToast();
|
|
this.showToast();
|
|
});
|
|
});
|
|
- }
|
|
|
|
|
|
+ },
|
|
|
|
+ // 微信登录
|
|
|
|
+ wechatLogin() {
|
|
|
|
+ const openId = this.$store.state.vuex_wxinfo.openId
|
|
|
|
+ if (openId) {
|
|
|
|
+ this.jumpIndex()
|
|
|
|
+ } else {
|
|
|
|
+ this.getCode()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 微信已登录则跳转到首页
|
|
|
|
+ jumpIndex() {
|
|
|
|
+ let storage = window.sessionStorage;
|
|
|
|
+ let backUrl = storage.getItem('backUrl');
|
|
|
|
+ if (backUrl) {
|
|
|
|
+ location.href = backUrl;
|
|
|
|
+ } else {
|
|
|
|
+ location.href = config.jumpHomeUrl
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 获取code
|
|
|
|
+ getCode () {
|
|
|
|
+ var local = window.location.href // 获取页面url
|
|
|
|
+ let locationLocaturl = window.location.search;
|
|
|
|
+ this.code = getUrlParams(locationLocaturl,"code"); // 截取code
|
|
|
|
+ if (this.code == null || this.code === '') { // 如果没有code,则去请求
|
|
|
|
+ window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.config.wxAppid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&#wechat_redirect`
|
|
|
|
+ } else {
|
|
|
|
+ this.handleGetWXInfo(this.code) //把code传给后台获取用户信息
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
|
|
|
|
+ handleGetWXInfo (code) {
|
|
|
|
+ this.$u.api.getWXInfo(code).then((res) => {
|
|
|
|
+ if (res.code === 200 ) {
|
|
|
|
+ this.$u.vuex('vuex_wxinfo', res.data);
|
|
|
|
+ this.jumpIndex()
|
|
|
|
+ }
|
|
|
|
+ }).catch((err) => {
|
|
|
|
+ this.$refs.uToast.show({
|
|
|
|
+ title: err.msg,
|
|
|
|
+ type: 'error',
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ },
|
|
}
|
|
}
|
|
};
|
|
};
|
|
</script>
|
|
</script>
|