浏览代码

spreadjs悬浮提示,添加最大宽度限制

MaiXinRong 5 年之前
父节点
当前提交
e61808e97b
共有 1 个文件被更改,包括 22 次插入27 次删除
  1. 22 27
      app/public/js/spreadjs_rela/spreadjs_zh.js

+ 22 - 27
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -1003,12 +1003,6 @@ const SpreadJsObj = {
             // 继承 SpreadJs定义的 普通的TextCellType
             TipCellType.prototype = new spreadNS.CellTypes.Text();
             const proto = TipCellType.prototype;
-            const getTextDisplayWidth = function(hitinfo, str) {
-                const xs = hitinfo.sheet.getParent().xs;
-                const ctx = xs.childNodes[0].getContext("2d");
-                ctx.font = hitinfo.cellStyle.font;
-                return ctx.measureText(str).width;
-            };
 
             const showTip = function (hitinfo, text) {
                 return text && text !== '';
@@ -1056,8 +1050,9 @@ const SpreadJsObj = {
                                 .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
                                 .css("font", "9pt Arial")
                                 .css("background", "white")
-                                .css("padding", 5).css("z-index", 99).css("word-wrap", "break-word")
+                                .css("padding", 5).css("z-index", 999).css("word-wrap", "break-word")
                                 .attr("id", 'autoTip');
+                            //$(div).attr("id", "autoTip").attr("class", "sjs-tooltip").css("word-wrap", "break-word");
                             //$(div).hide();
                             document.body.insertBefore(div, null);
                         }
@@ -1131,27 +1126,27 @@ const SpreadJsObj = {
                     text = col.getTip(sortData[hitinfo.row]);
                 }
                 const pos = SpreadJsObj.getObjPos(hitinfo.sheet.getParent().qo);
-                if (!this._toolTipElement) {
-                    let div = $('#autoTip')[0];
-                    if (!div) {
-                        div = document.createElement("div");
-                        $(div).css("position", "absolute")
-                            .css("border", "1px #C0C0C0 solid")
-                            .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
-                            .css("font", "9pt Arial")
-                            .css("background", "white")
-                            .css("padding", 5).css("z-index", 99).css("word-wrap", "break-word")
-                            .attr("id", 'autoTip');
-                        //$(div).hide();
-                        document.body.insertBefore(div, null);
-                    }
-                    this._toolTipElement = div;
-                    const validWidth = Math.min($(window).width() - (pos.x + hitinfo.x + 15) - 10, maxHintWidth);
-                    $(this._toolTipElement).text(text).css("top", pos.y + hitinfo.y + 15).css("left", pos.x + hitinfo.x + 15)
-                        .css("max-width", validWidth);
-                    $(this._toolTipElement).show("fast");
-                }
                 if (pos && showTip(hitinfo, text)) {
+                    if (!this._toolTipElement) {
+                        let div = $('#autoTip')[0];
+                        if (!div) {
+                            div = document.createElement("div");
+                            $(div).css("position", "absolute")
+                                .css("border", "1px #C0C0C0 solid")
+                                .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
+                                .css("font", "9pt Arial")
+                                .css("background", "white")
+                                .css("padding", 5).css("z-index", 999).css("word-wrap", "break-word")
+                                .attr("id", 'autoTip');
+                            //$(div).attr("id", "autoTip").attr("class", "sjs-tooltip");
+                            document.body.insertBefore(div, null);
+                        }
+                        this._toolTipElement = div;
+                        const validWidth = Math.min($(window).width() - (pos.x + hitinfo.x + 15) - 10, maxHintWidth);
+                        $(this._toolTipElement).text(text).css("top", pos.y + hitinfo.y + 15).css("left", pos.x + hitinfo.x + 15)
+                            .css("max-width", validWidth);
+                        $(this._toolTipElement).show("fast");
+                    }
                 }
             };
             /**