登录跳转首页功能实现
This commit is contained in:
parent
d5269a96d4
commit
1cd1f8d4ea
|
|
@ -83,55 +83,9 @@ const install = (Vue, vm) => {
|
|||
// // return res.result;
|
||||
// }
|
||||
if(res.code == 401) {
|
||||
// res为服务端返回值,可能有code,result等字段
|
||||
// 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
|
||||
// 如果配置了originalData为true,请留意这里的返回值
|
||||
|
||||
// return res.result;
|
||||
|
||||
uni.login({
|
||||
success: function(ret) {
|
||||
console.log("main.js==>res", ret)
|
||||
// vm.$u.post('/user/login',{"js_code": ret.code}).then(res=>{
|
||||
// if (res.code == 10003) {
|
||||
// // console.log("新用户登录")
|
||||
// uni.setStorageSync('token', res.data);
|
||||
|
||||
// } else if (res.code == 200) {
|
||||
// // console.log("老用户登录",res.data)
|
||||
// uni.setStorageSync('token', res.data);
|
||||
|
||||
// }
|
||||
// });
|
||||
}
|
||||
});
|
||||
wx.login({
|
||||
success(res) {
|
||||
if (res.code) {
|
||||
console.log('登录!', res);
|
||||
let data = {
|
||||
wxOpenId: res.code,
|
||||
|
||||
};
|
||||
vm.$u.post('/app/auth/wxLogin',data).then(res=>{
|
||||
if (res.code == 10003) {
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/login'
|
||||
})
|
||||
|
||||
} else if (res.code == 200) {
|
||||
// console.log("老用户登录",res.data)
|
||||
uni.switchTab({
|
||||
url:'/pages/index/index'
|
||||
})
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
uni.reLaunch({
|
||||
url:'/pages/login/login'
|
||||
})
|
||||
}
|
||||
return res;
|
||||
// else if(res.code == 201) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<u-navbar :is-back="false" :title="tittxt" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='36' >
|
||||
<u-navbar :is-back="false" :title="titleTxt" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='36' >
|
||||
|
||||
</u-navbar>
|
||||
<view class="imgbox">
|
||||
<image src="https://api.ccttiot.com/smartmeter/img/static/uGPwljIaEppyKAT1iQaW" mode=""></image>
|
||||
</view>
|
||||
<button class="button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" >
|
||||
<button class="button" @click="getPhoneNumber" >
|
||||
授权登录
|
||||
</button>
|
||||
<view class="tip">
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
bgc: {
|
||||
backgroundColor: "#fff",
|
||||
},
|
||||
tittxt:"登录",
|
||||
titleTxt:"登录",
|
||||
chooseType:true,
|
||||
usertype:'',
|
||||
login:false
|
||||
|
|
@ -33,51 +33,34 @@
|
|||
userType(num){
|
||||
this.chooseType=false
|
||||
this.login=true
|
||||
if(num==1){
|
||||
if(num===1){
|
||||
this.usertype='01'
|
||||
}else{
|
||||
this.usertype='00'
|
||||
}
|
||||
},
|
||||
getPhoneNumber(e) {
|
||||
getPhoneNumber() {
|
||||
let that = this;
|
||||
console.log("eeeeeeee", e);
|
||||
const wxLoginAsync = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
success(res) {
|
||||
if (res.code) {
|
||||
console.log('登录!', res);
|
||||
let data = {
|
||||
wxOpenId: res.code,
|
||||
userType: that.usertype,
|
||||
mobileCode: e.detail.code,
|
||||
};
|
||||
resolve(data);
|
||||
} else {
|
||||
reject(res.errMsg);
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
wxLoginAsync()
|
||||
.then(async (data) => {
|
||||
this.$u.post("/wxLogin",data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
console.log(res,'resres');
|
||||
wx.setStorageSync('token', res.token);
|
||||
that.ceshi()
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
wx.login({
|
||||
success(res) {
|
||||
if (res.code) {
|
||||
console.log('登录!', res);
|
||||
let data = {
|
||||
loginCode: res.code,
|
||||
appId:1,
|
||||
};
|
||||
that.$u.post("/wxLogin",data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
console.log(res,'resres');
|
||||
wx.setStorageSync('token', res.token);
|
||||
that.ceshi()
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
}
|
||||
});
|
||||
},
|
||||
async ceshi() {
|
||||
uni.switchTab({
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user