103 lines
1.9 KiB
JavaScript
103 lines
1.9 KiB
JavaScript
const app = getApp();
|
|
|
|
Component({
|
|
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
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:true,
|
|
cancelButtonText:{
|
|
type:String,
|
|
value:'取消'
|
|
},
|
|
okButtonText:{
|
|
type:String,
|
|
value:'确定'
|
|
},
|
|
show:{
|
|
type:Boolean,
|
|
value:false
|
|
}
|
|
},
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
dynamicsStyle:'',
|
|
textareaHeight:124
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
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
|
|
}
|
|
},this);
|
|
if(valid.length>0)return;
|
|
}
|
|
this.setData({
|
|
show:false
|
|
});
|
|
this.triggerEvent('ok',this.properties.content);
|
|
}
|
|
},
|
|
|
|
lifetimes:{
|
|
attached(){
|
|
console.log(this.properties.row);
|
|
const windowInfo = wx.getWindowInfo();
|
|
let viewHeight = 50+96+32+48;
|
|
const textareaHeight = this.properties.row*25+24;
|
|
if(this.properties.editable){
|
|
viewHeight+=textareaHeight;
|
|
}
|
|
this.setData({
|
|
textareaHeight:textareaHeight,
|
|
dynamicsStyle:`top:${(windowInfo.windowHeight-viewHeight)/2}px;height:${viewHeight}px;`
|
|
})
|
|
}
|
|
}
|
|
}) |