import Vue from 'vue';
import CmsDialogComponent from "./CmsDialog";
//使用vue的extend，以vue文件为基础组件，返回一个可以创建vue组件的特殊构造函数
const CmsDialogConstructor = Vue.extend(CmsDialogComponent)

CmsDialogComponent.install = (options) => {
  let instance
  const initInstance = () => {
    instance = new CmsDialogConstructor({
      data: options,
    }).$mount()
    document.body.appendChild(instance.$el)
  }
  Vue.prototype.$cmsDialog = {
    open: (opts) => {
      options = opts
      initInstance()
    },
    close () {
      instance.cancel()
    }
  }
}
export default CmsDialogComponent
