Skip to content

Commit

Permalink
replace that with this by applying arrow function
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuxiao committed Aug 8, 2018
1 parent 9d6ea40 commit 4fda618
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 67 deletions.
8 changes: 3 additions & 5 deletions components/heartbeat/heartbeat.js
Expand Up @@ -20,10 +20,9 @@ Component({
ready () {
let systeminfo = getApp().globalData.systeminfo
if (utils.isEmptyObject(systeminfo)) {
let that = this
wx.getSystemInfo({
success: function(res) {
that.setData({
success: (res) => {
this.setData({
windowWidth: res.windowWidth || res.screenWidth,
windowHeight: res.windowHeight || res.screenHeight,
})
Expand Down Expand Up @@ -68,9 +67,8 @@ Component({
tops,
widths,
})
let that = this
let timer = setTimeout(() => {
that.setData({
this.setData({
animations,
})
clearTimeout(timer)
Expand Down
7 changes: 3 additions & 4 deletions pages/about/about.js
Expand Up @@ -25,16 +25,15 @@ Page({
})
},
initSwiper () {
let that = this
let systeminfo = getApp().globalData.systeminfo
if (utils.isEmptyObject(systeminfo)) {
wx.getSystemInfo({
success: function (res) {
that.setSwiperHeight(res)
success: (res) => {
this.setSwiperHeight(res)
},
})
} else {
that.setSwiperHeight(systeminfo)
this.setSwiperHeight(systeminfo)
}
},
setSwiperHeight (res) {
Expand Down
58 changes: 24 additions & 34 deletions pages/index/index.js
Expand Up @@ -113,14 +113,13 @@ Page({
this.setData({
enableSearch: false,
})
let that = this
let heartbeat = this.selectComponent('#heartbeat')
heartbeat.dance(() => {
that.setData({
this.setData({
showHeartbeat: false,
enableSearch: true,
})
that.setData({
this.setData({
showHeartbeat: true,
})
})
Expand All @@ -138,17 +137,15 @@ Page({
duration: 300,
})
if (val) {
let that = this
this.geocoder(val, (loc) => {
that.init({
this.init({
location: `${loc.lng},${loc.lat}`
})
})
}
},
// 地理位置编码
geocoder (address, success) {
let that = this
wx.request({
url: getApp().setGeocoderUrl(address),
success (res) {
Expand All @@ -170,15 +167,14 @@ Page({
icon: 'none',
})
},
complete () {
that.setData({
complete: () => {
this.setData({
searchText: '',
})
},
})
},
fail (res) {
let that = this
wx.stopPullDownRefresh()
let errMsg = res.errMsg || ''
// 拒绝授权地理位置权限
Expand All @@ -187,14 +183,14 @@ Page({
title: '需要开启地理位置权限',
icon: 'none',
duration: 2500,
success (res) {
if (that.canUseOpenSettingApi()) {
success: (res) => {
if (this.canUseOpenSettingApi()) {
let timer = setTimeout(() => {
clearTimeout(timer)
wx.openSetting({})
}, 2500)
} else {
that.setData({
this.setData({
openSettingButtonShow: true,
})
}
Expand All @@ -220,14 +216,13 @@ Page({
}
},
init(params) {
let that = this
let BMap = new bmap.BMapWX({
ak: globalData.ak,
})
BMap.weather({
location: params.location,
fail: that.fail,
success: that.success,
fail: this.fail,
success: this.success,
})
},
// drawWeather () {
Expand All @@ -243,27 +238,25 @@ Page({
this.init({})
},
setMenuPosition () {
let that = this
wx.getStorage({
key: 'pos',
success: function(res) {
that.setData({
success: (res) => {
this.setData({
pos: res.data,
})
},
fail: function (res) {
that.setData({
fail: (res) => {
this.setData({
pos: {},
})
},
})
},
getCityDatas() {
let that = this
let cityDatas = wx.getStorage({
key: 'cityDatas',
success: function (res) {
that.setData({
success: (res) => {
this.setData({
cityDatas: res.data,
})
},
Expand All @@ -272,14 +265,13 @@ Page({
onShow () {
this.getCityDatas()
this.setMenuPosition()
let that = this
let bcgColor = utils.themeSetting()
this.setData({
bcgColor,
})
this.setBcg()
this.initSetting((setting) => {
that.checkUpdate(setting)
this.checkUpdate(setting)
})
if (!this.data.cityChanged) {
this.init({})
Expand Down Expand Up @@ -322,35 +314,33 @@ Page({
})
},
setBcg () {
let that = this
wx.getSavedFileList({
success: function (res) {
success: (res) => {
let fileList = res.fileList
if (!utils.isEmptyObject(fileList)) {
that.setData({
this.setData({
bcgImg: fileList[0].filePath,
})
} else {
that.setData({
this.setData({
bcgImg: '',
})
}
},
})
},
initSetting (successFunc) {
let that = this
wx.getStorage({
key: 'setting',
success: function(res) {
success: (res) => {
let setting = res.data || {}
that.setData({
this.setData({
setting,
})
successFunc && successFunc(setting)
},
fail: function () {
that.setData({
fail: () => {
this.setData({
setting: {},
})
},
Expand Down
42 changes: 18 additions & 24 deletions pages/setting/setting.js
Expand Up @@ -75,10 +75,9 @@ Page({
})
},
customBcg () {
let that = this
wx.chooseImage({
success: function (res) {
that.removeBcg(() => {
success: (res) => {
this.removeBcg(() => {
wx.saveFile({
tempFilePath: res.tempFilePaths[0],
success: function (res) {
Expand Down Expand Up @@ -116,17 +115,16 @@ Page({
})
this.ifDisableUpdate()
this.getScreenBrightness()
let that = this
wx.getStorage({
key: 'setting',
success: function(res) {
success: (res) => {
let setting = res.data
that.setData({
this.setData({
setting,
})
},
fail: function (res) {
that.setData({
fail: (res) => {
this.setData({
setting: {},
})
},
Expand Down Expand Up @@ -176,15 +174,14 @@ Page({
})
},
getScreenBrightness () {
let that = this
wx.getScreenBrightness({
success: function (res) {
that.setData({
success: (res) => {
this.setData({
screenBrightness: Number(res.value * 100).toFixed(0),
})
},
fail: function (res) {
that.setData({
fail: (res) => {
this.setData({
screenBrightness: '获取失败',
})
},
Expand All @@ -194,22 +191,20 @@ Page({
this.setScreenBrightness(e.detail.value)
},
setScreenBrightness (val) {
let that = this
wx.setScreenBrightness({
value: val / 100,
success: function (res) {
that.setData({
success: (res) => {
this.setData({
screenBrightness: val,
})
},
})
},
setKeepScreenOn (b) {
let that = this
wx.setKeepScreenOn({
keepScreenOn: b,
success () {
that.setData({
success: () => {
this.setData({
keepscreenon: b,
})
},
Expand All @@ -221,7 +216,6 @@ Page({
})
},
removeStorage (e) {
let that = this
let datatype = e.currentTarget.dataset.type
if (datatype === 'menu') {
wx.setStorage({
Expand All @@ -242,15 +236,15 @@ Page({
content: '确认要初始化设置',
cancelText: '容朕想想',
confirmColor: '#40a7e7',
success(res) {
success: (res) => {
if (res.confirm) {
wx.removeStorage({
key: 'setting',
success: function (res) {
wx.showToast({
title: '设置已初始化',
})
that.setData({
this.setData({
setting: {},
})
},
Expand All @@ -267,11 +261,11 @@ Page({
success (res) {
if (res.confirm) {
wx.clearStorage({
success: function (res) {
success: (res) => {
wx.showToast({
title: '数据已清除',
})
that.setData({
this.setData({
setting: {},
pos: {},
})
Expand Down

0 comments on commit 4fda618

Please sign in to comment.