You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GCSGUI/src/assets/js/useBlockDialog.js

54 lines
1.6 KiB
JavaScript

import { defineAsyncComponent, render, createVNode } from "vue";
export class routeDialog {
constructor() {
this.component = defineAsyncComponent(
() => import("@/components/RouteOptions.vue"));
this.vnode = null;
this.node = null;
this.props = {
width: "40%",
height: "auto",
};
}
installRouteDialog() {
if (!this.vnode) {
const dialog = createVNode(this.component, this.props);
const container = document.createElement('div');
render(dialog, container);
this.vnode = dialog;
this.node = container.childNodes[0];
document.body.appendChild(this.node);
}
}
/**
*
* @returns {Promise<string>}
* @param points 经纬度坐标点数组
*/
show(points) {
// 发送信号,显示窗口
const event = new CustomEvent('route-dialog-show', { detail:
{ show: true, pts: points }
});
document.dispatchEvent(event);
return new Promise((resolve,reject) => {
document.addEventListener('route-dialog-confirm', event => {
if(event.detail==='cancel'){
reject('cancel')
}else{
resolve(event.detail);
}
});
})
}
}
const aDialog = new routeDialog();
/**
* 展示一个阻塞式对话框
* @returns {Promise<string>}
* @param point 经纬度坐标点数组
*/
export async function showRouteDialog(point) {
return aDialog.show(point);
}