showModal.js 1.33 KB
// components/showModal/showModal.js
import util from '../../../utils/util'
const properties={
    cancelText:{type:String,value:''},
    cancelColor:{type:String,value:'#000'},
    confirmText:{type:String,value:'确认'},
    confirmColor:{type:String,value:'#fff'},
    header:{type:String,value:'确认信息'},
    body:{type:String,value:'确认信息'},
};
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */
  properties: properties,

  /**
   * 组件的初始数据
   */
  data: {
      hasShow:false,
  },
    attached(){
      let opt={};
        Object.keys(properties).forEach((k)=>{
            opt[k]=this.data[k]
        })
      this.setData({
          opt:opt
      })
    },
  /**
   * 组件的方法列表
   */
  methods: {
      options(obj){
        let opt=this.data.opt;
        this.setData({
            opt:{
                ...opt,
                ...obj
            }
        })
          return this;
      },
    show(){
          console.log(this.data.opt)
      this.setData({
          hasShow:true,
      })
    },
      tapButton(e){
        this.triggerEvent('showModal',{type:util.attr(e,'type')})
          this.hide();
      },
      hide(){
          this.setData({
              hasShow:false,
          })
      }
  }
})