const moudule = {};
import vue from "vue";
import objView from './index.vue';
import {openObsUploadDialog} from "@base/components/obsUpload/index.js"

let configUtil = {
  vue,
  objView
}

const objInstance = configUtil.vue.extend(configUtil.objView);
const initInstance = (containter) => {
  // 实例化vue实例
  let currentInstance = new objInstance({i18n: window.$vueRoot._i18n});
  let dom = currentInstance.$mount().$el;
  containter.appendChild(dom);
  return currentInstance;
};

function toDo(options) {
  let model = window.$vueRoot.$store.getters.fileServerInfo?.model;
  if(options?.model){
    model = options.model ;
  }
  if(model==="obs"){
    return openObsUploadDialog(options);
  }else{
    let containter = document.body;
    let currentInstance = initInstance(containter);
    Object.assign(currentInstance, options);
    return currentInstance.handleShow(options);
  }

};

function toDo2(options) {
  let containter = document.body;
  let currentInstance = initInstance(containter);
  Object.assign(currentInstance, options);
  return currentInstance.singerUpload(options);
};

// 定义插件对象
// vue的install方法，用于定义vue插件
moudule.install = function (Vue) {
  // 在Vue的原型上添加实例方法，以全局调用
  Vue.prototype.$baseUpload = {
    open: toDo,
    upload: toDo2
  }
};

export default moudule;
