const app = getApp(); Component({ /** * 组件的属性列表 */ properties: { width:String, titleText:{ type:String, value:'' }, titleTextCenter:{ type:Boolean, value:true }, editable:{ type:Boolean, value:false }, editRequired:{ type:Boolean, value:false }, row:{ type:Number, value:4 }, content:{ type:String, value:'' }, contentPlaceholder:{ type:String, value:'请输入内容' }, isShowCancel:{ type:Boolean, value:true }, isShowOk:{ type:Boolean, value:true }, cancelButtonText:{ type:String, value:'取消' }, okButtonText:{ type:String, value:'确定' }, show:{ type:Boolean, value:false, observer(show){ if(show){ const windowInfo = wx.getWindowInfo(); this.createSelectorQuery().select('#modalViewMain').boundingClientRect((res)=>{ const viewHeight = res.height; this.setData({ dynamicsStyle:`top:${(windowInfo.windowHeight-viewHeight)/2}px;height:${viewHeight}px;` }) }).exec(); } this.setData({ _show:show }) } }, overlayClose:{ type:Boolean, value:true }, showCloseButton:{ type:Boolean, value:false }, autoFocus:{ type:Boolean, value:false }, useInput:{ type:Boolean, value:false }, }, /** * 组件的初始数据 */ data: { dynamicsStyle:'', textareaHeight:124, _show:false }, /** * 组件的方法列表 */ methods: { cancelButtonTap(){ this.setData({ _show:false }); this.triggerEvent('cancel'); }, okButtonTap(){ if(this.properties.editRequired){ const valid = app.validateForm({ content:{ required:true, message:this.properties.contentPlaceholder, shake:true, // autoFocus:true //textarea 有 bug } },this); if(valid.length>0)return; } this.setData({ _show:false }); this.triggerEvent('ok',this.properties.content); }, afterLeave(event){ this.setData({ show:false }) this.triggerEvent('afterLeave') } }, lifetimes:{ attached(){ console.log('init model view'); } } })