const app = getApp() Component({ /** * 组件的一些选项 */ options: { addGlobalClass: true, multipleSlots: true }, /** * 组件的对外属性 */ properties: { bgColor: { type: String, default: '' }, isCustom: { type: [Boolean, String], default: false }, isBack: { type: [Boolean, String], default: false }, intercept: { type: Boolean, default: false }, bgImage: { type: String, default: '' } }, /** * 组件的初始数据 */ data: { StatusBar: app.globalData.StatusBar, CustomBar: app.globalData.CustomBar, Custom: app.globalData.Custom }, lifetimes: { // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached: function () { this.setData({ StatusBar: app.globalData.StatusBar || 40, CustomBar: app.globalData.CustomBar || (app.globalData.isIos ? 64 : 60), Custom: app.globalData.Custom }) } }, /** * 组件的方法列表 */ methods: { backPage() { if(this.data.intercept){ this.triggerEvent('customevent', null) return } if(getCurrentPages().length == 1){ this.toHome() } else { wx.navigateBack() } }, toHome(){ if(app.globalData.userInfo.userId){ wx.redirectTo({ url: '/pages/index/index' }) } else { wx.reLaunch({ url: '/pages/login/index' }) } } } })