Commit 8f0ecaa5a1cf2dba34de0e267d6db053e8772688

Authored by luoye
1 parent e780268d39

新增首页接口

Showing 3 changed files with 56 additions and 67 deletions

littleApp_child/app.js View file @ 8f0ecaa
... ... @@ -19,7 +19,9 @@
19 19 var that = this
20 20 //调用API从本地缓存中获取数据
21 21 var userToken = wx.getStorageSync('userToken')
  22 + var userId = wx.getStorageSync('userId')
22 23 this.globalData.token = userToken
  24 + this.globalData.userId = userId
23 25 console.log(userToken)
24 26  
25 27 // wx.navigateTo({
... ... @@ -318,6 +320,7 @@
318 320 globalData: {
319 321 userInfo: null,
320 322 token: '',
  323 + userId:'',
321 324 openInfo: {},
322 325 },
323 326  
littleApp_child/pages/home/home.js View file @ 8f0ecaa
... ... @@ -30,55 +30,37 @@
30 30 /*---------生命周期--------*/
31 31 onLoad: function () {
32 32 var isFirst = wx.getStorageSync('isFirst')
  33 + // 网络监听
  34 + this.networkStatusChange()
33 35 if (!isFirst) {
34   - this.setData({
35   - pageType: 3
36   - })
37   - console.log('我是空的')
  36 + wx.setStorageSync('isFirst', 'isFirst')
  37 + this.welcomePage()
38 38 } else {
39   - console.log('我是空的')
40   - }
41   -
42   -
43   - // var that = this
44   - this.networkStatusChange()
45   - // this.networkstatus()
46   - if (app.globalData.token == null || app.globalData.token == '') {
  39 + if (app.globalData.token == null || app.globalData.token == '') {
47 40 this.loginPage()
48   - } else {
  41 + } else {
49 42 networkUtil.showLoading()
50   - this.getUserInfo()
  43 +
51 44 this.homePage()
52 45 // 监听事件
53 46 event.on('likeChanged', this, function (data) {
54   - if (data.categoryIndex == -1) {
55   - var artList = this.data.crisisCategorie
56   - artList[data.articleIdIndex].likeCount++
57   - this.setData({
58   - crisisCategorie: artList
59   - });
60   - } else {
61   - var artList = this.data.articleList
62   - artList[data.categoryIndex].article[data.articleIdIndex].likeCount++
63   - this.setData({
64   - articleList: artList
65   - });
66   - }
  47 + if (data.categoryIndex == -1) {
  48 + var artList = this.data.crisisCategorie
  49 + artList[data.articleIdIndex].likeCount++
  50 + this.setData({
  51 + crisisCategorie: artList
  52 + });
  53 + } else {
  54 + var artList = this.data.articleList
  55 + artList[data.categoryIndex].article[data.articleIdIndex].likeCount++
  56 + this.setData({
  57 + articleList: artList
  58 + });
  59 + }
67 60 })
  61 + }
68 62 }
69   -
70 63 },
71   - onShow: function () {
72   - // 生命周期函数--监听页面显示
73   - if (app.globalData.token.length > 0 && this.data.isLogin == true) {
74   - this.getUserInfo()
75   - this.homePage()
76   - }
77   -
78   - if (wx.getStorageSync("access_token") != null && !wx.getStorageSync("isHxOpend")) {
79   -
80   - }
81   - },
82 64 onUnload: function () {
83 65 // 移除监听
84 66 event.remove('likeChanged', this);
... ... @@ -91,7 +73,6 @@
91 73 return
92 74 }
93 75 // 网络请求,重新请求一遍数据
94   - this.getUserInfo()
95 76 this.homePage()
96 77 },
97 78 // 点击头像
98 79  
99 80  
100 81  
101 82  
102 83  
... ... @@ -114,18 +95,32 @@
114 95 },
115 96 /*---------自定义函数--------*/
116 97 homePage() {
117   - this.getAccessToken()
118 98 var that = this
  99 + this.requestHomeInfo()
119 100 that.setData({
120   - isLogin: false
  101 + pageType: 2
121 102 })
122 103 },
123   - loginPage() {
  104 + toLogin() {
124 105 var that = this
125 106 that.setData({
126   - isLogin: true
  107 + pageType: 1
127 108 })
128 109 },
  110 + welcomePage(){
  111 + var that = this
  112 + that.setData({
  113 + pageType: 3
  114 + })
  115 + },
  116 + calculatePageSize() {
  117 + var windowWidth = wx.getSystemInfoSync().windowWidth
  118 + var smallWidth = ((windowWidth - 10) / 2 - 10)
  119 + this.setData({
  120 + item_big_height: 'height:' + windowWidth / 4 + 'px',
  121 + item_small: 'width:' + smallWidth / 2 + 'px;height:' + smallWidth / 2 + 'px',
  122 + })
  123 + },
129 124 // 监听网络状态
130 125 networkStatusChange() {
131 126 var that = this
132 127  
... ... @@ -135,13 +130,17 @@
135 130 }
136 131 })
137 132 },
  133 + requestHomeInfo(){
  134 + // 需要先请求用户信息
  135 + this.getUserInfo()
  136 + },
138 137 // 获取用户信息
139 138 getUserInfo() {
140 139  
141 140 var self = this
142 141 var param = { 'token': app.globalData.token }
143   - networkUtil._get(api.getUserInfo, param, function (res) {
144   -
  142 + networkUtil._get(api.userInfo + app.globalData.userId, {}, function (res) {
  143 + console.log('获取用户信息',res)
145 144 }, function (res) {
146 145 networkUtil.showErrorToast(res.errormsg)
147 146 })
... ... @@ -159,11 +158,6 @@
159 158  
160 159 },
161 160 /*---------------欢迎介绍页面---------------*/
162   - toLogin() {
163   - this.setData({
164   - pageType: 1
165   - })
166   - },
167 161  
168 162 // 获取验证码
169 163 getVerifyCode: function (e) {
170 164  
171 165  
... ... @@ -216,19 +210,14 @@
216 210 }, 1000)
217 211 },
218 212 blurInput: function (e) {
219   - console.log(e)
220 213 phone = e.detail.value
221 214 },
222 215 blurNameInput:function(e){
223   - console.log(e)
224 216 name = e.detail.value
225 217 },
226 218 // 提交表单
227 219 formSubmit: function (e) {
228 220  
229   - // wx.navigateTo({
230   - // url: '../childcare_knowledge/childcare_knowledge'
231   - // })
232 221 var self = this
233 222 if (e.detail.value.code == "") {
234 223 wx.showModal({
235 224  
236 225  
237 226  
... ... @@ -258,17 +247,14 @@
258 247 })
259 248 },
260 249 loginSuccess(data) {
261   - console.log(data)
262 250 wx.setStorageSync('userToken', data.token)
  251 + wx.setStorageSync('userId', data.id)
263 252 wx.setStorageSync('hxName', data.hxName)
264 253 wx.setStorageSync('hxPassWord', data.hxPassWord)
265 254 getApp().globalData.token = data.token
266   - // wx.navigateTo({
267   - // url: '../HasDocumentedVerifySuccess/HasDocumentedVerifySuccess?name=' + name
268   - // })
269   - this.setData({
270   - pageType:2
271   - })
  255 + getApp().globalData.userId = data.id
  256 + this.homePage()
272 257 }
  258 +
273 259 })
littleApp_child/utils/apiFile.js View file @ 8f0ecaa
... ... @@ -6,9 +6,9 @@
6 6 verifyCode: 'baby/vercode',
7 7 // 获取验证码
8 8 bindDoc : 'baby/bind',
9   - // 用户基本信息
10   -
11   - userInfo: 'baby/user/info',
12   -
  9 + // 用户基本信息/id
  10 + userInfo: 'baby/user/info/',
  11 + // 首页文章列表
  12 + homeArtList:'baby/categories',
13 13 }