From 8f0ecaa5a1cf2dba34de0e267d6db053e8772688 Mon Sep 17 00:00:00 2001 From: luoye <397379429@qq.com> Date: Tue, 8 Aug 2017 14:26:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A6=96=E9=A1=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- littleApp_child/app.js | 3 + littleApp_child/pages/home/home.js | 112 ++++++++++++++++--------------------- littleApp_child/utils/apiFile.js | 8 +-- 3 files changed, 56 insertions(+), 67 deletions(-) diff --git a/littleApp_child/app.js b/littleApp_child/app.js index 0e3a30a..c8c5455 100644 --- a/littleApp_child/app.js +++ b/littleApp_child/app.js @@ -19,7 +19,9 @@ App({ var that = this //调用API从本地缓存中获取数据 var userToken = wx.getStorageSync('userToken') + var userId = wx.getStorageSync('userId') this.globalData.token = userToken + this.globalData.userId = userId console.log(userToken) // wx.navigateTo({ @@ -318,6 +320,7 @@ App({ globalData: { userInfo: null, token: '', + userId:'', openInfo: {}, }, diff --git a/littleApp_child/pages/home/home.js b/littleApp_child/pages/home/home.js index 80323bf..826f836 100644 --- a/littleApp_child/pages/home/home.js +++ b/littleApp_child/pages/home/home.js @@ -30,53 +30,35 @@ Page({ /*---------生命周期--------*/ onLoad: function () { var isFirst = wx.getStorageSync('isFirst') + // 网络监听 + this.networkStatusChange() if (!isFirst) { - this.setData({ - pageType: 3 - }) - console.log('我是空的') + wx.setStorageSync('isFirst', 'isFirst') + this.welcomePage() } else { - console.log('我是空的') - } - - - // var that = this - this.networkStatusChange() - // this.networkstatus() - if (app.globalData.token == null || app.globalData.token == '') { + if (app.globalData.token == null || app.globalData.token == '') { this.loginPage() - } else { + } else { networkUtil.showLoading() - this.getUserInfo() + this.homePage() // 监听事件 event.on('likeChanged', this, function (data) { - if (data.categoryIndex == -1) { - var artList = this.data.crisisCategorie - artList[data.articleIdIndex].likeCount++ - this.setData({ - crisisCategorie: artList - }); - } else { - var artList = this.data.articleList - artList[data.categoryIndex].article[data.articleIdIndex].likeCount++ - this.setData({ - articleList: artList - }); - } + if (data.categoryIndex == -1) { + var artList = this.data.crisisCategorie + artList[data.articleIdIndex].likeCount++ + this.setData({ + crisisCategorie: artList + }); + } else { + var artList = this.data.articleList + artList[data.categoryIndex].article[data.articleIdIndex].likeCount++ + this.setData({ + articleList: artList + }); + } }) - } - - }, - onShow: function () { - // 生命周期函数--监听页面显示 - if (app.globalData.token.length > 0 && this.data.isLogin == true) { - this.getUserInfo() - this.homePage() - } - - if (wx.getStorageSync("access_token") != null && !wx.getStorageSync("isHxOpend")) { - + } } }, onUnload: function () { @@ -91,7 +73,6 @@ Page({ return } // 网络请求,重新请求一遍数据 - this.getUserInfo() this.homePage() }, // 点击头像 @@ -114,18 +95,32 @@ Page({ }, /*---------自定义函数--------*/ homePage() { - this.getAccessToken() var that = this + this.requestHomeInfo() that.setData({ - isLogin: false + pageType: 2 }) }, - loginPage() { + toLogin() { var that = this that.setData({ - isLogin: true + pageType: 1 }) }, + welcomePage(){ + var that = this + that.setData({ + pageType: 3 + }) + }, + calculatePageSize() { + var windowWidth = wx.getSystemInfoSync().windowWidth + var smallWidth = ((windowWidth - 10) / 2 - 10) + this.setData({ + item_big_height: 'height:' + windowWidth / 4 + 'px', + item_small: 'width:' + smallWidth / 2 + 'px;height:' + smallWidth / 2 + 'px', + }) + }, // 监听网络状态 networkStatusChange() { var that = this @@ -135,13 +130,17 @@ Page({ } }) }, + requestHomeInfo(){ + // 需要先请求用户信息 + this.getUserInfo() + }, // 获取用户信息 getUserInfo() { var self = this var param = { 'token': app.globalData.token } - networkUtil._get(api.getUserInfo, param, function (res) { - + networkUtil._get(api.userInfo + app.globalData.userId, {}, function (res) { + console.log('获取用户信息',res) }, function (res) { networkUtil.showErrorToast(res.errormsg) }) @@ -159,11 +158,6 @@ Page({ }, /*---------------欢迎介绍页面---------------*/ - toLogin() { - this.setData({ - pageType: 1 - }) - }, // 获取验证码 getVerifyCode: function (e) { @@ -216,19 +210,14 @@ Page({ }, 1000) }, blurInput: function (e) { - console.log(e) phone = e.detail.value }, blurNameInput:function(e){ - console.log(e) name = e.detail.value }, // 提交表单 formSubmit: function (e) { - // wx.navigateTo({ - // url: '../childcare_knowledge/childcare_knowledge' - // }) var self = this if (e.detail.value.code == "") { wx.showModal({ @@ -258,16 +247,13 @@ Page({ }) }, loginSuccess(data) { - console.log(data) wx.setStorageSync('userToken', data.token) + wx.setStorageSync('userId', data.id) wx.setStorageSync('hxName', data.hxName) wx.setStorageSync('hxPassWord', data.hxPassWord) getApp().globalData.token = data.token - // wx.navigateTo({ - // url: '../HasDocumentedVerifySuccess/HasDocumentedVerifySuccess?name=' + name - // }) - this.setData({ - pageType:2 - }) + getApp().globalData.userId = data.id + this.homePage() } + }) diff --git a/littleApp_child/utils/apiFile.js b/littleApp_child/utils/apiFile.js index fbfa9c8..11ff2ec 100644 --- a/littleApp_child/utils/apiFile.js +++ b/littleApp_child/utils/apiFile.js @@ -6,8 +6,8 @@ module.exports = { verifyCode: 'baby/vercode', // 获取验证码 bindDoc : 'baby/bind', - // 用户基本信息 - - userInfo: 'baby/user/info', - + // 用户基本信息/id + userInfo: 'baby/user/info/', + // 首页文章列表 + homeArtList:'baby/categories', } \ No newline at end of file -- 1.8.3.1