From 372240886496f4a759158e3100db821927e36ddb Mon Sep 17 00:00:00 2001 From: lqq Date: Tue, 22 Oct 2019 08:54:46 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=88=A0=E9=99=A4user/index.js=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E5=A3=B0=E6=98=8E=E5=91=A8=E6=9C=9F=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=AF=B7=E6=B1=82=E5=BA=93=E4=B8=AD=EF=BC=8C=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E9=86=92=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/user/index.js | 84 ++++++++++----------------------------------- utils/http.js | 14 ++++---- 2 files changed, 25 insertions(+), 73 deletions(-) diff --git a/pages/user/index.js b/pages/user/index.js index 3d0cd0b..fc47da9 100644 --- a/pages/user/index.js +++ b/pages/user/index.js @@ -13,10 +13,10 @@ Page({ /** * 页面的初始数据 */ - data: { + data: { messageTotal: Number, canIUse: wx.canIUse('button.open-type.getUserInfo'), - authType:0 + authType: 0 }, /** @@ -26,19 +26,19 @@ Page({ this.getUserInfo() this.isAuthUserInfo() }, - isAuthUserInfo(){ + isAuthUserInfo () { let that = this wx.showLoading() console.log('未授权') - return new Promise(resolve =>{ - + return new Promise(resolve => { + that.setData({ authType: 1 }, () => { wx.hideLoading() }) wx.getSetting({ - success(res) { + success (res) { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ @@ -48,10 +48,10 @@ Page({ let nickName = res.userInfo.nickName let avatarUrl = res.userInfo.avatarUrl console.log(nickName, avatarUrl) - if(nickName && avatarUrl){ + if (nickName && avatarUrl) { that.setData({ authType: 2 - },()=>{ + }, () => { wx.hideLoading() }) } @@ -62,9 +62,9 @@ Page({ }) }) }, - bindGetUserInfo(e) { + bindGetUserInfo (e) { console.log(e.detail.userInfo) - + let avatarUrl = e.detail.userInfo.avatarUrl let city = e.detail.userInfo.city let country = e.detail.userInfo.country @@ -74,22 +74,22 @@ Page({ this.updateUserInfo(avatarUrl, city, country, gender, nickName, province) this.isAuthUserInfo() }, - hasBindUserInfo(){ + hasBindUserInfo () { return store.hasBindUserInfo(); }, - updateUserInfo(avatarUrl, city, country, gender, nickName, province){ - userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province,res=>{ + updateUserInfo (avatarUrl, city, country, gender, nickName, province) { + userModel.updateUserInfo(avatarUrl, city, country, gender, nickName, province, res => { console.log(res) }) }, - getUserInfo(){ - userModel.getUserInfo(res=>{ + getUserInfo () { + userModel.getUserInfo(res => { console.log(res) }) }, - getMsgStatus(){ - userModel.getMyMessageTotal(res=>{ + getMsgStatus () { + userModel.getMyMessageTotal(res => { console.log(res.result.total) this.setData({ messageTotal: Number(res.result.total) @@ -97,7 +97,7 @@ Page({ }) }, onTapItem (e) { - const {type} = e.currentTarget.dataset + const { type } = e.currentTarget.dataset console.log(type) wx.navigateTo({ url: `/pages/user/${type}/index`, @@ -108,52 +108,4 @@ Page({ // }) // } }, - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { - - }, - - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - - }, - - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { - - }, - - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { - - }, - - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { - - }, - - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { - - }, - - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { - - } }) \ No newline at end of file diff --git a/utils/http.js b/utils/http.js index bc23d7f..c52761d 100644 --- a/utils/http.js +++ b/utils/http.js @@ -1,5 +1,5 @@ import { config } from '../config.js' -import {store} from './store.js' +import { store } from './store.js' const Method = { GET: 'GET', @@ -48,14 +48,14 @@ class HTTP { // token 无效 this.fetchAuthToken(res => { // 请求Token后,重新请求URL - if(res.code == 200) { + if (res.code == 200) { this.request(params) } }) } else { console.log('数据请求失败') wx.showToast({ - title: res.data.message, + title: res.data.message || '服务器错误,请稍后重试', icon: 'none' }) } @@ -70,7 +70,7 @@ class HTTP { }, fail: function (res) { wx.showToast({ - title: '网络连接错误,请求失败!', + title: '网络连接错误,请求稍后重试!', icon: 'none' }) params.fail && params.fail(res) @@ -78,7 +78,7 @@ class HTTP { }) } // 获取 Token - fetchAuthToken(success) { + fetchAuthToken (success) { // 获取token this._fetchWXCode().then(res => { console.log('啦啦啦啦凉啊') @@ -102,10 +102,10 @@ class HTTP { }) } // 获取微信code - _fetchWXCode() { + _fetchWXCode () { return new Promise(resolve => { wx.login({ - success(res) { + success (res) { console.log('获取Code成功 ' + res.code) resolve(res.code) } From 859d1da0c881e2c462a041423750eb38524b1ccc Mon Sep 17 00:00:00 2001 From: lqq Date: Tue, 22 Oct 2019 10:48:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E7=9A=84=E7=99=BB=E5=BD=95=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?;=E6=B7=BB=E5=8A=A0=E6=89=8B=E6=9C=BA=E5=8F=B7=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/topics/index.js | 10 +++++----- pages/user/index.js | 12 ++++++++++-- pages/user/index.wxml | 4 ++-- pages/user/index.wxss | 7 +------ utils/http.js | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pages/topics/index.js b/pages/topics/index.js index 302060a..ee4b634 100644 --- a/pages/topics/index.js +++ b/pages/topics/index.js @@ -23,9 +23,9 @@ Page({ /** * 生命周期函数--监听页面加载 */ - + onLoad: function () { - if (!store.hasPhone()) { + if (store.hasPhone()) { console.log('已经绑定手机号码') } else { console.log('未绑定手机号码') @@ -39,7 +39,7 @@ Page({ console.log('啦啦啦') this.fetchTopicList(); }, - fetchTopicList() { + fetchTopicList () { let page = this.data.currPage topicModel.getTopicList(page, res => { console.log('议题列表') @@ -82,10 +82,10 @@ Page({ wx.stopPullDownRefresh() }) }, - onRefreshList() { + onRefreshList () { this.fetchGoodIdeaList() }, - fetchGoodIdeaList() { + fetchGoodIdeaList () { let page = this.data.currPage topicModel.goldenList(page, res => { console.log('金点子列表') diff --git a/pages/user/index.js b/pages/user/index.js index e76ece6..fff2c37 100644 --- a/pages/user/index.js +++ b/pages/user/index.js @@ -27,7 +27,15 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - this.getUserInfo() + if (store.hasPhone()) { + console.log('已经绑定手机号码') + this.getUserInfo() + } else { + console.log('未绑定手机号码') + wx.redirectTo({ + url: '/pages/register/index', + }) + } }, isAuthUserInfo () { let that = this @@ -105,7 +113,7 @@ Page({ store.saveUserInfo({ nickName: res.result.nickName, avatarUrl: res.result.avatarUrl, - phone: res.result.phone === null ? '' : res.result.phone + phone: res.result.phone || '' }) } else { console.log('未授权') diff --git a/pages/user/index.wxml b/pages/user/index.wxml index 6245c1c..d04b769 100644 --- a/pages/user/index.wxml +++ b/pages/user/index.wxml @@ -9,10 +9,10 @@ - + - + 请升级微信版本 diff --git a/pages/user/index.wxss b/pages/user/index.wxss index d5c7e12..26f00ae 100644 --- a/pages/user/index.wxss +++ b/pages/user/index.wxss @@ -22,8 +22,7 @@ display: flex; flex-direction: row; align-items: center; - overflow: hidden; - justify-content: space-between; + justify-content: center; } .user_logo { width: 80px; @@ -66,8 +65,4 @@ overflow: hidden; } .authBtn{ - margin-right:10px; - margin: 0; - /* width: 100px; */ - flex-wrap: nowrap; } \ No newline at end of file diff --git a/utils/http.js b/utils/http.js index c52761d..615555c 100644 --- a/utils/http.js +++ b/utils/http.js @@ -30,7 +30,7 @@ class HTTP { 'content-type': 'application/json', } console.log(header) - console.log(data) + console.log(data || {}) wx.request({ url: url, data: data, From ede92534a4101c2de87914a7a1284306a1623539 Mon Sep 17 00:00:00 2001 From: lqq Date: Tue, 22 Oct 2019 11:15:16 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=BD=AE=E6=92=AD=E5=9B=BE=E5=92=8C?= =?UTF-8?q?=E7=83=AD=E7=82=B9=E8=AF=9D=E9=A2=98=E6=B7=BB=E5=8A=A0=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/home/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pages/home/index.js b/pages/home/index.js index b1142ec..93fd5c0 100644 --- a/pages/home/index.js +++ b/pages/home/index.js @@ -28,6 +28,8 @@ Page({ currPage: 1, }) this.fetchHomeList() + this.fetchHomeBanner() + this.fetchHomeHot() wx.vibrateShort({ success () { console.log('震动') @@ -46,7 +48,7 @@ Page({ this.fetchHomeList() }, // 获取首页列表 - fetchHomeList() { + fetchHomeList () { let page = this.data.currPage homeModel.getHomeList(page, res => { this.setData({ @@ -89,7 +91,7 @@ Page({ wx.stopPullDownRefresh() }) }, - fetchHomeBanner() { + fetchHomeBanner () { homeModel.getHomeBanner(res => { console.log('Banner') console.log(res) @@ -107,7 +109,7 @@ Page({ }) }) }, - fetchHomeHot() { + fetchHomeHot () { homeModel.getHomeHot(res => { console.log('Hot') console.log(res) @@ -125,19 +127,19 @@ Page({ }) }, // Banner/Hot/List事件 - tapSwiperItem(e) { + tapSwiperItem (e) { console.log(e.detail) this.gotoArticePage(e.detail.id) }, - tapFocusItem(e) { + tapFocusItem (e) { console.log(e.detail) this.gotoArticePage(e.detail.id) }, - clickListItem(e) { + clickListItem (e) { console.log(e.detail) this.gotoArticePage(e.detail.id) }, - gotoArticePage(id) { + gotoArticePage (id) { wx.navigateTo({ url: `/pages/article/index?id=${id}`, })