代码拉取完成,页面将自动刷新
//app.js
const defaultTime = {
defaultWorkTime: 25,
defaultRestTime: 5
}
App({
// 获取UIinfo
initUiGlobal() {
wx.getSystemInfo({
success: e => {
const { statusBarHeight: StatusBar, screenHeight, windowWidth } = e
this.globalData.StatusBar = StatusBar
this.globalData.screenHeight = screenHeight
this.globalData.windowWidth = windowWidth
const custom = wx.getMenuButtonBoundingClientRect()
if (custom) {
this.globalData.Custom = custom
this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight
} else {
this.globalData.CustomBar = StatusBar + 50
}
}
})
},
//初始化环境,做一个开发环境和测试环境/后期
initEnv() {
const env = 'cloud-environment-5e1r8y90a6ba7e'
wx.cloud.init({
env
})
this.globalData.env = env
},
onLaunch(){
let workTime = this.globalData.workTime
let restTime = this.globalData.restTime
if (!workTime) {
this.globalData.workTime = defaultTime.defaultWorkTime
}
if (!restTime) {
this.globalData.restTime = defaultTime.defaultRestTime
}
this.initUiGlobal()
this.initEnv()
},
globalData: {
// 用户信息
userInfo: {},
openid: null,
hasUserInfo: false,
requestUserInfo: [], // 好友信息
// 番茄时间
workTime: null,
restTime: null,
// 专注记录
logs: [],
totalFocusTime: null,
totalFocusNumber: null,
todayLogs: [],
todayFocusTime: null,
todayFocusNumber: null,
// 待办
todoLists: [],
isTodo: 0,
todoIndex: -1,
// 界面
StatusBar: null,
Custom: null,
CustomBar: null,
screenHeight: null,
windowWidth: null,
// 环境
env: null
},
// getApp().watch("totalFocusTime", (res) => {this.setData({totalFocusTime: res})}, this);
watch: function(dataName, callback, that) {
let obj = this.globalData // 拿到全局变量
Object.defineProperty(obj, dataName, {
configurable: true, //可配置
enumerable: true, //可枚举
set: value => { //当监听到的函数被设置新值的时候执行
this['temp' + dataName] = value;
callback.call(that, value) //调用回调函数。传入新值
},
get: () => {
return this['temp' + dataName]
}
})
}
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。