背景: 用户需要在单元格中插入使用者的签名图片,需要双击单元格时弹框输入用户名密码,通过校验后将查询到的签名图片插入单元格内。
实现效果图:
关键代码:
- function SWSignCellType(items, size, isHorizontal) {
- this.typeName = "SWSignCellType";
- this.size = size || 10;
- }
- SWSignCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
- SWSignCellType.prototype.paint = function (ctx, value, x, y, w, h, style, context) {
- style = style || new GC.Spread.Sheets.Style();//默认格式
- if (value) {
- // 双击弹窗,用户名密码正确从后端获取图片/数据地址,这里分析返回的数据,拿到图片,设置style.backgroundImage
- var signInfo = value.split("@@");
- var newValue = signInfo[1];//日期
- var signPic = signInfo[2];// 图片地址
- style.hAlign = GC.Spread.Sheets.HorizontalAlign.right;
- style.vAlign = GC.Spread.Sheets.VerticalAlign.center;
- style.backgroundImage = signPic;
- style.backgroundImageLayout = GC.Spread.Sheets.ImageLayout.none;
- style.diagonalUp = undefined;
- spreadNS.CellTypes.Base.prototype.paint.apply(this, [ctx, newValue, x, y, w, h, style, context]);
- } else {
- style.diagonalUp = new GC.Spread.Sheets.LineBorder("black", GC.Spread.Sheets.LineStyle.thin);
- spreadNS.CellTypes.Base.prototype.paint.apply(this, [ctx, "", x, y, w, h, style, context]);
- }
- };
- var swSignCellTypeDialog;
- SWSignCellType.prototype.createEditorElement = function () {
- if (swSignCellTypeDialog === undefined) {
- swSignCellTypeDialog = new designer.SWSignCellTypeDialog();
- }
- swSignCellTypeDialog.open();
- };
- SWSignCellType.prototype.isReservedKey = function (e) {
- //cell type handle tab key by itself
- return (e.keyCode === GC.Spread.Commands.Key.tab && !e.ctrlKey && !e.shiftKey && !e.altKey);
- };
- SWSignCellType.prototype.isEditingValueChanged = function (oldValue, newValue) {
- return oldValue == newValue;
- };
复制代码
|
|