import Vue from 'vue'
|
// 导入组件
|
import FileCompareDialog from './Dialog.vue'
|
// 使用基础 Vue 构造器,创建一个“子类”
|
const FileCompareConstructor = Vue.extend(FileCompareDialog)
|
|
let fileCompareInstance = null
|
/**
|
* 初始化文件详情文件实例
|
* @param {object | array} fileInfo 文件信息,批量时为数组、单文件时为对象
|
*/
|
const initInstanceFileCompare = (fileInfo) => {
|
fileCompareInstance = new FileCompareConstructor({
|
el: document.createElement('div'),
|
data() {
|
return {
|
fileInfo
|
}
|
}
|
})
|
}
|
/**
|
* 文件详情文件 Promise 函数
|
* @returns {Promise} 抛出确认和取消回调函数
|
*/
|
const showFileCompareDialog = (obj) => {
|
// 非首次调用服务时,在 DOM 中移除上个实例
|
if (fileCompareInstance !== null) {
|
document.body.removeChild(fileCompareInstance.$el)
|
}
|
let { fileInfo } = obj
|
return new Promise((reslove) => {
|
initInstanceFileCompare(fileInfo)
|
fileCompareInstance.callback = (res) => {
|
reslove(res)
|
// 服务取消时卸载 DOM
|
if (res === 'cancel' && fileCompareInstance !== null) {
|
document.body.removeChild(fileCompareInstance.$el)
|
fileCompareInstance = null
|
}
|
}
|
document.body.appendChild(fileCompareInstance.$el) // 挂载 DOM
|
Vue.nextTick(() => {
|
fileCompareInstance.visible = true // 打开对话框
|
})
|
})
|
}
|
|
export default showFileCompareDialog
|