Browse Source

获取用户信息

feature/v1.1.0
lfs3 7 years ago
parent
commit
66bdd2a782
3 changed files with 74 additions and 6 deletions
  1. 3
      app.js
  2. 67
      pages/mcenter/mcenter.js
  3. 10
      pages/mcenter/mcenter.wxml

3
app.js

@ -1,7 +1,8 @@
//app.js //app.js
App({ App({
gw: { gw: {
hostUrl: 'https://www.1hjz.cn',
// hostUrl: 'https://www.1hjz.cn',
hostUrl: 'https://test.1hjz.cn/',
mapUrl:'https://api.map.baidu.com', mapUrl:'https://api.map.baidu.com',
systemInfo : null,//系统信息 systemInfo : null,//系统信息
}, },

67
pages/mcenter/mcenter.js

@ -45,6 +45,72 @@ Page({
}, },
onLoad: function () { onLoad: function () {
// this.setData({
// sessionId: wx.getStorageSync('sessionId')
// })
// let that = this;
// wx.request({
// url: app.gw.hostUrl + '/mall/wxa/user/baseinfo',
// data: {},
// header: {
// "Content-Type": "application/json",
// 'sessionId': wx.getStorageSync('sessionId')
// },
// method: 'GET',
// dataType: 'json',
// responseType: 'text',
// success: function (res) {
// var data = res.data;
// var status = data.code;
// if (status != 0) {
// wx.showToast({
// title: data.msg,
// icon: 'none',
// duration: 3000
// });
// return;
// }
// that.setData({
// items2: res.data.response
// })
// },
// fail: function (res) {
// wx.showToast({
// title: '网络异常!err:authlogin',
// icon: 'none',
// duration: 2000
// });
// },
// complete: function (res) { },
// })
// if (app.globalData.userInfo) {
// this.setData({
// userInfo: app.globalData.userInfo,
// hasUserInfo: true
// })
// } else if (this.data.canIUse) {
// // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// // 所以此处加入 callback 以防止这种情况
// app.userInfoReadyCallback = res => {
// this.setData({
// userInfo: res.userInfo,
// hasUserInfo: true
// })
// }
// } else {
// // 在没有 open-type=getUserInfo 版本的兼容处理
// wx.getUserInfo({
// success: res => {
// app.globalData.userInfo = res.userInfo
// this.setData({
// userInfo: res.userInfo,
// hasUserInfo: true
// })
// }
// })
// }
},
onShow: function(){
this.setData({ this.setData({
sessionId: wx.getStorageSync('sessionId') sessionId: wx.getStorageSync('sessionId')
}) })
@ -118,3 +184,4 @@ Page({
}) })
} }
}) })

10
pages/mcenter/mcenter.wxml

@ -1,5 +1,5 @@
<view class='user-msg' wx:if='{{sessionId}}'> <view class='user-msg' wx:if='{{sessionId}}'>
<view class="userinfo">
<view class="userinfo">
<image wx:if="{{imgUrl!=null}}" class="userinfo-avatar" src="{{imgUrl}}" background-size="cover"></image> <image wx:if="{{imgUrl!=null}}" class="userinfo-avatar" src="{{imgUrl}}" background-size="cover"></image>
<image wx:else class="userinfo-avatar" src="{{userInfo.avatarUrl!=undefined?userInfo.avatarUrl:items2.headUrl}}" background-size="cover"></image> <image wx:else class="userinfo-avatar" src="{{userInfo.avatarUrl!=undefined?userInfo.avatarUrl:items2.headUrl}}" background-size="cover"></image>
<view class='detail-msg'> <view class='detail-msg'>
@ -7,19 +7,19 @@
<view></view> <view></view>
<view></view> <view></view>
<!-- <view class="userinfo-nickname">微信号:zgq9577</view> --> <!-- <view class="userinfo-nickname">微信号:zgq9577</view> -->
<view class='userinfo-phone'>绑定手机:{{items2.mobile}}</view>
<view class='userinfo-phone'>绑定手机:{{items2.mobile}}</view>
</view> </view>
</view> </view>
</view> </view>
<view class='user-msg' wx:else> <view class='user-msg' wx:else>
<view class="userinfo">
<view class="userinfo">
<view class='loginText'>登录一号家政,实现高端保洁</view> <view class='loginText'>登录一号家政,实现高端保洁</view>
<button class='loginBtn' bindtap='goLogin'>登录/注册</button> <button class='loginBtn' bindtap='goLogin'>登录/注册</button>
</view> </view>
</view> </view>
<view wx:for-items="{{items}}" wx:key="page"> <view wx:for-items="{{items}}" wx:key="page">
<view class='box top{{item.top}}' bindtap='go{{item.page}}'> <view class='box top{{item.top}}' bindtap='go{{item.page}}'>
<image class="icon" src="{{item.img}}" mode='aspectFit'/>
<image class="icon" src="{{item.img}}" mode='aspectFit' />
<text class='text'>{{item.title}}</text> <text class='text'>{{item.title}}</text>
</view> </view>
</view>
</view>
Loading…
Cancel
Save