You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

81 lines
1.9 KiB

// components/login/login.js
const app = getApp();
const axios = require('../../api/index')
Component({
/**
* 组件的属性列表
*/
properties: {
is_show: {
type: Boolean,
value: false
}
},
/**
* 组件的初始数据
*/
data: {
// user_info: null
imageServerUrl: getApp().globalData.imageServerUrl,
},
/**
* 组件的方法列表
*/
methods: {
close() {
this.setData({
is_show: false
})
this.triggerEvent('close')
},
prevent() {},
//登录
getUserProfile() {
wx.getUserProfile({
desc: '记录用户信息',
success: res => {
let {
errMsg,
userInfo
} = res;
userInfo.id = '0';
if (errMsg == "getUserProfile:ok") {
wx.login({
success: e => {
let code = e.code;
wx.showLoading({
title: '正在登录...',
});
let data = {
jsCode: code,
wxUnifyUserAddInput: userInfo
}
axios.login(data).then(res => {
wx.setStorageSync('token', res.data);
wx.setStorageSync('loginUserInfo', userInfo)
this.get_user_info()
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
})
}
})
}
}
})
},
get_user_info() {
axios.getUser().then(res => {
console.log(res)
app.globalData.userInfo = res.data
wx.setStorageSync('userInfo', res.data)
let shareType = wx.getStorageSync('shareType'),
userId = wx.getStorageSync('userId')
if (shareType && userId) app.share_add_integral(shareType, userId)
this.close()
})
},
}
})