feat(uitls): 只是自定义dsl与dom el的关联关系函数

This commit is contained in:
roymondchen 2024-08-15 14:43:30 +08:00 committed by roymondchen
parent 39e68bd33a
commit 9494ed79a3
2 changed files with 22 additions and 8 deletions

View File

@ -46,7 +46,6 @@ const popoverVisible = ref(false);
const visibleWatch = watch(
() => props.visible,
(visible) => {
console.log(visible);
if (typeof visible === 'undefined') {
nextTick(() => {
visibleWatch();

View File

@ -123,11 +123,26 @@ export const calcValueByFontsize = (doc: Document | undefined, value: number) =>
return value;
};
export const getIdFromEl = () => (el?: HTMLElement | SVGElement | null) => el?.dataset?.tmagicId;
export const getElById = () => (doc?: Document, id?: string | number) =>
doc?.querySelector(`[data-tmagic-id=${id}]`) as HTMLElement;
export const setIdToEl = () => (el: HTMLElement | SVGElement, id: string | number) => {
const dslDomRelateConfig = {
getIdFromEl: (el?: HTMLElement | SVGElement | null) => el?.dataset?.tmagicId,
getElById: (doc?: Document, id?: string | number) => doc?.querySelector(`[data-tmagic-id="${id}"]`) as HTMLElement,
setIdToEl: (el: HTMLElement | SVGElement, id: string | number) => {
el.dataset.tmagicId = `${id}`;
},
};
export const setDslDomRelateConfig = <
K extends keyof typeof dslDomRelateConfig,
T extends (typeof dslDomRelateConfig)[K],
>(
name: K,
value: T,
) => {
dslDomRelateConfig[name] = value;
};
export const getIdFromEl = () => dslDomRelateConfig.getIdFromEl;
export const getElById = () => dslDomRelateConfig.getElById;
export const setIdToEl = () => dslDomRelateConfig.setIdToEl;