找回密码
 立即注册

QQ登录

只需一步,快速开始

Fiooona
论坛元老   /  发表于:2020-3-11 17:14  /   查看:3221  /  回复:0
背景: 用户需要在单元格中插入使用者的签名图片,需要双击单元格时弹框输入用户名密码,通过校验后将查询到的签名图片插入单元格内。
实现效果图:
image.png340463256.png
关键代码:
  1. function SWSignCellType(items, size, isHorizontal) {
  2.     this.typeName = "SWSignCellType";
  3.     this.size = size || 10;
  4. }
  5. SWSignCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  6. SWSignCellType.prototype.paint = function (ctx, value, x, y, w, h, style, context) {
  7.     style = style || new GC.Spread.Sheets.Style();//默认格式
  8.     if (value) {
  9.         // 双击弹窗,用户名密码正确从后端获取图片/数据地址,这里分析返回的数据,拿到图片,设置style.backgroundImage
  10.         var signInfo = value.split("@@");
  11.         var newValue = signInfo[1];//日期
  12.         var signPic = signInfo[2];// 图片地址

  13.         style.hAlign = GC.Spread.Sheets.HorizontalAlign.right;
  14.         style.vAlign = GC.Spread.Sheets.VerticalAlign.center;
  15.         style.backgroundImage = signPic;
  16.         style.backgroundImageLayout = GC.Spread.Sheets.ImageLayout.none;
  17.         style.diagonalUp = undefined;

  18.         spreadNS.CellTypes.Base.prototype.paint.apply(this, [ctx, newValue, x, y, w, h, style, context]);
  19.     } else {
  20.         style.diagonalUp = new GC.Spread.Sheets.LineBorder("black", GC.Spread.Sheets.LineStyle.thin);
  21.         spreadNS.CellTypes.Base.prototype.paint.apply(this, [ctx, "", x, y, w, h, style, context]);
  22.     }
  23. };
  24. var swSignCellTypeDialog;
  25. SWSignCellType.prototype.createEditorElement = function () {
  26.     if (swSignCellTypeDialog === undefined) {
  27.         swSignCellTypeDialog = new designer.SWSignCellTypeDialog();
  28.     }
  29.     swSignCellTypeDialog.open();
  30. };
  31. SWSignCellType.prototype.isReservedKey = function (e) {
  32.     //cell type handle tab key by itself
  33.     return (e.keyCode === GC.Spread.Commands.Key.tab && !e.ctrlKey && !e.shiftKey && !e.altKey);
  34. };
  35. SWSignCellType.prototype.isEditingValueChanged = function (oldValue, newValue) {
  36.     return oldValue == newValue;
  37. };
复制代码


组件化表格编辑器(预览版)试用进行中,点击了解详情!
请点击评分,对我的服务做出评价!5分为非常满意!

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部