75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
// Pages/login/index.js
|
|
import { API } from './../../utils/network/api'
|
|
const api = new API()
|
|
const app = getApp()
|
|
Page({
|
|
data: {
|
|
navbarData: {
|
|
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
title: '登录', //导航栏 中间的标题
|
|
},
|
|
checked: false,
|
|
static_host: api.getStaticHost()
|
|
},
|
|
onLoad(){
|
|
let usertype = wx.getStorageSync('usertype');
|
|
if(!usertype){
|
|
wx.navigateTo({
|
|
url: "/Pages/index/index"
|
|
})
|
|
}
|
|
},
|
|
onChange(event) {
|
|
this.setData({
|
|
checked: event.detail,
|
|
});
|
|
},
|
|
_navback() {
|
|
wx.navigateBack()
|
|
},
|
|
go(e){
|
|
let url = e.currentTarget.dataset.url;
|
|
app.go(url);
|
|
},
|
|
getPhoneNumber (e) {
|
|
console.log(e);
|
|
console.log(e.detail.code);
|
|
if(!this.data.checked){
|
|
wx.showToast({
|
|
title: '请同意协议',
|
|
icon: "error"
|
|
})
|
|
return;
|
|
}
|
|
let usertype = wx.getStorageSync('usertype');
|
|
let next_url = wx.getStorageSync('next_url');
|
|
wx.login({
|
|
success (res) {
|
|
if (res.code) {
|
|
console.log('登录成功!' + res.errMsg)
|
|
var params = {
|
|
phone_code: e.detail.code,
|
|
user_type: usertype,
|
|
wx_code: res.code
|
|
}
|
|
api.wechatMobileLogin(params).then(response => {
|
|
console.log(response);
|
|
wx.setStorageSync('AUTH_TOKEN_'+usertype, response.data.token);
|
|
wx.setStorageSync('user_id_'+usertype, response.data.user_id);
|
|
wx.setStorageSync('client_user_id_'+usertype, response.data.client_user_id);
|
|
app.globalData.config.userID = response.data.user_id;
|
|
app.imInit();
|
|
//跳转页面
|
|
wx.switchTab({
|
|
url: next_url
|
|
})
|
|
}).catch(errors => {
|
|
console.error(errors);
|
|
})
|
|
} else {
|
|
console.log('登录失败!' + res.errMsg)
|
|
}
|
|
}
|
|
})
|
|
},
|
|
}) |