From a592850d8be5524f7c587da6f1721e869853200f Mon Sep 17 00:00:00 2001 From: Ge Hao Date: Fri, 4 Nov 2016 17:35:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=92=8C=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E8=BF=98=E9=9C=80=E8=A6=81=E5=88=86=E7=A6=BB=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=EF=BC=8C=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=89=8B=E6=9C=BA=E5=8F=B7=EF=BC=8C=E5=8F=91=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E8=BF=9B=E8=A1=8C=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 21 --------------------- pages/mine/mine.js | 18 +++++++++--------- pages/mine/mine.wxml | 8 +++++--- utils/profile.js | 31 +++++++++++++++++++++++++++---- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/app.js b/app.js index d29666d..5e8207e 100644 --- a/app.js +++ b/app.js @@ -28,27 +28,6 @@ App({ } }, - getCustomerInfo: function (cb) { - var that = this - wx.request({ - url: 'http://localhost:3000/sessions/new', - header: { 'Content-Type': 'application/json'}, - data: { - code: 'sadjfskdf', - mobile: '13054277777', - name: 'test' - }, - success: function(res) { - that.globalData.currentCustomer = res.data.customer - that.globalData.token = res.data.token - typeof cb == "function" && cb(that.globalData.currentCustomer) - }, - fail: function(res) { - } - }) - }, - - globalData:{ userInfo: null, currentCustomer: null diff --git a/pages/mine/mine.js b/pages/mine/mine.js index 4f4895a..c253ac7 100644 --- a/pages/mine/mine.js +++ b/pages/mine/mine.js @@ -18,18 +18,18 @@ Page({ var that = this app.getUserInfo(function(userInfo){ that.setData({userInfo:userInfo}) - app.getCustomerInfo(function(currentCustomer){ + profile.getCustomerInfo(function(currentCustomer){ var baye_rank = currentCustomer.baye_rank that.setData({baye_rank: baye_rank}) - }) - }) - profile.getZichanSlides({}, function(result) { - var data = getApp().store.sync(result.data) - that.setData({'zichan_slides': data}) - wx.setStorage({ - key:"zichan_slides", - data:data + profile.getZichanSlides(function(result) { + var data = getApp().store.sync(result.data) + that.setData({'zichan_slides': data}) + wx.setStorage({ + key:"zichan_slides", + data:data + }) + }) }) }) }, diff --git a/pages/mine/mine.wxml b/pages/mine/mine.wxml index e2ddd58..a01a174 100644 --- a/pages/mine/mine.wxml +++ b/pages/mine/mine.wxml @@ -3,9 +3,11 @@ {{userInfo.nickName}} - - - {{baye_rank}} + + + + {{baye_rank || ''}} + diff --git a/utils/profile.js b/utils/profile.js index 3497e06..e22597c 100644 --- a/utils/profile.js +++ b/utils/profile.js @@ -1,17 +1,40 @@ const API_URL = 'http://localhost:3000' +const app = getApp() -function getZichanSlides (data, resolve) { +function getZichanSlides (resolve) { wx.request({ url: `${API_URL}/profiles/zichan_sildes`, - data: data, + data: {token: app.globalData.token}, header: { 'Content-Type': 'application/json'}, success: resolve, fail: function(){} }) } +function getCustomerInfo (cb) { + wx.request({ + url: `${API_URL}/sessions/new`, + header: { 'Content-Type': 'application/json'}, + data: { + code: 'sadjfskdf', + mobile: '13054277977', + name: 'test' + }, + success: function(res) { + app.globalData.currentCustomer = res.data.customer + app.globalData.token = res.data.token + typeof cb == "function" && cb(app.globalData.currentCustomer) + }, + fail: function(res) { + } + }) +} + module.exports = { - getZichanSlides (data, resolve) { - return getZichanSlides(data, resolve) + getZichanSlides (resolve) { + return getZichanSlides(resolve) + }, + getCustomerInfo (resolve) { + return getCustomerInfo(resolve) } } \ No newline at end of file