惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks

秋码分享

我是如何解决将 c++ 编译成可以在 node.js 中使用的 *.node,中间出现的一大堆问题的(指纹浏览器基石篇) eSIM Plus 爱沙尼亚手机号彻底翻车?“永久有效”悄然变成了一年! 接码平台 SMS-Activate 余额可以转移到新平台使用,截止日期:2026年1月29日 是时候将 hugo-theme-kiwi 主题提交到 themes.gohugo.io 站点上了 Flux2 刚开源就凉了?Z-Image 本地部署狠狠打了个样 声音的未来:Chatterbox —— 用「夸张度旋钮」提升表现力的开源 TTS 向导 还以为那只是换个背景?Qwen-Image-Edit 在 ComfyUI 中能做到更离谱的事 Windows 结合最新版 ComfyUI 部署阿里最新开源的 Qwen-Image 图像大模型 从零样本到跨场景:Seed-VC语音转换技术的革命性突破 大语音模型轻量化革命:MegaTTS3 如何重新定义文本生成语音的技术边界(windows篇) 竞赛级编程大模型OlympicCoder-7B之本地部署(Windows篇) 阿里开源了端到端全模态大模型Qwen-2.5-Omini-7B之本地部署(windows篇) 语音识别之whisper本地部署(实时语音之开篇) 甭管是个人还是企业都能部署的Mistral-Small3.1,远超同级别的模型 文生音乐开源项目DiffRhythm,8G显存本地部署之Windows篇 阿里QwQ-32B本地部署指南:用Ollama轻松运行320亿参数大模型 基于Qwen2.5大模型的Spark-TTS,零样本语音克隆,CPU可运行之本地部署(Windows篇) 智谱开源了文生图CogView4-6B模型,支持中文提示词之本地部署(Windows篇) 基于歌词生成整首歌的开源AI音乐模型,支持中、英、日、韩等多种语言,本地化部署YuE(windows篇) 阿里云开源的文生视频万相 Wan2.1之本地部署Wan2.1-T2V-1.3B模型 互动式开源AI图像编辑神器,Windows11本地部署 MagicQuill 本地部署Qwen2.5-VL-7B-Instruct多模态视觉大模型(Windows篇) 保持角色一致性的绘本生成AI开源项目之Story-Adapter本地部署Windows篇 本地部署 Stable Diffusion 3.5(最新 ComfyUI记录篇) 谁说Win7安装不了Node.js最新版的呢?都2025年,还不更新系统到Win11 vs code远程调试Linux服务器上的php代码 浏览器定制 | Windows11 编译 Chromium 133.0.6885.0(截稿前Chromium最新版之编译篇[一]) 不说是彻底搞懂,至少让你不再惧怕c/c++指针,以及各种奇葩指针变种 解决windows下php8.x及以上版本,在Apache2.4中无法加载CURL扩展的问题 在 Windows8.1 下编译 Chromium (103.0.5060.68 之三)
自定义vxe-table表头标题文字过多,显示两行多余省略号并给出...
一个游离于山间之上的江湖漫行者。A jungle wanderer who wanders above the mountain · 2022-06-11 · via 秋码分享

自定义vxe-table表头标题文字过多,显示两行多余省略号并给出tooltip

在上一篇已经实现表头换行,本文将继续实现对含有省略号的标题做出tooltip提示。

最终效果如下图: img

1、首先在body创建一个div

let tooltipDiv = document.createElement('div')
tooltipDiv.setAttribute("class","vxe-table--tooltip-wrapper")
document.body.appendChild(tooltipDiv);

2、对表头添加鼠标移入移出事件

mounted() {
    let that = this
setTimeout( () => {
                const tooltipDom = document.querySelector('.vxe-table--tooltip-wrapper')

                let th =document.querySelectorAll('.vxe-table--header th.vxe-header--column')


                let storeColumn = this.$store.state.autoFilter.columnTitleObj

                for(let i=0;i<th.length;i++){
                    let colid = th[i].getAttribute("colid")
                    let currColumn = that.$refs.table.getColumnById(colid)
                    let isTooltip = false
                    let orgTitle = ''
                    for(let j = 0; j < storeColumn.length; j++){
                        if(storeColumn[j]['prop'] == currColumn['property']){
                            isTooltip = storeColumn[j]['tooltip']
                            orgTitle = storeColumn[j]['orgTitle']
                            break
                        }
                    }

                    if(isTooltip){
                        th[i].addEventListener('mouseenter',(e) => {

                            const { scrollTop, scrollLeft, visibleWidth } = this.$TOOL.getDomNode()
                            const { top, left } = this.$TOOL.getAbsolutePos(e.target)
                            const el = th[i]
                            const marginSize = 6
                            const offsetHeight = el.offsetHeight
                            const offsetWidth = el.offsetWidth
                            let tipLeft = left
                            //let tipTop = top - offsetHeight - marginSize
                            tipLeft = Math.max(marginSize, left + Math.floor((e.target.offsetWidth - offsetWidth) / 2))
                            if (tipLeft + offsetWidth + marginSize > scrollLeft + visibleWidth) {
                                tipLeft = scrollLeft + visibleWidth - offsetWidth - marginSize
                            }
                            if (top - offsetHeight < scrollTop + marginSize) {
                                //tipStore.placement = 'bottom'
                                //tipTop = top + e.target.offsetHeight + marginSize
                            }

                            let arrowLeft = `${left - tipLeft + e.target.offsetWidth / 2}px`


                            tooltipDom.classList.add("theme--dark","size--small","placement--top","is--enterable",
                                "is--visible","is--arrow","is--actived")
                            tooltipDom.setAttribute("style","width:auto;left:"+tipLeft+"px;top:126px;z-index:1000;")

                            tooltipDom.innerHTML = '<div class="vxe-table--tooltip-content">'+orgTitle+'</div><div class="vxe-table--tooltip-arrow" style="left:'+arrowLeft+'"></div>'

                        })

                        th[i].addEventListener( 'mouseleave',() => {
                            console.log('鼠标移出')
                            tooltipDom.classList.remove("placement--top","is--visible","is--actived")
                        })

                    }


                }

            },1500)
}

工具函数

/**
 * 获取某DOM节点的信息
 * @param elem {object} DOM节点
 * @returns {{boundingLeft: number, visibleWidth: *, top: *, left: *, boundingTop: number, visibleHeight: *}}
 */
tool.getAbsolutePos = function(elem){
    const bounding = elem.getBoundingClientRect()
    const boundingTop = bounding.top
    const boundingLeft = bounding.left
    const { scrollTop, scrollLeft, visibleHeight, visibleWidth } = this.getDomNode()
    return { boundingTop, top: scrollTop + boundingTop, boundingLeft, left: scrollLeft + boundingLeft, visibleHeight, visibleWidth }
}
/**
 * 获取body DOM对象相关信息
 * @returns {{visibleWidth: number, visibleHeight: number, scrollLeft: number, scrollTop: number}}
 */
tool.getDomNode = function() {
    const documentElement = document.documentElement
    const bodyElem = document.body
    return {
        scrollTop: documentElement.scrollTop || bodyElem.scrollTop,
        scrollLeft: documentElement.scrollLeft || bodyElem.scrollLeft,
        visibleHeight: documentElement.clientHeight || bodyElem.clientHeight,
        visibleWidth: documentElement.clientWidth || bodyElem.clientWidth
    }
}

在vuex加入

export default {
    state: {
        columnTitleObj: [], //列表头标题
        orgTitle: '', //原表头标题
    },
    mutations:{
        SET_COLUMN_TITLE(state,item){
            state.columnTitleObj = item
        },
        SET_ORG_TITLE(state,item){
            state.orgTitle = item
        },
    }
}

在 resizableChange 方法添加如下内容

resizableChange({column}){
let orgColumn = this.$store.state.autoFilter.columnTitleObj

                for(let i = 0; i < orgColumn.length; i++){
                    if(orgColumn[i].prop == column.property){
                        this.$store.commit("SET_ORG_TITLE", orgColumn[i]['orgTitle'])
                        break
                    }
                }

                let orgTitle = this.$store.state.autoFilter.orgTitle

                let l = orgTitle.length //column.title.length
                let f = 16 //每一个字大小,实际上是每一个字的比例值,大概会比字体大小差很少大一点,


                let subLen = ~~(2 * (Number(column['resizeWidth']) - 30 )) / f

                let lineCount = ~~((Number(column['resizeWidth']) - 30 ) / f)
                let showTextNum = 2 * lineCount


                let isTooltip = false
                if(l > showTextNum){
                    column.title = this.$TOOL.subString(orgTitle,10,true)
                    isTooltip = true


                }else{
                    column.title = this.$TOOL.subString(orgTitle,subLen,false)
                    isTooltip = false

                }

                for(let i = 0; i < orgColumn.length; i++){
                    if(orgColumn[i].prop == column.property){
                        orgColumn[i].tooltip = isTooltip
                        break
                    }
                }

                this.$store.commit("SET_COLUMN_TITLE", orgColumn)
}