const STORAGE_KEY = 'PLUG-ADD-MYAPP-KEY'; Component({ properties: { text: { type: String, value: '点击「添加小程序」,下次访问更便捷' }, duration: { type: Number, value: 3 } }, data: { SHOW:false, SHOW_TOP: true, SHOW_MODAL: false, statusBarHeight:20, attachDir:global.config.attachDir }, ready: function () { let cache = wx.getStorageSync(STORAGE_KEY); if (cache) return; this.setData({ SHOW:true }); setTimeout(() => { this.setData({ SHOW_TOP: false }) }, this.data.duration * 1000); }, attached(){ wx.getSystemInfo({ success: res=> { let {statusBarHeight} = res; this.setData({statusBarHeight}); } }) }, methods: { showModal: function () { this.setData({ SHOW_TOP: false, SHOW_MODAL: true }); }, okHandler: function () { this.setData({ SHOW: false }); wx.setStorage({ key: STORAGE_KEY, data: +new Date, }); } } })