Commit 0b375fde by 姜雷

添加微信登录

parent f2214756
...@@ -178,6 +178,52 @@ Page({ ...@@ -178,6 +178,52 @@ Page({
// url: '/pages/home/home' // url: '/pages/home/home'
// }) // })
}, },
codeLogin() {
wx.login({
success: res => {
if (res.code) {
const code = res.code;
systemFetch({
url: '/boss/login',
method: 'POST',
data: {
code,
},
})
.then(res => {
console.log(res);
const {
token,
data: { userInfo, userRoles },
} = res;
app.globalData.token = token;
app.globalData.userInfo = userInfo;
app.globalData.userRoles = userRoles;
try {
wx.setStorageSync('token', token);
} catch (error) {}
wx.hideLoading();
wx.redirectTo({
url: '/pages/homeAndReport/homeAndReport',
});
})
.catch(err => {
console.log(err);
wx.hideLoading();
wx.showToast({
title: err.errMsg,
icon: 'none',
});
});
} else {
wx.showToast({
title: '登录获取code失败',
icon: 'none',
});
}
},
});
},
nameInputHandle(e) { nameInputHandle(e) {
const value = e.detail.value; const value = e.detail.value;
this.updateInputValue('account', value); this.updateInputValue('account', value);
......
...@@ -11,5 +11,8 @@ ...@@ -11,5 +11,8 @@
</div> </div>
</view> </view>
<button class="login-btn" bindtap="loginHandle">登录</button> <button class="login-btn" bindtap="loginHandle">登录</button>
<view class="wx-login" bind:tap="codeLogin">
<image class="wx-login-icon" src="../../images/ic_wechat@2x.png"></image>
</view>
</view> </view>
</view> </view>
\ No newline at end of file
...@@ -39,3 +39,12 @@ ...@@ -39,3 +39,12 @@
.login-btn { .login-btn {
margin-top: 40rpx; margin-top: 40rpx;
} }
.wx-login {
width: 72rpx;
height: 72rpx;
margin: 80rpx auto 0;
}
.wx-login-icon {
width: 72rpx;
height: 72rpx;
}
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 to comment