From 46df470bbba226da5224d9adc1c47ecfadf11e1d Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期四, 18 七月 2024 14:21:01 +0800
Subject: [PATCH] chart resize

---
 src/directive/customDirective.ts |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/src/directive/customDirective.ts b/src/directive/customDirective.ts
index c67350f..5a13bdd 100644
--- a/src/directive/customDirective.ts
+++ b/src/directive/customDirective.ts
@@ -53,6 +53,14 @@
 	});
 }
 
+export const eleFocusDirective = (app: App) => {
+	app.directive('elInputFocus', {
+		mounted: (el) => {
+			el.querySelector('input.el-input__inner')?.focus();
+		},
+	});
+};
+
 /**
  * 鑷畾涔夋嫋鍔ㄦ寚浠�
  * @description  浣跨敤鏂瑰紡锛歷-drag="[dragDom,dragHeader]"锛屽 `<div v-drag="['.drag-container .el-dialog', '.drag-container .el-dialog__header']"></div>`
@@ -176,3 +184,37 @@
 		},
 	});
 }
+
+//#region ====================== v-resize ======================
+const resizeMap = new WeakMap();
+const ob = new ResizeObserver((entries) => {
+	for (const entry of entries) {
+		// 鑾峰彇dom鍏冪礌鐨勫洖璋�
+		const handler = resizeMap.get(entry.target);
+		//瀛樺湪鍥炶皟鍑芥暟
+		if (handler) {
+			// 灏嗙洃鍚殑鍊肩粰鍥炶皟鍑芥暟
+			handler({
+				width: entry.borderBoxSize[0].inlineSize,
+				height: entry.borderBoxSize[0].blockSize,
+			});
+		}
+	}
+});
+
+export const elementResizeDirective = (app: App) => {
+	app.directive('resize', {
+		mounted(el: any, binding: any) {
+			//灏哾om涓庡洖璋冪殑鍏崇郴濉炲叆map
+			resizeMap.set(el, binding.value);
+			//鐩戝惉el鍏冪礌鐨勫彉鍖�
+			ob.observe(el);
+		},
+		unmounted(el: any) {
+			//鍙栨秷鐩戝惉
+			ob.unobserve(el);
+		},
+	});
+};
+
+//#endregion

--
Gitblit v1.9.3