lifanagju_citu 4 ماه پیش
والد
کامیت
44685f0ba6
1فایلهای تغییر یافته به همراه17 افزوده شده و 16 حذف شده
  1. 17 16
      src/components/CtTooltip/index.js

+ 17 - 16
src/components/CtTooltip/index.js

@@ -14,9 +14,12 @@ function calculationLocation(el, target, placements) {
 
   el.tooltipPosition.y = 0;
   el.tooltipPosition.x = 0;
-  let el_dom = el.$el?.nextElementSibling?.getBoundingClientRect() || null
-  if (!el_dom) return
+  let el_dom = el.$el?.nextElementSibling?.getBoundingClientRect() || target?.w_tipInstance?.$el?.nextElementSibling?.getBoundingClientRect() || null
   let target_dom = target.getBoundingClientRect()
+  if(!el_dom) {
+    console.log('el_dom:不存在', el_dom)
+    return
+  }
 
   if (placements === "left") {
     el.tooltipPosition.x = target_dom.x - el_dom.width - 10
@@ -87,26 +90,24 @@ export const ellipsisTooltip = localStorage.getItem('useEllipseTooltip') ? {
       if (isOverflow(el)) {
         const directiveList = allPlacements.filter(placement => binding.modifiers[placement])
         const placements = directiveList.length ? directiveList : allPlacements
-        console.log('el.w_tooltip-1:', el.w_tooltip)
-        if (!el.w_tooltip) {
-          // 创建tooltip实例
-          const vm = createApp(MyToolTip)
-          // 创建根元素
-          el.w_tooltip = document.createElement('div')
-          // 挂载到页面
-          document.body.appendChild(el.w_tooltip)
-          el.w_tooltip.id = `tooltip_${Math.floor(Math.random() * 10000)}`
-          el.w_tipInstance = vm.mount(el.w_tooltip)
-        }
-        console.log('el.w_tooltip-2:', el.w_tooltip)
+        console.log('w_tooltip1:', el.w_tooltip)
+        // if (!el.w_tooltip) {}
+        // 创建tooltip实例
+        const vm = createApp(MyToolTip)
+        // 创建根元素
+        el.w_tooltip = document.createElement('div')
+        // 挂载到页面
+        document.body.appendChild(el.w_tooltip)
+        el.w_tooltip.id = `tooltip_${Math.floor(Math.random() * 10000)}`
+        el.w_tipInstance = vm.mount(el.w_tooltip)
+        console.log('w_tooltip2:', el.w_tooltip)
+        console.log('w_tipInstance:', el.w_tipInstance)
         // 设置 tooltip 显示方向
         el.w_tipInstance.placements = placement || placements[0] || 'top'
         // 设置显示内容
         el.w_tipInstance.setContent(content || el.innerText)
         // 使 tooltip 显示
         el.w_tipInstance.showTip()
-        console.log('el:', el)
-        console.log('el.w_tipInstance:', el.w_tipInstance)
         nextTick(() => {
           // 计算 tooltip 在页面中的位置
           calculationLocation(el.w_tipInstance, el, placements[0])