You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

import { defineComponent, watch, onBeforeMount, onUnmounted, getCurrentInstance, isVue2 } from "vue-demi";
import { useMapRoot } from "../../use";
import { useInit, PROPS, EVENTS } from "./use";
export const TdtCarTrack = defineComponent({
name: "TdtCarTrack",
props: PROPS,
emits: EVENTS,
setup(props, { emit, expose }) {
onBeforeMount(async () => {
onUnmounted(() => tdtComponent?.clear());
expose?.({ start, pause, stop, clear });
if (isVue2) {
const vm = getCurrentInstance()?.proxy as any;
vm.star = start;
vm.paus = pause;
vm.sto = stop;
}
const tdtMap = await useMapRoot();
let tdtComponent: T.CarTrack | null = null;
watch(
() => props.Datas,
val => {
tdtComponent?.clear();
tdtComponent = null;
if (!val.length) return;
tdtComponent = useInit(props, emit, tdtMap);
emit("init", tdtComponent);
},
{ immediate: true }
);
function start() {
tdtComponent?.start();
}
function pause() {
tdtComponent?.pause();
}
function stop() {
tdtComponent?.stop();
}
function clear() {
tdtComponent?.clear();
}
});
return () => {};
}
});
export type TdtCarTrack = InstanceType<typeof TdtCarTrack>;