登录
This commit is contained in:
		
							parent
							
								
									c3addc7383
								
							
						
					
					
						commit
						f51effaf09
					
				| @ -7,9 +7,41 @@ Page({ | |||||||
|    */ |    */ | ||||||
|   data: { |   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){ |   login(a){ | ||||||
|     console.log(a) |     console.log(a) | ||||||
|  |     let i = this | ||||||
|     wx.login({ |     wx.login({ | ||||||
|       success (res) { |       success (res) { | ||||||
|         if (res.code) { |         if (res.code) { | ||||||
| @ -21,6 +53,11 @@ Page({ | |||||||
|             } |             } | ||||||
|           }).then((res)=>{ |           }).then((res)=>{ | ||||||
|             console.log(res) |             console.log(res) | ||||||
|  |             wx.setStorageSync("openid",res.data.openid) | ||||||
|  |             i.getinfo(a) | ||||||
|  |             wx.switchTab({ | ||||||
|  |               url:"/pages/index/index" | ||||||
|  |             }) | ||||||
|           }) |           }) | ||||||
|         } else { |         } else { | ||||||
|           console.log('登录失败!' + res.errMsg) |           console.log('登录失败!' + res.errMsg) | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| // pages/personal/personal.js
 | // pages/personal/personal.js.
 | ||||||
|  | import {request} from "../../utils/bin" | ||||||
| Page({ | Page({ | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -13,9 +14,7 @@ Page({ | |||||||
|      * 生命周期函数--监听页面加载 |      * 生命周期函数--监听页面加载 | ||||||
|      */ |      */ | ||||||
|     onLoad: function(options) { |     onLoad: function(options) { | ||||||
|         this.setData({ |          | ||||||
|             openid:wx.getStorageSync("openid") |  | ||||||
|         }) |  | ||||||
|     }, |     }, | ||||||
|     toorder() { |     toorder() { | ||||||
|         wx.navigateTo({ |         wx.navigateTo({ | ||||||
| @ -57,6 +56,13 @@ Page({ | |||||||
|     /** |     /** | ||||||
|      * 生命周期函数--监听页面初次渲染完成 |      * 生命周期函数--监听页面初次渲染完成 | ||||||
|      */ |      */ | ||||||
|  |     login(){ | ||||||
|  |         if(this.data.openid == ""){ | ||||||
|  |             wx.navigateTo({ | ||||||
|  |                 url:"/pages/login/login" | ||||||
|  |             }) | ||||||
|  |         } | ||||||
|  |     }, | ||||||
|     onReady: function() { |     onReady: function() { | ||||||
| 
 | 
 | ||||||
|     }, |     }, | ||||||
| @ -65,7 +71,14 @@ Page({ | |||||||
|      * 生命周期函数--监听页面显示 |      * 生命周期函数--监听页面显示 | ||||||
|      */ |      */ | ||||||
|     onShow: function() { |     onShow: function() { | ||||||
| 
 |         this.setData({ | ||||||
|  |             openid:wx.getStorageSync("openid") | ||||||
|  |         }) | ||||||
|  |         request({ | ||||||
|  |             url:"User/validateOpenid" | ||||||
|  |         }).then((res)=>{ | ||||||
|  |             console.log(res) | ||||||
|  |         }) | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -16,6 +16,10 @@ let request = function (obj){ | |||||||
|         } |         } | ||||||
|         header['content-type'] = "application/x-www-form-urlencoded" |         header['content-type'] = "application/x-www-form-urlencoded" | ||||||
|     } |     } | ||||||
|  |     if(data == undefined){ | ||||||
|  |         data = {} | ||||||
|  |     } | ||||||
|  |     data.openid = wx.getStorageSync("openid") | ||||||
|     return new Promise((res,rej)=>{ |     return new Promise((res,rej)=>{ | ||||||
|         wx.request({ |         wx.request({ | ||||||
|             url, |             url, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user