|
@@ -322,6 +322,9 @@ const SpreadJsObj = {
|
|
|
if ((colSpan[i] !== '' && colSpan[i] !== '1') || (rowSpan[i] !== '' && rowSpan[i] !== '1')) {
|
|
|
sheet.addSpan(i, iCol, parseInt(rowSpan[i]), parseInt(colSpan[i]), spreadNS.SheetArea.colHeader);
|
|
|
}
|
|
|
+ if (col.headerCellType) {
|
|
|
+ this._defineColHeader(sheet, cell, col);
|
|
|
+ }
|
|
|
}
|
|
|
sheet.setColumnWidth(iCol, col.width);
|
|
|
if (col.visible !== undefined && col.visible !== null) {
|
|
@@ -391,11 +394,12 @@ const SpreadJsObj = {
|
|
|
sheet.setColumnWidth(i, w, spreadNS.SheetArea.rowHeader);
|
|
|
}
|
|
|
}
|
|
|
+ sheet.extendCellType = {};
|
|
|
+ sheet.extendRowHeader = {};
|
|
|
+ sheet.extendColHeader = {};
|
|
|
this._initSheetDeafult(sheet);
|
|
|
this._initSheetHeader(sheet);
|
|
|
sheet.setRowCount(sheet.zh_setting.emptyRows);
|
|
|
- sheet.extendCellType = {};
|
|
|
- sheet.extendRowHeader = {};
|
|
|
sheet.zh_setting.rowHeader && sheet.zh_setting.rowHeader.forEach(function (col, j) {
|
|
|
self._defineRowHeader(sheet, j, col);
|
|
|
});
|
|
@@ -605,6 +609,14 @@ const SpreadJsObj = {
|
|
|
sheet.getRange(-1, col, -1, 1, spreadNS.SheetArea.rowHeader).cellType(sheet.extendRowHeader.multiTag);
|
|
|
}
|
|
|
},
|
|
|
+ _defineColHeader: function(sheet, cell, colSetting) {
|
|
|
+ if (colSetting.headerCellType === 'tip') {
|
|
|
+ if (!sheet.extendColHeader.tip) {
|
|
|
+ sheet.extendColHeader.tip = this.ColHeader.getTipHeader(colSetting);
|
|
|
+ }
|
|
|
+ cell.cellType(sheet.extendColHeader.tip);
|
|
|
+ }
|
|
|
+ },
|
|
|
_defineColCellType: function (sheet, col, colSetting) {
|
|
|
sheet.AcitveComboRefresh = false;
|
|
|
if(colSetting.cellType === 'ellipsis') {
|
|
@@ -2941,6 +2953,105 @@ const SpreadJsObj = {
|
|
|
},
|
|
|
},
|
|
|
|
|
|
+ ColHeader: {
|
|
|
+ getTipHeader: function () {
|
|
|
+ const maxHintWidth = 200, indent = 15, borderIndent = 10;
|
|
|
+ const TipCellType = function () {};
|
|
|
+ // 继承 SpreadJs定义的 普通的TextCellType
|
|
|
+ TipCellType.prototype = new spreadNS.CellTypes.ColumnHeader();
|
|
|
+ const proto = TipCellType.prototype;
|
|
|
+ proto.getTextDisplayWidth = function(hitinfo, str, font) {
|
|
|
+ const xs = hitinfo.sheet.getParent().xs;
|
|
|
+ const ctx = xs.childNodes[0].getContext("2d");
|
|
|
+ if (font && font !== '') {
|
|
|
+ ctx.font = font;
|
|
|
+ } else {
|
|
|
+ ctx.font = hitinfo.cellStyle.font;
|
|
|
+ }
|
|
|
+ return ctx.measureText(str).width;
|
|
|
+ };
|
|
|
+ proto.showTip = function (hitinfo, text) {
|
|
|
+ return text && text !== '';
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 获取点击信息
|
|
|
+ * @param {Number} x
|
|
|
+ * @param {Number} y
|
|
|
+ * @param {Object} cellStyle
|
|
|
+ * @param {Object} cellRect
|
|
|
+ * @param {Object} context
|
|
|
+ * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
|
|
|
+ */
|
|
|
+ proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
|
|
|
+ return {
|
|
|
+ x: x,
|
|
|
+ y: y,
|
|
|
+ row: context.row,
|
|
|
+ col: context.col,
|
|
|
+ cellStyle: cellStyle,
|
|
|
+ cellRect: cellRect,
|
|
|
+ sheet: context.sheet,
|
|
|
+ sheetArea: context.sheetArea,
|
|
|
+ ctx: context.sheet.getParent().xs,
|
|
|
+ };
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 鼠标进入单元格事件 - 显示悬浮提示
|
|
|
+ * @param {Object} hitinfo - 见getHitInfo返回值
|
|
|
+ */
|
|
|
+ proto.processMouseEnter = function (hitinfo) {
|
|
|
+ let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
|
|
|
+ const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
|
|
|
+ if (col.getHeaderTip && Object.prototype.toString.apply(col.getHeaderTip) === "[object Function]") {
|
|
|
+ text = col.getHeaderTip();
|
|
|
+ }
|
|
|
+ const pos = SpreadJsObj.getObjPos(hitinfo.sheet.getParent().qo);
|
|
|
+ if (pos && this.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("max-width", maxHintWidth)
|
|
|
+ .css("word-wrap", "break-word")
|
|
|
+ .attr("id", 'autoTip');
|
|
|
+ document.body.insertBefore(div, null);
|
|
|
+ }
|
|
|
+ const validWidth = $(window).width() - (pos.x + hitinfo.x + indent) - borderIndent;
|
|
|
+ const textWidth = this.getTextDisplayWidth(hitinfo, text, "9pt Arial");
|
|
|
+ if (validWidth >= maxHintWidth || textWidth <= validWidth) {
|
|
|
+ $(div).html(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x + indent);
|
|
|
+ } else if (textWidth > maxHintWidth) {
|
|
|
+ $(div).html(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x - indent - maxHintWidth);
|
|
|
+ } else {
|
|
|
+ $(div).html(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x - indent - textWidth);
|
|
|
+ }
|
|
|
+ this._toolTipElement = div;
|
|
|
+ $(div).show("fast");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 鼠标移出单元格事件 - 隐藏悬浮提示
|
|
|
+ * @param {Object} hitinfo - 见getHitInfo返回值
|
|
|
+ */
|
|
|
+ proto.processMouseLeave = function (hitinfo) {
|
|
|
+ if (this._toolTipElement) {
|
|
|
+ $(this._toolTipElement).hide();
|
|
|
+ this._toolTipElement = null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return new TipCellType();
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
Formatter: {
|
|
|
baseNumberFormatter: function () {
|
|
|
const formatter = function () {};
|