pages/index/index.wxml
1 2 3 4 5 6 |
<view class="weather-wrapper"> <view class="temp">{{setup}}</view> <view class="weather">{{joke}}</view> <image class="weather-bg" src="/images/sunny-bg.png" mode="scaleToFill"></image> </view> |
pages/index/index.wxss
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/*width 750rpx, height 760rpx 760=174+280+56+250*/ .weather-wrapper{ position: relative; padding-top: 174rpx; padding-bottom: 250rpx; } .temp { text-align:center; font-size:80rpx; line-height:180rpx; opacity:0.8; } .weather { text-align: center; font-size: 40rpx; line-height: 56rpx; opacity: 0.65; } .weather-bg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; } |
pages/index/index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
const weatherMap = { 'sunny': 'sunny', 'cloudy': 'cloudy', 'overcast': 'overcast', 'lightrain': 'lightrain', 'heavyrain': 'heavyrain', 'snow': 'snow' } const weatherColorMap = { 'sunny': '#cbeefd', 'cloudy': '#deeef6', 'overcast': '#c6ced2', 'lightrain': '#bdd5e1', 'heavyrain': '#c5ccd0', 'snow': '#aae1fc' } const URL = 'http://106.15.137.49:8080/rickyabc/api/v1/auth/login' const HTTP_VERB = 'POST' var app = getApp() Page({ data: { setup: "", joke: "", userInfo: {} }, onLoad() { console.log('onLoad') console.log('does app have getUserInfo?', (app && app.getUserInfo) ? "true" : "false") app.getUserInfo(function(userInfo){ console.log('userInfo', userInfo); }) this.getNow() }, onPullDownRefresh(){ this.getNow(() => { wx.stopPullDownRefresh() }) }, getNow(callback){ wx.request({ url: URL, method: HTTP_VERB, data: { "username": "rachel", "password": "123" }, success: res => { console.log(res.data); let setup = res.data.setup; let punchline = res.data.punchline; this.setData({ joke: punchline, setup: setup, }) wx.setNavigationBarColor({ frontColor: '#000000', backgroundColor: weatherColorMap['sunny'], }) }, complete: () =>{ // callback && callback() } }) } }) |
app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
App({ globalData:{ userInfo:null }, getUserInfo:function(cb) { console.log('1') var that = this if(this.globalData.userInfo) { console.log('2') typeof cb == "function" && cb(this.globalData.userInfo) } else { // Login interface call console.log('No globalData.userInfo exists...') wx.login({ fail: function(err) { console.log('ERROR', err); }, success: function () { console.log('wxlogin SUCCESS') wx.getUserInfo({ success: function (res) { console.log('result: ', res); // typeof cb == "function" && cb(that.globalData.userInfo) } }) } }) } }, onLaunch: function() { console.log('App Launched √'); var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) } }) |