本帖最后由 zhouy123456 于 2024-5-9 16:32 编辑
export function MutipHyperLinkPictureCellType(items, size, isHorizontal) {
this.typeName = 'MutipHyperLinkPictureCellType'
this._size = size || 22
this._isHorizontal = isHorizontal || false
this._items = items || []
this._valueArr = []
this._itemsTextWidth = []
this._maxItemTextWidth = 0
this._sumItemTextWidth = 0
this._zoomCatah = 1
this._autofitheight = 0
this._autofitwidth = 0
this.hasPictureSet = false
}
MutipHyperLinkPictureCellType.prototype = new spreadNS.CellTypes.Base()
MutipHyperLinkPictureCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
console.log('paint~~~', x, y, w, h, value, style, options, this.hasPictureSet)
if (this.hasPictureSet && !value) {
this._valueArr = []
const sheet = options.sheet
const textCellType = new window.GC.Spread.Sheets.CellTypes.Text(
window.GC.Spread.Sheets.CellTypes.EditorType.textarea
)
const startRow = sheet.getActiveRowIndex()
const startCol = sheet.getActiveColumnIndex()
sheet.setCellType(startRow, startCol, textCellType)
}
// 保存当前绘图上下文的状态
ctx.save()
// 清除当前单元格区域的内容(如果需要)
ctx.clearRect(x, y, w, h)
if (!value) {
this.hasPictureSet = false
this._valueArr = []
} else {
this.hasPictureSet = true
this._valueArr = []
window.GC.Spread.Sheets.CellTypes.Base.prototype.paint.call(this, ctx, '', x, y, w, h, style, options)
if (!ctx) {
return
}
const sheet = options.sheet
const zoomFactor = sheet.zoom()
const startX = this._getPaintStartX(x, y, w, h, style.hAlign),
startY = this._getPaintStartY(x, y, w, h, style.vAlign)
ctx.save()
ctx.rect(x, y, w, h)
ctx.clip()
ctx.font = style.font
ctx.fillStyle = style.foreColor
this._zoomCatah = zoomFactor
const hyperStyle = new window.GC.Spread.Sheets.Style()
hyperStyle.foreColor = 'blue'
hyperStyle.font = style.font
const backgroundImgStyle = new window.GC.Spread.Sheets.Style()
backgroundImgStyle.backgroundImage = value
const valueObj = {}
valueObj.width = w * 0.8
valueObj.value = value
this._valueArr.push(valueObj)
window.GC.Spread.Sheets.CellTypes.Text.prototype.paint.call(
this,
ctx,
'',
startX,
startY,
w,
h,
backgroundImgStyle,
options
)
}
ctx.restore()
} |