This commit is contained in:
pplokijuhyg 2019-12-19 14:18:09 +08:00
parent c3addc7383
commit f51effaf09
3 changed files with 59 additions and 5 deletions

View File

@ -7,9 +7,41 @@ Page({
*/
data: {
},
getinfo(a){
request({
url:"User/validateOpenid"
}).then((res)=>{
if(res.data.code == 400){
request({
url:"User/register",
data:{
country:"",
gender:0,
nick_name:a.detail.userInfo.nickName,
province:"",
city:"",
head_pic:a.detail.userInfo.avatarUrl,
open_id: wx.getStorageSync("openid"),
}
}).then((res)=>{
if(res.data.code == 200){
wx.switchTab({
url:"/pages/index/index"
})
}
})
}else{
wx.switchTab({
url:"/pages/index/index"
})
}
})
},
login(a){
console.log(a)
let i = this
wx.login({
success (res) {
if (res.code) {
@ -21,6 +53,11 @@ Page({
}
}).then((res)=>{
console.log(res)
wx.setStorageSync("openid",res.data.openid)
i.getinfo(a)
wx.switchTab({
url:"/pages/index/index"
})
})
} else {
console.log('登录失败!' + res.errMsg)

View File

@ -1,4 +1,5 @@
// pages/personal/personal.js
// pages/personal/personal.js.
import {request} from "../../utils/bin"
Page({
/**
@ -13,9 +14,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.setData({
openid:wx.getStorageSync("openid")
})
},
toorder() {
wx.navigateTo({
@ -57,6 +56,13 @@ Page({
/**
* 生命周期函数--监听页面初次渲染完成
*/
login(){
if(this.data.openid == ""){
wx.navigateTo({
url:"/pages/login/login"
})
}
},
onReady: function() {
},
@ -65,7 +71,14 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function() {
this.setData({
openid:wx.getStorageSync("openid")
})
request({
url:"User/validateOpenid"
}).then((res)=>{
console.log(res)
})
},
/**

View File

@ -16,6 +16,10 @@ let request = function (obj){
}
header['content-type'] = "application/x-www-form-urlencoded"
}
if(data == undefined){
data = {}
}
data.openid = wx.getStorageSync("openid")
return new Promise((res,rej)=>{
wx.request({
url,