Xiao_123 3 months ago
parent
commit
4a96114cb1
1 changed files with 13 additions and 4 deletions
  1. 13 4
      src/components/CtTooltip/index.js

+ 13 - 4
src/components/CtTooltip/index.js

@@ -14,8 +14,13 @@ function calculationLocation(el, target, placements) {
 
   el.tooltipPosition.y = 0;
   el.tooltipPosition.x = 0;
-  let el_dom = el.$el?.nextElementSibling?.getBoundingClientRect() || target?.w_tipInstance?.$el?.nextElementSibling?.getBoundingClientRect() || null
+  // let el_dom = el.$el?.nextElementSibling?.getBoundingClientRect() || target?.w_tipInstance?.$el?.nextElementSibling?.getBoundingClientRect() || null
+
+  const parent_dom = el?.$el ? el.$el?.nextElementSibling?.getBoundingClientRect() : el._.vnode.el
+  let el_dom = parent_dom || target?.w_tipInstance?.$el?.nextElementSibling?.getBoundingClientRect() || null
+
   let target_dom = target.getBoundingClientRect()
+  console.log(parent_dom, el_dom, el, target, placements, '位置定位')
   if(!el_dom) {
     // console.log('el_dom:不存在', el_dom)
     return
@@ -95,7 +100,7 @@ export const ellipsisTooltip = {
       if (isOverflow(el)) {
         const directiveList = allPlacements.filter(placement => binding.modifiers[placement])
         const placements = directiveList.length ? directiveList : allPlacements
-        console.log('w_tooltip1:', el.w_tooltip)
+        // console.log('w_tooltip1:', el.w_tooltip)
         // if (!el.w_tooltip) {}
         // 创建tooltip实例
         const vm = createApp(MyToolTip)
@@ -105,14 +110,18 @@ export const ellipsisTooltip = {
         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)
+        // console.log('w_tooltip2:', el.w_tooltip)
         // 设置 tooltip 显示方向
         el.w_tipInstance.placements = placement || placements[0] || 'top'
         // 设置显示内容
         el.w_tipInstance.setContent(content || el.innerText)
         // 使 tooltip 显示
         el.w_tipInstance.showTip()
+        
+        
+        // console.log('w_tipInstance:', el.w_tipInstance, el, placements[0])
+
+
         nextTick(() => {
           // 计算 tooltip 在页面中的位置
           calculationLocation(el.w_tipInstance, el, placements[0])