From 1df71bdd7fc5b35be1447c9cc574bf610666f436 Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期一, 14 四月 2025 19:13:11 +0800 Subject: [PATCH] SERVE_URL --- src/directive/customDirective.ts | 71 +++++++++++++++++++++++++++++------ 1 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/directive/customDirective.ts b/src/directive/customDirective.ts index 83738b5..30e025e 100644 --- a/src/directive/customDirective.ts +++ b/src/directive/customDirective.ts @@ -11,17 +11,17 @@ el.classList.add('waves-effect'); binding.value && el.classList.add(`waves-${binding.value}`); function setConvertStyle(obj: { [key: string]: unknown }) { - let style: string = ''; - for (let i in obj) { + let style = ''; + for (const i in obj) { if (obj.hasOwnProperty(i)) style += `${i}:${obj[i]};`; } return style; } function onCurrentClick(e: { [key: string]: unknown }) { - let elDiv = document.createElement('div'); + const elDiv = document.createElement('div'); elDiv.classList.add('waves-ripple'); el.appendChild(elDiv); - let styles = { + const styles = { left: `${e.layerX}px`, top: `${e.layerY}px`, opacity: 1, @@ -53,13 +53,13 @@ }); } -export const eleFocusDirective =(app:App)=>{ - app.directive('elInputFocus',{ - mounted:(el)=>{ - el.querySelector('input.el-input__inner')?.focus() - } - }) -} +export const eleFocusDirective = (app: App) => { + app.directive('elInputFocus', { + mounted: (el) => { + el.querySelector('input.el-input__inner')?.focus(); + }, + }); +}; /** * 鑷畾涔夋嫋鍔ㄦ寚浠� @@ -125,7 +125,7 @@ } function move(e: any, type: string, obj: any) { - let { disX, disY, minDragDomLeft, maxDragDomLeft, minDragDomTop, maxDragDomTop, styL, styT } = obj; + const { disX, disY, minDragDomLeft, maxDragDomLeft, minDragDomTop, maxDragDomTop, styL, styT } = obj; // 閫氳繃浜嬩欢濮旀墭锛岃绠楃Щ鍔ㄧ殑璺濈 let left = type === 'pc' ? e.clientX - disX : e.touches[0].clientX - disX; @@ -184,3 +184,50 @@ }, }); } + +//#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 +//#region ====================== v-focus鎸囦护 ====================== +export const focusDirective = (app: App) => { + app.directive('focus', { + mounted: function (el) { + // 鐢变簬el-input鏄竴涓粍浠讹紝闇�瑕佹壘鍒板唴閮ㄧ殑input鍏冪礌 + const inputEl = el.querySelector('input'); + if (inputEl) { + inputEl.focus(); + } + }, + }); +}; +//#endregion -- Gitblit v1.9.3