Files
mayfly-go/mayfly_go_web/src/views/ops/db/component/SqlExecBox.ts

45 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { h, render, VNode } from 'vue';
import SqlExecDialog from './SqlExecDialog.vue';
export type SqlExecProps = {
sql: string;
dbId: number;
db: string;
runSuccessCallback?: Function;
cancelCallback?: Function;
};
const boxId = 'sql-exec-id';
const renderBox = (): VNode => {
const props: SqlExecProps = {
sql: '',
dbId: 0,
} as any;
const container = document.createElement('div');
container.id = boxId;
// 创建 虚拟dom
const boxVNode = h(SqlExecDialog, props);
// 将虚拟dom渲染到 container dom 上
render(boxVNode, container);
// 最后将 container 追加到 body 上
document.body.appendChild(container);
return boxVNode;
};
let boxInstance: any;
const SqlExecBox = (props: SqlExecProps): void => {
if (boxInstance) {
const boxVue = boxInstance.component;
// 调用open方法显示弹框注意不能使用boxVue.ctx来调用组件函数build打包后ctx会获取不到
boxVue.exposed.open(props);
} else {
boxInstance = renderBox();
SqlExecBox(props);
}
};
export default SqlExecBox;