Commit f8805346d0ba7af8980b65504734b6ac0c8bbb8c

Authored by luoye
1 parent 92fd0e4f51

首页

Showing 2 changed files with 79 additions and 46 deletions

littleApp_child/pages/home/home.js View file @ f880534
... ... @@ -17,6 +17,11 @@
17 17 var timer;
18 18 var phone;
19 19 var name;
  20 +// 用户信息的缓存
  21 +var babyCache = ['','']
  22 + // 文章的缓存
  23 +var artCache = ['','']
  24 +
20 25 Page({
21 26 /*---------属性变量--------*/
22 27 data: {
23 28  
24 29  
25 30  
... ... @@ -29,41 +34,36 @@
29 34 list:[],
30 35 userInfo:'',
31 36 inputFocus: { nameInput: false, phoneInput: false, codeInput: false },
32   - currentBabyIndex:0
  37 + currentBabyIndex:0,
  38 + babys:[]
33 39 },
34 40 /*---------生命周期--------*/
35 41 onLoad: function () {
36 42 this.calculatePageSize()
37   - var isFirst = wx.getStorageSync('isFirst')
38   - // 网络监听
39   - this.networkStatusChange()
40   - if (!isFirst) {
41   - wx.setStorageSync('isFirst', 'isFirst')
42   - this.welcomePage()
43   - } else {
44   - if (app.globalData.token == null || app.globalData.token == '') {
45   - this.toLogin()
  43 + // 网络监听
  44 + this.networkStatusChange()
  45 + if (app.globalData.token == null || app.globalData.token == '') {
  46 + this.welcomePage()
  47 + } else {
  48 +
  49 + this.homePage()
  50 + // 监听事件
  51 + event.on('likeChanged', this, function (data) {
  52 + if (data.categoryIndex == -1) {
  53 + var artList = this.data.crisisCategorie
  54 + artList[data.articleIdIndex].likeCount++
  55 + this.setData({
  56 + crisisCategorie: artList
  57 + });
46 58 } else {
47   -
48   - this.homePage()
49   - // 监听事件
50   - event.on('likeChanged', this, function (data) {
51   - if (data.categoryIndex == -1) {
52   - var artList = this.data.crisisCategorie
53   - artList[data.articleIdIndex].likeCount++
54   - this.setData({
55   - crisisCategorie: artList
56   - });
57   - } else {
58   - var artList = this.data.articleList
59   - artList[data.categoryIndex].article[data.articleIdIndex].likeCount++
60   - this.setData({
61   - articleList: artList
62   - });
63   - }
64   - })
  59 + var artList = this.data.articleList
  60 + artList[data.categoryIndex].article[data.articleIdIndex].likeCount++
  61 + this.setData({
  62 + articleList: artList
  63 + });
65 64 }
66   - }
  65 + })
  66 + }
67 67 },
68 68 onUnload: function () {
69 69 // 移除监听
70 70  
71 71  
... ... @@ -142,17 +142,20 @@
142 142 },
143 143 // 改变baby
144 144 changeBaby(e){
145   -
146 145 this.setData({
147 146 currentBabyIndex: e.currentTarget.dataset.index
148 147 })
  148 + this.setUserInfo(babyCache[e.currentTarget.dataset.index])
  149 + this.setArtInfo(artCache[e.currentTarget.dataset.index])
149 150 },
150 151 /*---------自定义函数--------*/
151 152 homePage() {
152 153 var that = this
153 154 this.requestHomeInfo()
154 155 that.setData({
155   - pageType: 2
  156 + pageType: 2,
  157 + // babys: [1,2]
  158 + babys: app.globalData.userId
156 159 })
157 160 },
158 161 toLogin() {
159 162  
... ... @@ -195,12 +198,9 @@
195 198 var param = { 'token': app.globalData.token }
196 199 networkUtil._get(api.userInfo + app.globalData.currentId, {}, function (res) {
197 200 console.log('获取用户信息',res)
198   - app.globalData.days = res.data.data.days
199   - app.globalData.userInfo = res.data.data
200 201 self.getArticleInfo(res.data.data.days)
201   - self.setData({
202   - userData: res.data.data
203   - })
  202 + self.setUserInfo(res.data.data)
  203 + babyCache[self.data.currentBabyIndex] = res.data.data
204 204 }, function (res) {
205 205 networkUtil.showErrorToast(res.errormsg)
206 206 })
207 207  
... ... @@ -210,14 +210,29 @@
210 210 // 文章列表
211 211 networkUtil._get(api.homeArtList, { page: 0, limit: 100, days: days }, function (res) {
212 212 console.log('获取文章信息', res.data.list)
213   - app.globalData.artList = res.data.list
214   - self.setData({
215   - list: res.data.list
216   - })
  213 + artCache[self.data.currentBabyIndex] = res.data.list
  214 + self.setArtInfo(res.data.list)
217 215 }, function (res) {
218 216 wx.stopPullDownRefresh()
219 217 })
220 218 },
  219 + // 设置UI 用户信息
  220 + setUserInfo(data){
  221 + var self = this
  222 + app.globalData.days = data.days
  223 + app.globalData.userInfo = data
  224 + self.setData({
  225 + userData: data
  226 + })
  227 + },
  228 + // 设置UI 文章信息
  229 + setArtInfo(list) {
  230 + var self = this
  231 + app.globalData.artList = list
  232 + self.setData({
  233 + list: list
  234 + })
  235 + },
221 236 // 文章点赞
222 237 articleLike(e) {
223 238 console.log(e)
... ... @@ -271,7 +286,23 @@
271 286 that.setData({
272 287 time: '0s'
273 288 })
274   - networkUtil.showErrorToast(res.errormsg)
  289 + if (res.errorcode == 4003) {
  290 + wx.showModal({
  291 + title: '提示',
  292 + content: '您还没有在医院建档,是否立即使用游客身份注册',
  293 + success: function (res) {
  294 + if (res.confirm) {
  295 + wx.navigateTo({
  296 + url: '../Register/Register',
  297 + })
  298 + } else if (res.cancel) {
  299 + console.log('用户点击取消')
  300 + }
  301 + }
  302 + })
  303 + } else {
  304 + networkUtil.showErrorToast(res.errormsg)
  305 + }
275 306 })
276 307 if (timeCount == 60) {
277 308 this.keepTime()
littleApp_child/pages/home/home.wxml View file @ f880534
... ... @@ -11,13 +11,16 @@
11 11 <!--头像-->
12 12 <image class="avatar" bindtap="tapAvatar" src="{{userData.avatar.medium ? userData.avatar.medium : ''}}" background-size="cover"></image>
13 13 <!--用户名-->
14   - <view class="top_name">
  14 + <view class="top_name" wx:if="{{babys.length > 1}}">
15 15 <view class="userName {{currentBabyIndex == 0 ? 'userName_selected' : ''}}" data-index="0" bindtap="changeBaby">{{userData.username}}</view>
16 16 <view class="top_name_line"></view>
17   - <view class="userName {{currentBabyIndex == 1 ? 'userName_selected' : ''}}" data-index="1" bindtap="changeBaby">{{userData.username}}</view>
  17 + <view class="userName {{currentBabyIndex == 1 ? 'userName_selected' : ''}}" data-index="1" bindtap="changeBaby">儿童2</view>
18 18 </view>
  19 + <view class="top_name" wx:if="{{babys.length < 2}}">
  20 + <view class="userName" data-index="0">{{userData.username}}</view>
  21 + </view>
19 22 <!--下方黑色横条-->
20   - <view class="infoBar">
  23 + <view class="infoBar" wx:if="">
21 24 <view class="infoView">
22 25 <text class="titleText">出生日期</text>
23 26 <text class="timeText">{{userData.birth}}</text>
... ... @@ -135,7 +138,7 @@
135 138 </view>
136 139  
137 140 <button class="we_button" bindtap="toLogin">身份验证</button>
138   -
  141 + <view class="we_button" bindtap="toRegister">游客注册</view>
139 142 </view>
140 143  
141 144 <!-- 登录 -->
... ... @@ -162,7 +165,6 @@
162 165 </view>
163 166  
164 167 </view>
165   - <view class="we_button" bindtap="toRegister">游客注册</view>
166 168 <button class="record-submit-btn" formType="submit">确认</button>
167 169 </form>
168 170 </view>