eason před 1 rokem
rodič
revize
a0e970ad7d

+ 108 - 85
fore-end/app.js

@@ -12,100 +12,123 @@ App({
 		appSecret: '9e94011d65b0f4307b1cab14022ea060'
 	}
 const ui_w = 360;
-//把vid存到缓存
-wx.setStorage({
-	key: 'vid',
-	data: '',
-	success: function() {
-		console.log('写入vid缓存成功')
-	},
-	fail: function() {
-		console.log('写入vid发生错误')
-	}
-})
+	//把vid存到缓存
+	wx.setStorage({
+		key: 'vid',
+		data: '',
+		success: function() {
+			console.log('写入vid缓存成功')
+		},
+		fail: function() {
+			console.log('写入vid发生错误')
+		}
+	})
 // 获取屏幕的宽度
 var clientWidth = wx.getSystemInfoSync().windowWidth;
+	//检测缓存是否有token
+	// console.log(wx.getStorageSync('token'));
+	if(wx.getStorageSync('token') == ''){
 
-
-    // 登录
-    wx.login({
-      success: (res) => {
-		  //获取用户昵称和头像
-		
-		  //和微信接口服务校验
-		console.log("code: "+res.code);
-		var url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + wxInfo.appid + '&secret=' + wxInfo.appSecret + '&js_code=' + res.code + '&grant_type=authorization_code'
-		 wx.request({
-		  url: url,
-		  success(res){
-			wx.setStorageSync('vid', res.data.openid);
-			console.log(wx.getStorageSync('vid'));
-			wx.getUserProfile({
-				desc: '登录',
-				
-				success: (res) => {
-					wx.setStorageSync('nickName', res.userInfo.nickuName);
-					wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl);
-				}
-			  });
-			//登录
-			wx.request({
-				url: 'http://192.168.31.28:8084/user/login',
-				method:'POST',
-				header: {
-					'content-type': 'application/x-www-form-urlencoded'
-				},
-				data:{
-					vid: wx.getStorageSync('vid')
-				},
-				
+		console.log('token不存在');
+		// 登录
+		wx.login({
+			success: (res) => {
+				//获取用户昵称和头像
+			  
+				//和微信接口服务校验
+			  console.log("code: "+res.code);
+			  var url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + wxInfo.appid + '&secret=' + wxInfo.appSecret + '&js_code=' + res.code + '&grant_type=authorization_code'
+			   wx.request({
+				url: url,
 				success(res){
-					console.log(res);
-					var avatar = wx.getStorageSync('avatarUrl');
-					var name = wx.getStorageSync('nickName');
-					// console.log(vid);
-					console.log('vid: '+ wx.getStorageSync('vid'));
-					if(res.data.code == 403){
-						
-							wx.request({
-								url: 'http://192.168.31.28:8084/user/register',
-								method: 'POST',
-								data: {
-									avatar: avatar,
-									name: name,
-									vid: wx.getStorageSync('vid'),
-									phone: '',
-									sign: '',
-								},
-								success(res){
-								  console.log('注册成功');
-								  console.log(res);
+				  wx.setStorageSync('vid', res.data.openid);
+				  console.log(wx.getStorageSync('vid'));
+				  wx.getUserProfile({
+					  desc: '登录',
+					  
+					  success: (res) => {
+						  wx.setStorageSync('nickName', res.userInfo.nickuName);
+						  wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl);
+					  }
+					});
+				  //登录
+				  wx.request({
+					  url: 'http://192.168.31.28:8084/user/login',
+					  method:'POST',
+					  header: {
+						  'content-type': 'application/x-www-form-urlencoded'
+					  },
+					  data:{
+						  vid: wx.getStorageSync('vid')
+					  },
+					  
+					  success(res){
+						  console.log(res);
+						  wx.setStorageSync('token', res.data.data.token);
+						  var avatar = wx.getStorageSync('avatarUrl');
+						  var name = wx.getStorageSync('nickName');
+						  // console.log(vid);
+						  console.log('vid: '+ wx.getStorageSync('vid'));
+						  if(res.data.code == 403){
+							  
 								  wx.request({
-									url: 'http://192.168.31.28:8084/user/login',
-									method: 'POST',
-									header: {
-										'content-type': 'application/x-www-form-urlencoded'
-									},
-									data:{
-										vid: wx.getStorageSync('vid')
-									},
-									
-									success(res){
+									  url: 'http://192.168.31.28:8084/user/register',
+									  method: 'POST',
+									  data: {
+										  avatar: avatar,
+										  name: name,
+										  vid: wx.getStorageSync('vid'),
+										  phone: '',
+										  sign: '',
+									  },
+									  success(res){
+										console.log('注册成功');
 										console.log(res);
-									}
-								  })
-								}
-							  })
+										wx.navigateTo({
+										  url: '/pages/register/register',
+										})
+										wx.request({
+										  url: 'http://192.168.31.28:8084/user/login',
+										  method: 'POST',
+										  header: {
+											  'content-type': 'application/x-www-form-urlencoded'
+										  },
+										  data:{
+											  vid: wx.getStorageSync('vid')
+										  },
+										  
+										  success(res){
+											  wx.setStorageSync('token', res.data.data.token);
+										  }
+										})
+									  }
+									})
+					  }
+							  
+					  }
+				  })
 				}
-						
-				}
-			})
+			  })
+			  
+			  
+			}
+		  })
+	}else{
+		wx.request({
+		  url: 'http://192.168.31.28:8084/user/info',
+		  header:{
+			  "Authorization": wx.getStorageSync('token')
+		  },
+		  success(res){
+			  console.log(res);
+			  if(res.code == 200){
+				  console.log('token有效');
+			  }
 		  }
 		})
-		
-		
-      }
-    })
+	}
+
+    
   },
   globalData: {
     userInfo: null

+ 1 - 1
fore-end/app.json

@@ -49,7 +49,7 @@
                 "selectedIconPath": "/assets/tabBar_img/append-active.png"
             },
             {
-                "pagePath": "pages/message/message",
+                "pagePath": "pages/register/register",
                 "iconPath": "/assets/tabBar_img/message.png",
                 "selectedIconPath": "/assets/tabBar_img/message-active.png"
             },

+ 22 - 17
fore-end/pages/register/register.js

@@ -1,4 +1,6 @@
 // pages/register.js
+const app = getApp()
+
 const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
 Page({
 
@@ -6,15 +8,14 @@ Page({
      * 页面的初始数据
      */
     data: {
-
+		avatarUrl: defaultAvatarUrl,
+		theme: wx.getSystemInfoSync().theme,
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {
-
-    },
+	
 
     /**
      * 生命周期函数--监听页面初次渲染完成
@@ -66,16 +67,20 @@ Page({
 	},
 
 
-
-  data: {
-    avatarUrl: defaultAvatarUrl,
-  },
-  onChooseAvatar(e) {
-    const { avatarUrl } = e.detail 
-    this.setData({
-      avatarUrl,
-	})
-	bindonChooseAvatar
-  }
-
-})
+	
+	
+	 
+	  onLoad() {
+		wx.onThemeChange((result) => {
+		  this.setData({
+			theme: result.theme
+		  })
+		})
+	  },
+	  onChooseAvatar(e) {
+		const { avatarUrl } = e.detail 
+		this.setData({
+		  avatarUrl,
+		})
+	  }
+	})

+ 3 - 2
fore-end/pages/register/register.json

@@ -1,3 +1,4 @@
 {
-    "usingComponents": {}
-}
+	"usingComponents": {
+	}
+  }

+ 12 - 4
fore-end/pages/register/register.wxml

@@ -1,5 +1,13 @@
 <!--pages/register.wxml-->
-<button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
-  <image class="avatar" src="{{avatarUrl}}"></image>
-</button> 
-<input type="nickname" class="weui-input" placeholder="请输入昵称"/>
+<view data-weui-theme="{{theme}}">
+  <button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
+    <image class="avatar" src="{{avatarUrl}}"></image>
+  </button> 
+  <mp-form>
+    <mp-cells>
+      <mp-cell title="昵称">
+        <input type="nickname" class="weui-input" placeholder="请输入昵称"/>
+      </mp-cell>
+    </mp-cells>
+  </mp-form>
+</view>

+ 19 - 1
fore-end/pages/register/register.wxss

@@ -1 +1,19 @@
-/* pages/register.wxss */
+/* pages/register.wxss */
+.avatar-wrapper {
+	padding: 0;
+	width: 56px !important;
+	border-radius: 8px;
+	margin-top: 40px;
+	margin-bottom: 40px;
+  }
+  
+  .avatar {
+	display: block;
+	width: 56px;
+	height: 56px;
+  }
+  
+  .container {
+	display: flex;
+  }
+