Ver Fonte

前台修改

elis há 2 anos atrás
pai
commit
1fa99744c1

+ 6 - 5
nngkxxdp/src/main/java/com/example/nngkxxdp/program/service/Impl/MiniLoginServiceImpl.java

@@ -49,7 +49,7 @@ public class MiniLoginServiceImpl implements MiniLoginService {
      * 微信小程序登录接口
      *
      * @param code
-     * @param userInfo
+     *
      */
     @Override
     public Map<String, Object> login(String code, String phoneCode) {
@@ -83,11 +83,12 @@ public class MiniLoginServiceImpl implements MiniLoginService {
             }
             appletUserDao.add(appletUser);
 
-            // 华龙网参数请求
-            // 华龙网数据保存
-            // 生成token
             String token = MiniTokenUtil.generateToken(appletUser.getId(), appletUser.getNickName(), 60 * 24);
-            return SendUtil.send(true, "", token);
+            HashMap<String, Object> returnedValue = new HashMap<>(5);
+            returnedValue.put("nickName", appletUser.getNickName());
+            returnedValue.put("imgUrl", appletUser.getImgUrl());
+            returnedValue.put("token", token);
+            return SendUtil.send(true, "", returnedValue);
         } catch (Exception e) {
             e.printStackTrace();
             return SendUtil.send(false, "登陆失败");

+ 8 - 12
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/login/login.js

@@ -87,20 +87,16 @@ Page({
 			let data =  {
 				code: res.code,
 				phoneCode: phoneCode
-			};
-			login(data).then(res => {
-				console.log(res)
-				wx.setStorageSync("token", res.data.data)
-			})
-			// login(data).then(res=>{
-			// 	wx.showToast({
-			// 		title: '登陆成功',
-			// 	})
-			// 	wx.setStorageSync("userId", res.data.data)
+      };
+      wx.navigateBack({
+        delta: 1
+      });
+			// login(data).then(res => {
+			// 	wx.setStorageSync("token", res.data.data)
 			// 	wx.navigateBack({
-			// 		delta: 0
-			// 	})
+			// 		delta: 1
 			// 	});
+			// })
 		  } else {
 			console.log('登录失败!' + res.errMsg)
 		  }

+ 26 - 1
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/myCenter/myCenter.js

@@ -5,7 +5,10 @@ Page({
 	 * 页面的初始数据
 	 */
 	data: {
-
+    canIUseGetUserProfile:true,
+    nickName:"",
+    avatarUrl:"",
+    hasUserInfo:false
 	},
 	// 自定义函数
 	toCanteen: function (e) {
@@ -90,8 +93,30 @@ Page({
 		})
 	},
 	tologin(){
+		this.setData({
+			canIUseGetUserProfile : false
+		})
 		wx.navigateTo({
 		  url: '/pages/login/login',
 		})
+	},
+	getUserInfo(){
+    wx.getUserProfile({
+      desc: '获取用户信息',
+      success: (res) => {
+        this.setData({
+          nickName:res.userInfo.nickName,
+          avatarUrl:res.userInfo.avatarUrl
+        })
+        this.setData({
+          hasUserInfo:true
+        })
+        // wx.setStorageSync('nickname', res.userInfo.nickName);
+        // wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl);
+      },
+      fail(res) {
+        console.log("获取用户信息失败", res)
+      }
+    })
 	}
 })

+ 16 - 3
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/myCenter/myCenter.wxml

@@ -1,8 +1,21 @@
 <!--pages/myCenter/myCenter.wxml-->
 <view class="bg">
-	<view class="head-bg" bindtap="tologin">
-		<image src="../images/sculpture.png" alt="" class="headPortrait"></image>
-		<text>李四</text>
+	<view class="head-bg" >
+
+    
+    <block wx:if="{{!hasUserInfo}}">
+      <image src="../images/sculpture.png" alt=""  class="headPortrait"></image>
+      <text wx:if="{{canIUseGetUserProfile}}" bindtap="tologin">登陆/注册</text>
+      <button wx:else bindtap="getUserInfo">点击显示微信头像</button>
+    </block>
+    <block wx:else>
+      <image src="{{avatarUrl}}" alt="" class="headPortrait"></image>
+      <text>{{nickName}}</text>
+    </block>
+
+		<!-- <image src="../images/sculpture.png" alt="" class="headPortrait"></image>
+		<text wx:if="{{canIUseGetUserProfile}}">登陆/注册</text>
+		<button wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo">点击显示微信头像</button> -->
 	</view>
 	<view class="banner cont-width">
 		<view class="banner-nav">

+ 14 - 1
nngkxxdp/src/main/resources/static/nnzwminiapp/pages/myCenter/myCenter.wxss

@@ -20,13 +20,26 @@
 	height: 120rpx;
 	margin-left: 40rpx;
 }
-
 .head-bg text {
 	color: #fff;
 	font-size: 1.225rem;
 	margin-left: 0.9375rem;
 	font-weight: bold;
+	border:0;
+	background:transparent;
 }
+.head-bg button {
+	color: #fff;
+	font-size: 1.225rem;
+	margin-left: 0.9375rem;
+	font-weight: bold;
+	border:0;
+	background:transparent;
+}
+
+button::after {
+	border: none;
+  }
 
 .cont-width {
 	width: 92%;