sheet_common.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. var sheetCommonObj = {
  5. // CSL.2017.06.05
  6. // createSpread、initSheet 在一个Spread多个Sheet分别调用时的情况下使用。
  7. createSpread: function (container, SheetCount) {
  8. var me = this;
  9. var spreadBook = new GC.Spread.Sheets.Workbook(container, { sheetCount: SheetCount });
  10. spreadBook.options.tabStripVisible = false;
  11. spreadBook.options.showHorizontalScrollbar = true;
  12. spreadBook.options.showVerticalScrollbar = true;
  13. spreadBook.options.allowCopyPasteExcelStyle = false;
  14. spreadBook.options.allowUserDragDrop = true;
  15. spreadBook.options.allowContextMenu = false;
  16. spreadBook.options.allowUserEditFormula = false;
  17. spreadBook.options.showDragFillSmartTag = false;
  18. return spreadBook;
  19. },
  20. initSheet: function(sheet, setting, rowCount) {
  21. var me = this;
  22. var spreadNS = GC.Spread.Sheets;
  23. if(setting.headRows == 2){
  24. return me.buildSpanHeader(sheet, setting);//初始化合并表格列头
  25. }
  26. sheet.suspendPaint();
  27. sheet.suspendEvent();
  28. if(setting.frozenCols) sheet.frozenColumnCount(setting.frozenCols);//冻结列s
  29. sheet.setRowCount(setting.headRows ? setting.headRows : 1, spreadNS.SheetArea.colHeader);
  30. sheet.setColumnCount(setting.header.length, spreadNS.SheetArea.viewport);
  31. if (setting && setting.view && setting.view.colHeaderHeight) {
  32. sheet.setRowHeight(0, setting.view.colHeaderHeight, spreadNS.SheetArea.colHeader);
  33. };
  34. if (setting && setting.view && setting.view.rowHeaderWidth) {
  35. sheet.setColumnWidth(0, setting.view.rowHeaderWidth, spreadNS.SheetArea.rowHeader);
  36. };
  37. if (setting.emptyRowHeader) {
  38. sheet.setColumnWidth(0, 1, GC.Spread.Sheets.SheetArea.rowHeader);
  39. }
  40. sheet.options.colHeaderAutoTextIndex = 1;
  41. sheet.options.colHeaderAutoText = spreadNS.HeaderAutoText.numbers;
  42. sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  43. sheet.options.protectionOptions = {
  44. allowResizeColumns: true
  45. };
  46. sheet.showRowOutline(false);
  47. sheet.options.allowCellOverflow = false;
  48. me.buildHeader(sheet, setting);
  49. sheet.setRowCount(rowCount, spreadNS.SheetArea.viewport);
  50. sheet.resumeEvent();
  51. sheet.resumePaint();
  52. },
  53. // buildSheet 在一个Spread、一个Sheet的情况下使用。
  54. buildSheet: function (container, setting, rowCount) {
  55. var me = this;
  56. var spreadBook = me.createSpread(container, { sheetCount: 1 });
  57. var sheet = spreadBook.getSheet(0);
  58. me.initSheet(sheet, setting, rowCount);
  59. return spreadBook;
  60. },
  61. buildSpanHeader:function (sheet, setting) {
  62. let temSetting = {
  63. "emptyRows":0,
  64. "headRows":2,
  65. "headRowHeight":[21],
  66. "defaultRowHeight": 21,
  67. "treeCol": 0,
  68. "cols":[]
  69. };
  70. let spanSetting = sheetCommonObj.transferToTreeSetting(setting,temSetting);
  71. TREE_SHEET_HELPER.loadSheetHeader(spanSetting, sheet);
  72. },
  73. buildHeader: function (sheet, setting) {
  74. var me = this, ch = GC.Spread.Sheets.SheetArea.colHeader;
  75. for (var i = 0; i < setting.header.length; i++) {
  76. sheet.setValue(0, i, setting.header[i].headerName, ch);
  77. sheet.getCell(0, i, ch).wordWrap(true);
  78. sheet.setColumnWidth(i, setting.header[i].headerWidth ? setting.header[i].headerWidth : 100);
  79. sheet.setColumnVisible(i, setting.header[i].visible === false ? false : true);
  80. }
  81. },
  82. cleanSheet: function (sheet, setting, rowCount) {
  83. sheet.suspendPaint();
  84. sheet.suspendEvent();
  85. sheet.clear(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  86. if (rowCount > 0) sheet.setRowCount(rowCount);
  87. sheet.clearSelection();
  88. sheet.resumeEvent();
  89. sheet.resumePaint();
  90. },
  91. cleanData: function (sheet, setting, rowCount) {
  92. sheet.suspendPaint();
  93. sheet.suspendEvent();
  94. sheet.clear(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  95. if (rowCount > 0) sheet.setRowCount(rowCount);
  96. sheet.resumeEvent();
  97. sheet.resumePaint();
  98. },
  99. setAreaAlign: function (area, hAlign, vAlign) {
  100. if (!(hAlign) || hAlign === "left") {
  101. area.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  102. } else if (hAlign === "right") {
  103. area.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
  104. } else if (hAlign === "center") {
  105. area.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  106. } else {
  107. area.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  108. }
  109. if (!(vAlign) || vAlign === "center") {
  110. area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  111. } else if (vAlign === "top") {
  112. area.vAlign(GC.Spread.Sheets.VerticalAlign.top);
  113. } else if (vAlign === "bottom") {
  114. area.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
  115. } else {
  116. area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  117. }
  118. },
  119. showData: function (sheet, setting, data, distTypeTree, callback) {//这个callback是为了在showdata后还做了引起重画表格的操作,在callback里调用能提高效率
  120. var me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
  121. sheet.suspendPaint();
  122. sheet.suspendEvent();
  123. //sheet.addRows(row, 1);
  124. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  125. if (sheet.getRowCount() < data.length) {
  126. data.length < 30 ? sheet.setRowCount(30) : sheet.setRowCount(data.length);
  127. } else if (sheet.getRowCount() == 0) {
  128. sheet.setRowCount(30);
  129. }
  130. for (var col = 0; col < setting.header.length; col++) {
  131. var hAlign = "left", vAlign = "center";
  132. if (setting.header[col].hAlign) {
  133. hAlign = setting.header[col].hAlign;
  134. } else if (setting.header[col].dataType !== "String") {
  135. hAlign = "right";
  136. }
  137. vAlign = setting.header[col].vAlign ? setting.header[col].vAlign : vAlign;
  138. me.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  139. if (setting.header[col].formatter) {
  140. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  141. }
  142. /* 直接在showrowdata时当val为null时返回一个text类型的单元格
  143. if (setting.header[col].cellType === "checkBox" || setting.header[col].cellType === "button") {//clear and reset
  144. var me = this, header = GC.Spread.Sheets.SheetArea.colHeader;
  145. sheet.deleteColumns(col, 1);
  146. sheet.addColumns(col, 1);
  147. sheet.setValue(0, col, setting.header[col].headerName, header);
  148. sheet.setColumnWidth(col, setting.header[col].headerWidth ? setting.header[col].headerWidth : 100);
  149. } */
  150. if (setting.header[col].visible !== null && setting.header[col].visible !== undefined) {
  151. sheet.setColumnVisible(col, setting.header[col].visible);
  152. }
  153. sheet.getCell(0, col, GC.Spread.Sheets.SheetArea.colHeader).wordWrap(true);
  154. }
  155. for (var row = 0; row < data.length; row++) {
  156. //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
  157. this.showRowData(sheet, setting, row, data, distTypeTree);
  158. }
  159. if (setting.emptyRowHeader) {
  160. let rowCount = sheet.getRowCount();
  161. for (let row = 0; row < rowCount; row++) {
  162. sheet.setValue(row, 0, '', GC.Spread.Sheets.SheetArea.rowHeader);
  163. }
  164. }
  165. this.lockCells(sheet, setting);
  166. if (callback) callback();
  167. sheet.resumeEvent();
  168. sheet.resumePaint();
  169. //me.shieldAllCells(sheet);
  170. },
  171. showRowData: function (sheet, setting, row, data, distTypeTree = null) {
  172. let ch = GC.Spread.Sheets.SheetArea.viewport;
  173. for (var col = 0; col < setting.header.length; col++) {
  174. //var cell = sheet.getCell(row, col, GC.Spread.Sheets.SheetArea.viewport);
  175. var val = _.get(data[row],setting.header[col].dataCode);
  176. if (val && setting.header[col].dataType === "Number") {
  177. if (setting.header[col].hasOwnProperty('tofix')) {
  178. val = scMathUtil.roundToString(val, setting.header[col].tofix);
  179. }
  180. else if (setting.header[col].hasOwnProperty('decimalField')) {
  181. var decimal = getDecimal(setting.header[col].decimalField);
  182. val = scMathUtil.roundToString(val, decimal);
  183. sheet.setFormatter(-1, col, getFormatter(decimal), GC.Spread.Sheets.SheetArea.viewport);
  184. } else {
  185. val = val + '';
  186. }
  187. }
  188. if (setting.header[col].cellType === "checkBox") {
  189. this.setCheckBoxCell(row, col, sheet, val)
  190. }
  191. if (setting.header[col].cellType === "comboBox") {
  192. this.setComboBox(row, col, sheet, setting.header[col].options, setting.header[col].editorValueType, setting.header[col].editable, setting.header[col].maxDropDownItems);
  193. }
  194. if (setting.header[col].cellType === "selectButton") {
  195. this.setSelectButton(row, col, sheet, setting.header[col]);
  196. }
  197. if (setting.header[col].cellType === "replaceButton") {
  198. this.setReplaceButton(row, col, sheet, setting.header[col]);
  199. }
  200. if (setting.header[col].cellType === "cusButton") {
  201. this.setCusButton(row, col, sheet, setting);
  202. }
  203. if (setting.header[col].cellType === "tipsCell") {
  204. this.setTipsCell(row, col, sheet);
  205. }
  206. if (setting.owner === 'gljTree') {
  207. if (setting.header[col].cellType === "checkBox") {
  208. val= val == 1 ? val : 0;
  209. this.setCheckBoxCell(row, col, sheet, val);
  210. }
  211. if (setting.header[col].dataCode === 'gljType' && data[row].gljType) {
  212. let distTypeVal = distTypeTree.distTypes[distTypeTree.prefix + data[row].gljType].data.fullName;
  213. val = distTypeVal;
  214. }
  215. }
  216. if(setting.setCellType) setting.setCellType(sheet,data[row],row,col)
  217. if (setting.header[col].getText) {
  218. val = setting.getText[setting.header[col].getText](data[row], val)
  219. }
  220. sheet.setValue(row, col, val, ch);
  221. }
  222. this.setRowStyle(row, sheet, data[row].bgColour);
  223. if (setting.autoFit == true) {//设置自动行高
  224. if (setting.fitRow && setting.fitRow.length > 0) {//如果有设置特定的某些列才需要自动行高就按设置的来,没有设置就默认所有列
  225. for (let dataCode of setting.fitRow) {
  226. let col = _.findIndex(setting.header, { dataCode: dataCode });
  227. sheet.getCell(row, col).wordWrap(true);
  228. }
  229. } else {
  230. sheet.getRange(row, -1, 1, -1, GC.Spread.Sheets.SheetArea.viewport).wordWrap(true);
  231. }
  232. sheet.autoFitRow(row);
  233. }
  234. if (setting.getStyle && setting.getStyle(data[row], row, sheet.getActiveRowIndex())) {
  235. sheet.setStyle(row, -1, setting.getStyle(data[row]));
  236. }
  237. },
  238. showTreeData:function (sheet,setting,data) {
  239. let ch = GC.Spread.Sheets.SheetArea.viewport;
  240. let parentMap=_.groupBy(data, 'ParentID');
  241. let visibleMap = {};
  242. let styleRow=[];
  243. let treeCol = setting.treeCol?setting.treeCol:0;
  244. sheet.suspendPaint();
  245. sheet.suspendEvent();
  246. sheet.setRowCount(data.length);
  247. for (let col = 0; col < setting.header.length; col++) {
  248. let hAlign = "left", vAlign = "center";
  249. if (setting.header[col].hAlign) {
  250. hAlign = setting.header[col].hAlign;
  251. } else if (setting.header[col].dataType !== "String"){
  252. hAlign = "right";
  253. }
  254. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  255. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  256. if (setting.header[col].formatter) {
  257. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  258. }
  259. if(setting.header[col].cellType === "comboBox"){
  260. this.setComboBox(-1,col,sheet,setting.header[col].options,setting.header[col].editorValueType,setting.header[col].editable,setting.header[col].maxDropDownItems);
  261. }
  262. for (let row = 0; row < data.length; row++) {
  263. if(data[row].cellType === 'comboBox'){
  264. let options = data[row].options ? data[row].options.split("@") : [];
  265. this.setComboBox(row,col,sheet,options);
  266. }else if(data[row].cellType === 'String'){//默认设置字符输入,避免出现输入10:01变成日期的情况
  267. sheet.setFormatter(row, col,"@", GC.Spread.Sheets.SheetArea.viewport);
  268. }
  269. let val = data[row][setting.header[col].dataCode];
  270. if(val&&setting.header[col].dataType === "Number"){
  271. if(setting.header[col].hasOwnProperty('decimalField')){
  272. let decimal = getDecimal(setting.header[col].decimalField);
  273. val =scMathUtil.roundToString(val,decimal);
  274. sheet.setFormatter(-1, col,getFormatter(decimal), GC.Spread.Sheets.SheetArea.viewport);
  275. }else {
  276. val = val + '';
  277. }
  278. }
  279. if(val!=null && setting.header[col].cellType == "checkBox"){
  280. this.setCheckBoxCell(row,col,sheet,val);
  281. }
  282. if(setting.header[col].getText) {
  283. val = setting.getText[setting.header[col].getText](data[row], val)
  284. }
  285. sheet.setValue(row, col, val, ch);
  286. if(col==treeCol){
  287. let treeType = sheetCommonObj.getTreeNodeCellType(data,row,parentMap,treeCol);
  288. sheet.getCell(row, col).cellType(treeType);
  289. visibleMap[data[row].ID] = treeType.collapsed;
  290. this.setRowVisible(data,row,visibleMap,sheet);
  291. }
  292. if(data[row].bgColour) styleRow.push(row)
  293. }
  294. }
  295. for(let r of styleRow){
  296. this.setRowStyle(r,sheet,data[r].bgColour);
  297. }
  298. this.lockCells(sheet,setting);
  299. sheet.resumeEvent();
  300. sheet.resumePaint();
  301. },
  302. setRowVisible:function (data,row,visibleMap,sheet) {
  303. sheet.getRange(row , -1, 1, -1).visible(getVisible(data[row].ParentID));//显示或隐藏
  304. function getVisible(ParentID) {
  305. if(visibleMap[ParentID]) return false //如果父节点是缩起的,那就隐藏本身。
  306. if(visibleMap[ParentID] == false){//如果父节点不是缩起的,要再往父节点找看
  307. let pnode = _.find(data,{'ID':ParentID});
  308. if(pnode) return getVisible(pnode.ParentID);//如果有父节点,递归调用
  309. return true;//没有,返回显示
  310. }
  311. }
  312. },
  313. checkData: function (col, setting, value) {
  314. let result = true;
  315. let validator = setting.header[col].validator !== undefined ? setting.header[col].validator : null;
  316. if (validator === null) {
  317. return result;
  318. }
  319. switch (validator) {
  320. case 'number':
  321. let regular = /^\d+(\.\d+)?$/;
  322. result = regular.test(value);
  323. break;
  324. case 'boolean':
  325. let booleanValue = [true, false];
  326. result = booleanValue.indexOf(value) >= 0;
  327. break;
  328. }
  329. return result;
  330. },
  331. analyzePasteData: function (setting, pastedInfo) {
  332. var rst = [], propId = pastedInfo.cellRange.col, preStrIdx = 0, itemObj = {};//propId = 0 to proId = pastedInfo.cellRange.col, update by zhong
  333. for (var i = 0; i < pastedInfo.pasteData.text.length; i++) {
  334. if (pastedInfo.pasteData.text[i] === "\n") {
  335. propId = pastedInfo.cellRange.col;//propId = 0 to proId = pastedInfo.cellRange.col, update by zhong
  336. preStrIdx = i + 1;
  337. rst.push(itemObj);
  338. if (i < pastedInfo.pasteData.text.length - 1) {
  339. itemObj = {};
  340. }
  341. } else if (pastedInfo.pasteData.text[i] === "\t" || pastedInfo.pasteData.text[i] === "\r") {
  342. if (setting.header[propId]) {
  343. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx, i);
  344. }
  345. propId++;
  346. preStrIdx = i + 1;
  347. //if the last copied-cell were empty, should check whether the end of text
  348. if (i == pastedInfo.pasteData.text.length - 1 && setting.header[propId]) {
  349. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx);
  350. rst.push(itemObj);
  351. }
  352. } else if (i == pastedInfo.pasteData.text.length - 1 && setting.header[propId]) {
  353. itemObj[setting.header[propId].dataCode] = pastedInfo.pasteData.text.slice(preStrIdx);
  354. rst.push(itemObj);
  355. }
  356. }
  357. return rst;
  358. },
  359. combineRowData: function (sheet, setting, row) {
  360. var rst = {};
  361. for (var col = 0; col < setting.header.length; col++) {
  362. rst[setting.header[col].dataCode] = sheet.getValue(row, col);
  363. }
  364. return rst;
  365. },
  366. shieldAllCells: function (sheet) {
  367. sheet.options.isProtected = true;
  368. },
  369. unShieldAllCells: function (sheet) {
  370. sheet.options.isProtected = false;
  371. },
  372. lockCells: function (sheet, setting) {
  373. if (setting && setting.view.lockColumns && setting.view.lockColumns.length > 0) {
  374. sheet.options.isProtected = true;
  375. sheet.getRange(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  376. for (var i = 0; i < setting.view.lockColumns.length; i++) {
  377. let col = setting.view.lockColumns[i];
  378. if (_.isString(col)) {//如果是dataCode 进行转换
  379. col = _.findIndex(setting.header, { dataCode: col })
  380. }
  381. sheet.getRange(-1, col, -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(true);
  382. }
  383. }
  384. },
  385. setCheckBoxCell(row, col, sheet, val) {
  386. var c = val==null?new GC.Spread.Sheets.CellTypes.Text():new GC.Spread.Sheets.CellTypes.CheckBox();
  387. if(val != null) c.isThreeState(false);
  388. sheet.setCellType(row, col, c, GC.Spread.Sheets.SheetArea.viewport);
  389. sheet.getCell(row, col).value(val);
  390. sheet.getCell(row, col).hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  391. },
  392. getCheckBox(threeState = false){
  393. var c = new GC.Spread.Sheets.CellTypes.CheckBox();
  394. c.isThreeState(threeState);
  395. return c
  396. },
  397. // 无法勾选的复选框
  398. getReadOnlyCheckBox () {
  399. function ReadOnlyCheckBox() {}
  400. ReadOnlyCheckBox.prototype = new GC.Spread.Sheets.CellTypes.CheckBox();
  401. ReadOnlyCheckBox.prototype.processMouseUp = function () {
  402. return;
  403. };
  404. return new ReadOnlyCheckBox();
  405. },
  406. setComboBox(row, col, sheet, options, editorValueType, editable, maxDropDownItems) {
  407. //let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  408. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  409. if (options) {
  410. dynamicCombo.items(options);
  411. if (editorValueType == true) {
  412. dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  413. }
  414. if (editable) dynamicCombo.editable(true);
  415. if (maxDropDownItems) dynamicCombo.maxDropDownItems(maxDropDownItems);
  416. }
  417. sheet.setCellType(row, col, dynamicCombo, GC.Spread.Sheets.SheetArea.viewport);
  418. },
  419. setRowStyle(row, sheet, bgColour) {
  420. if (bgColour) {
  421. let style = new GC.Spread.Sheets.Style();
  422. style.backColor = bgColour;
  423. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  424. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  425. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  426. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  427. sheet.setStyle(row, -1, style);
  428. }
  429. },
  430. getCustomerCoeCellType: function (htmlGenerator, setEditorValue, updateCallback) {
  431. let me = this;
  432. function CustomerCoeCellType() {
  433. this.isEscKey = false;
  434. this.displayText = '';
  435. }
  436. CustomerCoeCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  437. CustomerCoeCellType.prototype.createEditorElement = function (context) {
  438. console.log("create editor")
  439. let element = document.createElement("div");//这里创建的,会自动销毁
  440. return element
  441. };
  442. CustomerCoeCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
  443. if (editorContext) {
  444. $editor = $(editorContext);
  445. $editor.css("position", "fixed");
  446. $editor.css("background", "white");
  447. //$editor.css("width", cellRect.width); 2018-11-15 改成固定列宽
  448. $editor.css("width", 160);
  449. $editor.attr("gcUIElement", "gcEditingInput");
  450. if (htmlGenerator) htmlGenerator(context, cellRect, $editor);
  451. }
  452. }
  453. CustomerCoeCellType.prototype.deactivateEditor = function (editorContext, context) {
  454. };
  455. CustomerCoeCellType.prototype.setEditorValue = function (editor, value, context) {
  456. console.log("set editor value");
  457. this.displayText = value;
  458. };
  459. CustomerCoeCellType.prototype.getEditorValue = function (editor, context) {
  460. console.log("get value");
  461. if (this.isEscKey != true && updateCallback) {
  462. updateCallback();
  463. }
  464. this.isEscKey = false;
  465. return this.displayText;
  466. };
  467. CustomerCoeCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
  468. console.log(" update editor");
  469. if (setEditorValue) {//不是esc时才更新
  470. setEditorValue(context);
  471. }
  472. };
  473. CustomerCoeCellType.prototype.isReservedKey = function (e, context) {
  474. //cell type handle tab key by itself
  475. this.isEscKey = e.keyCode === GC.Spread.Commands.Key.esc;
  476. return false;
  477. };
  478. return new CustomerCoeCellType();
  479. },
  480. scrollSheetForOption: function (sheet, cxt, cellRect, row, options) {
  481. let topRow = sheet.getViewportTopRow(1);
  482. if (row == topRow) return;//已经是最顶行了
  483. let length = options && options.length > 0 ? options.length : 1;
  484. let height = cxt.canvas.height;
  485. let startY = cellRect.y + cellRect.height;//下拉框的起始显示位置
  486. let endY = startY + length * cellRect.height;//下拉框的结束显示位置
  487. if (endY <= height) return; //如果没有超出显示位置,直接返回
  488. let overRow = Math.ceil((endY - height) / cellRect.height);//超出的行数
  489. let showRow = topRow + overRow > row ? row : topRow + overRow;
  490. sheet.showRow(showRow, GC.Spread.Sheets.VerticalPosition.top);
  491. },
  492. setSelectButton(row, col, sheet, header) {
  493. sheet.setCellType(row, col, this.getSelectButton(header.headerWidth), GC.Spread.Sheets.SheetArea.viewport);
  494. },
  495. getSelectButton(cellWidth = 100) {
  496. function moreButton() {
  497. }
  498. moreButton.prototype = new GC.Spread.Sheets.CellTypes.Button();
  499. moreButton.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  500. GC.Spread.Sheets.CellTypes.Button.prototype.paint.call(this, ctx, value, x, y, w, h, style, options);
  501. ctx.font = '14px Calibri';
  502. let buttonW = cellWidth / 5;
  503. let endX = x + w - 2;
  504. if (value) {
  505. let textWidth = ctx.measureText(value).width;
  506. let spaceWidth = cellWidth - buttonW;
  507. let textEndX = x + textWidth + 2;
  508. if (spaceWidth < textWidth) {
  509. for (let i = value.length - 1; i > 1; i--) {
  510. let newValue = value.substr(0, i);
  511. let newTestWidth = ctx.measureText(newValue).width;
  512. if (spaceWidth > newTestWidth) {
  513. value = newValue;
  514. textEndX = x + newTestWidth + 2;
  515. break;
  516. }
  517. }
  518. }
  519. ctx.fillText(value, textEndX, y + h - 6);
  520. }
  521. //画三个点
  522. ctx.save();
  523. ctx.beginPath();
  524. ctx.arc(endX - buttonW / 2, y + h / 2, 1, 0, 360, false);
  525. ctx.arc(endX - buttonW / 2 - 4, y + h / 2, 1, 0, 360, false);
  526. ctx.arc(endX - buttonW / 2 + 4, y + h / 2, 1, 0, 360, false);
  527. ctx.fillStyle = "black";//填充颜色,默认是黑色
  528. ctx.fill();//画实心圆
  529. ctx.closePath();
  530. ctx.restore();
  531. };
  532. moreButton.prototype.processMouseLeave = function (hitinfo) {
  533. let newCell = new selectButton();
  534. hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, newCell, GC.Spread.Sheets.SheetArea.viewport);
  535. hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(false);
  536. };
  537. function selectButton() {
  538. }
  539. selectButton.prototype = new GC.Spread.Sheets.CellTypes.Text();
  540. selectButton.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  541. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  542. };
  543. selectButton.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  544. return {
  545. x: x,
  546. y: y,
  547. row: context.row,
  548. col: context.col,
  549. cellStyle: cellStyle,
  550. cellRect: cellRect,
  551. sheetArea: context.sheetArea
  552. };
  553. };
  554. selectButton.prototype.processMouseDown = function (hitinfo) {
  555. if (hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked() != true) {
  556. let b1 = new moreButton();
  557. b1.marginLeft(cellWidth * 4 / 5);
  558. hitinfo.sheet.setCellType(hitinfo.row, hitinfo.col, b1, GC.Spread.Sheets.SheetArea.viewport);
  559. hitinfo.sheet.getCell(hitinfo.row, hitinfo.col).locked(true);
  560. }
  561. };
  562. return new selectButton();
  563. },
  564. setCusButton: function (row, col, sheet, setting) {
  565. let functionName = setting.header[col].callback;
  566. let readOnly = setting.disable[setting.header[col].disable];
  567. if (typeof (readOnly) == 'function') {
  568. readOnly = readOnly(row, col);
  569. }
  570. if (functionName) {
  571. sheet.setCellType(row, col, this.getCusButtonCellType(setting.callback[functionName], readOnly));
  572. }
  573. //sheet.setCellType(row, col,this.getSelectButton(header.headerWidth),GC.Spread.Sheets.SheetArea.viewport);
  574. },
  575. getCusButtonCellType: function (callback, readOnly = false) {
  576. var ns = GC.Spread.Sheets;
  577. function CusButtonCellType() {
  578. }
  579. CusButtonCellType.prototype = new ns.CellTypes.Text();
  580. CusButtonCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  581. if (!readOnly) {
  582. if (options.sheet.getActiveRowIndex() == options.row && options.sheet.getActiveColumnIndex() == options.col) {
  583. var image = document.getElementById('f_btn'), imageMagin = 3;
  584. var imageHeight = 15;
  585. var imageWidth = 25;
  586. var imageX = x + w - imageWidth - imageMagin, imageY = y + h / 2 - imageHeight / 2;
  587. ctx.save();
  588. if (style.backColor) {
  589. ctx.fillStyle = style.backColor;
  590. ctx.fillRect(x, y, w, h);
  591. }
  592. ctx.drawImage(image, imageX, imageY, imageWidth, imageHeight);
  593. ctx.beginPath();
  594. ctx.arc(imageX + imageWidth / 2, imageY + imageHeight / 2, 1, 0, 360, false);
  595. ctx.arc(imageX + imageWidth / 2 - 4, imageY + imageHeight / 2, 1, 0, 360, false);
  596. ctx.arc(imageX + imageWidth / 2 + 4, imageY + imageHeight / 2, 1, 0, 360, false);
  597. ctx.fillStyle = "black";//填充颜色,默认是黑色
  598. ctx.fill();//画实心圆
  599. ctx.closePath();
  600. ctx.restore();
  601. w = w - imageWidth - imageMagin;
  602. //这里的左对齐的,当显示的字长度超过空白地方时,要改成右对齐
  603. if (style.hAlign == 0) {
  604. if (value) {
  605. let textWidth = ctx.measureText(value).width;
  606. let spaceWidth = w;
  607. if (spaceWidth < textWidth) {
  608. style.hAlign = 2;
  609. }
  610. }
  611. }
  612. }
  613. }
  614. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  615. };
  616. CusButtonCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  617. return {
  618. x: x,
  619. y: y,
  620. row: context.row,
  621. col: context.col,
  622. cellStyle: cellStyle,
  623. cellRect: cellRect,
  624. sheetArea: context.sheetArea
  625. };
  626. };
  627. CusButtonCellType.prototype.processMouseDown = function (hitinfo) {
  628. if (hitinfo.sheet.getActiveRowIndex() == hitinfo.row && hitinfo.sheet.getActiveColumnIndex() == hitinfo.col) {
  629. var offset = hitinfo.cellRect.x + hitinfo.cellRect.width - 6;
  630. var imageWidth = 25;
  631. if (hitinfo.x < offset && hitinfo.x > offset - imageWidth) {
  632. if (!readOnly) {
  633. if (callback) callback(hitinfo)
  634. }
  635. }
  636. }
  637. };
  638. return new CusButtonCellType();
  639. },
  640. setReplaceButton(row, col, sheet) {
  641. let replaceButton = function () {
  642. };
  643. replaceButton.prototype = new GC.Spread.Sheets.CellTypes.Button();
  644. replaceButton.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  645. GC.Spread.Sheets.CellTypes.Button.prototype.paint.apply(this, arguments);
  646. if (value) {
  647. ctx.save();
  648. ctx.fillStyle = "white";
  649. let fh = options.fontInfo && options.fontInfo.fontSize ? options.fontInfo.fontSize : h - 6;
  650. ctx.fillText(value, x + (w + ctx.measureText(value).width) / 2, y + (h + fh) / 2 - 2);
  651. ctx.restore();
  652. }
  653. };
  654. let cellType = new replaceButton();
  655. cellType.buttonBackColor("#07A0FF");
  656. sheet.setCellType(row, col, cellType, GC.Spread.Sheets.SheetArea.viewport);
  657. },
  658. setTipsCell(row, col, sheet,tips) {
  659. let TipCellType = function () { };
  660. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  661. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  662. return {
  663. x: x,
  664. y: y,
  665. row: context.row,
  666. col: context.col,
  667. cellStyle: cellStyle,
  668. cellRect: cellRect,
  669. sheet: context.sheet,
  670. sheetArea: context.sheetArea
  671. };
  672. };
  673. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  674. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  675. console.log(tips);
  676. let setting = {};
  677. if(!tips){
  678. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  679. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  680. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  681. zoom = hitinfo.sheet.zoom();
  682. let textLength = this.getAutoFitWidth(value, text, acStyle, zoom, { sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport });
  683. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  684. if (textLength <= cellWidth) {
  685. return;
  686. }
  687. }
  688. text = tips;
  689. if (sheet && sheet.getParent().qo) {
  690. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  691. }
  692. TREE_SHEET_HELPER.showTipsDiv(text, setting, hitinfo);
  693. };
  694. TipCellType.prototype.processMouseLeave = function (hitinfo) {
  695. TREE_SHEET_HELPER.tipDiv = 'hide';
  696. if (TREE_SHEET_HELPER._toolTipElement) {
  697. $(TREE_SHEET_HELPER._toolTipElement).hide();
  698. TREE_SHEET_HELPER._toolTipElement = null;
  699. };
  700. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  701. };
  702. sheet.setCellType(row, col, new TipCellType(), GC.Spread.Sheets.SheetArea.viewport);
  703. },
  704. chkIfEmpty: function (rObj, setting) {
  705. var rst = true;
  706. if (rObj) {
  707. for (var i = 0; i < setting.header.length; i++) {
  708. if (rObj[setting.header[i].dataCode]) {
  709. rst = false;
  710. break;
  711. }
  712. }
  713. }
  714. return rst;
  715. },
  716. //add by zhong 2017-10-10
  717. //动态下拉框,配合EnterCell, args.sheet.repaint();
  718. getDynamicCombo: function (forLocked) {
  719. let ComboCellForActiveCell = function () { };
  720. ComboCellForActiveCell.prototype = new GC.Spread.Sheets.CellTypes.ComboBox();
  721. ComboCellForActiveCell.prototype.paintValue = function (ctx, value, x, y, w, h, style, options) {
  722. let sheet = options.sheet;
  723. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex() && (!forLocked || forLocked && !sheet.getCell(options.row, options.col).locked())) {
  724. GC.Spread.Sheets.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
  725. } else {
  726. GC.Spread.Sheets.CellTypes.Base.prototype.paintValue.apply(this, arguments);
  727. }
  728. };
  729. ComboCellForActiveCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, options) {
  730. let sheet = options.sheet;
  731. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex() && (!forLocked || forLocked && !sheet.getCell(options.row, options.col).locked())) {
  732. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  733. } else {
  734. return {
  735. x: x,
  736. y: y,
  737. row: options.row,
  738. col: options.col,
  739. cellStyle: cellStyle,
  740. cellRect: cellRect,
  741. sheetArea: options.sheetArea
  742. };//GC.Spread.Sheets.CellTypes.Text.prototype.getHitInfo.apply(this, arguments);
  743. }
  744. };
  745. return new ComboCellForActiveCell();
  746. },
  747. getTipsCell: function (baseCell, cellPrototype, tips, setting, node) {
  748. let getTipsCell = function () {
  749. this.clickCom=false;
  750. };
  751. getTipsCell.prototype = baseCell;
  752. if(tips && tips !=""){
  753. getTipsCell.prototype.processMouseEnter = function(hitinfo){
  754. if(this.clickCom == true){ //点击了下拉框的三角形,则不用再显示悬浮框了
  755. this.clickCom = false;
  756. return;
  757. }
  758. let text = typeof tips == 'function'?tips(node):tips;
  759. TREE_SHEET_HELPER.delayShowTips(hitinfo,setting,text);
  760. };
  761. getTipsCell.prototype.processMouseLeave = function (hitinfo) {
  762. TREE_SHEET_HELPER.hideTipsDiv();
  763. };
  764. getTipsCell.prototype.processMouseDown = function (hitinfo){
  765. if(hitinfo.isReservedLocation == true){//这里是点击了下拉框的三角形才会有这个属性
  766. TREE_SHEET_HELPER.hideTipsDiv();
  767. this.clickCom = true;
  768. }
  769. cellPrototype.processMouseDown.apply(this, arguments);
  770. };
  771. getTipsCell.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context){
  772. TREE_SHEET_HELPER.hideTipsDiv();
  773. cellPrototype.updateEditor.apply(this, arguments);
  774. };
  775. }
  776. return new getTipsCell();
  777. },
  778. getTipsText: function (tips, setting, node) {
  779. function baseTextCell() {}
  780. baseTextCell.prototype = new GC.Spread.Sheets.CellTypes.Text();
  781. baseTextCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  782. return {
  783. x: x,
  784. y: y,
  785. row: context.row,
  786. col: context.col,
  787. cellStyle: cellStyle,
  788. cellRect: cellRect,
  789. sheetArea: context.sheetArea
  790. };
  791. };
  792. return this.getTipsCell(new baseTextCell(), GC.Spread.Sheets.CellTypes.Text.prototype, tips, setting, node);
  793. },
  794. getTipsCombo:function (forLocked,tips,setting,node) {
  795. const baseCell = sheetCommonObj.getDynamicCombo(forLocked);
  796. return this.getTipsCell(baseCell, GC.Spread.Sheets.CellTypes.ComboBox.prototype, tips, setting, node);
  797. },
  798. /* getTipsCombo: function (forLocked, tips, setting, node) {
  799. let getTipsCombo = function () {
  800. this.clickCom = false;
  801. };
  802. getTipsCombo.prototype = sheetCommonObj.getDynamicCombo(forLocked);
  803. if (tips && tips != "") {
  804. getTipsCombo.prototype.processMouseEnter = function (hitinfo) {
  805. if (this.clickCom == true) { //点击了下拉框的三角形,则不用再显示悬浮框了
  806. this.clickCom = false;
  807. return;
  808. }
  809. let text = typeof tips == 'function' ? tips(node) : tips;
  810. TREE_SHEET_HELPER.delayShowTips(hitinfo, setting, text);
  811. };
  812. getTipsCombo.prototype.processMouseLeave = function (hitinfo) {
  813. TREE_SHEET_HELPER.hideTipsDiv();
  814. };
  815. getTipsCombo.prototype.processMouseDown = function (hitinfo) {
  816. if (hitinfo.isReservedLocation == true) {//这里是点击了下拉框的三角形才会有这个属性
  817. TREE_SHEET_HELPER.hideTipsDiv();
  818. this.clickCom = true;
  819. }
  820. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
  821. };
  822. getTipsCombo.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
  823. TREE_SHEET_HELPER.hideTipsDiv();
  824. GC.Spread.Sheets.CellTypes.ComboBox.prototype.updateEditor.apply(this, arguments);
  825. };
  826. }
  827. return new getTipsCombo();
  828. }, */
  829. getTreeNodeCellType: function (datas, row, parentMap,treeCol, paintFunc,tips) {// 2018-09-26 不用spreadjs默认的树结构,自定义控件
  830. var ns = GC.Spread.Sheets;
  831. let rectW = 10;
  832. let rectH = 10;
  833. let margin = 3;
  834. function TreeNodeCellType() {
  835. this.collapsed = gljUtil.isDef(datas[row].collapsed) ? datas[row].collapsed : true; //默认是折叠的
  836. this.treeNodeType = true;
  837. this.rectInfo = {};
  838. }
  839. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  840. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  841. if (paintFunc) {
  842. paintFunc(ctx, value, x, y, w, h, style, { rectW, rectH, margin }, datas[row]);
  843. }
  844. let offset = 0;
  845. let step = 7;
  846. let level = getTreeLevel(datas[row], datas);//从0开始,取当前节点是第几级的
  847. let tem = offset + margin + rectW / 2 + step;//两条线之间的间隔
  848. let t_offset = offset;
  849. let temParentID = datas[row].ParentID;
  850. if (this.treeNodeType == true) {
  851. for (let i = level; i > 0; i--) {//这里是画子节点前面的竖线,从第二级开始
  852. let temParent = getParent(temParentID, datas);
  853. if (temParent) {//父节点有下一个兄弟节点才需要画
  854. if (hasNextBrother(parentMap, temParent)) sheetCommonObj.drawLine(ctx, x + t_offset + tem * i, y, x + t_offset + tem * i, y + h);
  855. temParentID = temParent.ParentID;
  856. }
  857. offset += tem;
  858. }
  859. }
  860. offset += step; //这个没法移动,所以要两个判断
  861. if (this.treeNodeType == true) {
  862. if (hasChildern(datas[row].ID, datas)) {//如果是有子节点
  863. //第一条 或者没有父节点(如费率子表综合里程项)不用画方框头上那条竖线其它都要
  864. if (row != 0 && gljUtil.isDef(datas[row].ParentID)) sheetCommonObj.drawLine(ctx, x + offset + rectW / 2 + margin, y, x + offset + rectW / 2 + margin, y + Math.round(h / 2) - rectH / 2);
  865. //画方框下面的那条竖线,如果没有下一个兄弟节点,则不用画
  866. if (hasNextBrother(parentMap, datas[row])) sheetCommonObj.drawLine(ctx, x + offset + rectW / 2 + margin, y + Math.round(h / 2) + rectH / 2, x + offset + rectW / 2 + margin, y + h);
  867. sheetCommonObj.drowRect(ctx, x + offset, y, w, h, rectW, rectH, margin);
  868. sheetCommonObj.drowSymbol(ctx, x + offset, y, w, h, rectW, rectH, margin, this.collapsed);
  869. this.rectInfo = { x: x + offset + margin, rectW: rectW }//计录一下可点击位置
  870. } else {
  871. let hasNext = datas[row + 1] ? datas[row + 1].ParentID == datas[row].ParentID : false;
  872. sheetCommonObj.drowSubItem(ctx, x, y, w, h, offset, hasNext, margin + rectW / 2);
  873. }
  874. }
  875. offset += step;
  876. offset += rectW;
  877. x = x + offset;//设置偏移
  878. w = w - offset;
  879. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  880. };
  881. // override getHitInfo to allow cell type get mouse messages
  882. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  883. return {
  884. x: x,
  885. y: y,
  886. row: context.row,
  887. col: context.col,
  888. cellStyle: cellStyle,
  889. cellRect: cellRect,
  890. sheetArea: context.sheetArea
  891. };
  892. }
  893. if(tips){
  894. TreeNodeCellType.prototype.processMouseEnter = function (hitinfo) {
  895. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  896. let setting = {};
  897. text = tips;
  898. if (hitinfo.sheet && hitinfo.sheet.getParent().qo) {
  899. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  900. }
  901. TREE_SHEET_HELPER.showTipsDiv(text, setting, hitinfo);
  902. };
  903. TreeNodeCellType.prototype.processMouseLeave = function (hitinfo) {
  904. TREE_SHEET_HELPER.tipDiv = 'hide';
  905. if (TREE_SHEET_HELPER._toolTipElement) {
  906. $(TREE_SHEET_HELPER._toolTipElement).hide();
  907. TREE_SHEET_HELPER._toolTipElement = null;
  908. };
  909. TREE_SHEET_HELPER.tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  910. };
  911. }
  912. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  913. ////方框外1像素内都有效
  914. if (!_.isEmpty(this.rectInfo) && Math.floor(hitinfo.x) <= this.rectInfo.x + this.rectInfo.rectW + 2 && Math.floor(hitinfo.x) >= this.rectInfo.x - 2) {
  915. this.collapsed = !this.collapsed;
  916. datas[row].collapsed = this.collapsed;
  917. this.refreshChildrenVisible(hitinfo.sheet);
  918. hitinfo.sheet.invalidateLayout();
  919. hitinfo.sheet.repaint();
  920. }
  921. };
  922. TreeNodeCellType.prototype.refreshChildrenVisible = function (sheet) {
  923. sheet.suspendPaint();
  924. sheet.suspendEvent();
  925. refreshVisible(datas[row]);
  926. sheet.resumeEvent();
  927. sheet.resumePaint();
  928. function refreshVisible(item) {
  929. if (parentMap[item.ID]) {
  930. for (let sub of parentMap[item.ID]) {
  931. refreshVisible(sub)
  932. }
  933. }
  934. let visible = getVisible(item);
  935. let trow = datas.indexOf(item);
  936. sheet.getRange(trow, -1, 1, -1).visible(visible);
  937. }
  938. function getVisible(item) {
  939. if (item.ParentID) {
  940. let parent = getParent(item.ParentID, datas);
  941. if (!parent) return true;
  942. let p_row = datas.indexOf(parent);
  943. treeCol = treeCol?treeCol:0;
  944. let visible = !sheet.getCellType(p_row, treeCol).collapsed;
  945. if (visible == true) { //如果是显示的,则要再往父节点的父节点检查,只要有一个节点是隐藏的,则都是隐藏
  946. return getVisible(parent);
  947. } else {
  948. return visible
  949. }
  950. } else {//如果parentID 为空则是最根节点
  951. return true;
  952. }
  953. }
  954. };
  955. return new TreeNodeCellType()
  956. function getTreeLevel(item, data) {
  957. if (item.ParentID && item.ParentID!=-1) {
  958. let pitem = _.find(data, { 'ID': item.ParentID });
  959. return getTreeLevel(pitem, data) + 1;
  960. } else {
  961. return 0
  962. }
  963. }
  964. function hasChildern(ID, data) {//返回是否有子项
  965. let p = _.find(data, { 'ParentID': ID });
  966. if (p) return true;
  967. return false
  968. }
  969. function getParent(ParentID, data) {
  970. let p = _.find(data, { 'ID': ParentID });
  971. return p;
  972. }
  973. function hasNextBrother(parentMap, item) {
  974. let children = parentMap[item.ParentID];
  975. if (!gljUtil.isDef(children) || children.indexOf(item) == children.length - 1) return false;
  976. return true
  977. }
  978. },
  979. setDynamicCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
  980. let me = this;
  981. sheet.suspendPaint();
  982. let combo = me.getDynamicCombo();
  983. for (let i = 0, len = rowCount; i < len; i++) {
  984. if (itemsHeight) {
  985. combo.itemHeight(itemsHeight);
  986. combo._maxDropDownItems = itemsHeight + 5;
  987. }
  988. if (itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  989. else if (itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
  990. else combo.items(items);
  991. sheet.getCell(beginRow + i, col).cellType(combo);
  992. }
  993. sheet.resumePaint();
  994. },
  995. setStaticCombo: function (sheet, beginRow, col, rowCount, items, itemsHeight, itemsType) {
  996. sheet.suspendPaint();
  997. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  998. for (let i = 0, len = rowCount; i < len; i++) {
  999. if (itemsHeight) combo.itemHeight(itemsHeight);
  1000. if (itemsType === 'value') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1001. else if (itemsType === 'text') combo.items(items).editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.text);
  1002. else combo.items(items);
  1003. sheet.getCell(beginRow + i, col).cellType(combo);
  1004. }
  1005. sheet.resumePaint();
  1006. },
  1007. //设置系统粘贴板数据,需要用户触发事件,直接调用会失败
  1008. copyTextToClipboard: function (text) {
  1009. let textArea = document.createElement("textarea");
  1010. textArea.style.position = 'fixed';
  1011. textArea.style.top = 0;
  1012. textArea.style.left = 0;
  1013. textArea.style.width = '2em';
  1014. textArea.style.height = '2em';
  1015. textArea.style.padding = 0;
  1016. textArea.style.border = 'none';
  1017. textArea.style.outline = 'none';
  1018. textArea.style.boxShadow = 'none';
  1019. textArea.style.background = 'transparent';
  1020. textArea.value = text;
  1021. document.body.appendChild(textArea);
  1022. textArea.select();
  1023. try {
  1024. let successful = document.execCommand('copy');
  1025. let msg = successful ? 'successful' : 'unsuccessful';
  1026. console.log('Copying text command was ' + msg);
  1027. } catch (err) {
  1028. console.log('Oops, unable to copy');
  1029. }
  1030. document.body.removeChild(textArea);
  1031. },
  1032. //获取选中区域的表格类型数据(可粘贴到excel)
  1033. getTableData: function (sheet, colSettings = null) {
  1034. let rst = '';
  1035. let sel = sheet.getSelections()[0];
  1036. let pasteText = [];
  1037. for (let row = sel.row; row < sel.row + sel.rowCount; row++) {
  1038. if (!sheet.getCell(row, -1).visible())
  1039. continue;
  1040. let rowText = [];
  1041. for (let j = 0; j < sel.colCount; j++) {
  1042. let col = sel.col + j;
  1043. if (!sheet.getCell(-1, col).visible())
  1044. continue;
  1045. if (colSettings && (colSettings[col]['data']['field'] === 'itemCharacterText' || colSettings[col]['data']['field'] === 'jobContentText'))
  1046. rowText.push(sheet.getText(row, col) ? `"${sheet.getText(row, col)}"` : '');
  1047. else
  1048. rowText.push(sheet.getText(row, col) ? sheet.getText(row, col) : '');
  1049. }
  1050. pasteText.push(rowText.join('\t'));
  1051. }
  1052. return pasteText.join('\n');
  1053. },
  1054. transferToTreeSetting: function (setting, treeSetting, treeCol) {
  1055. for (let h of setting.header) {
  1056. treeSetting.cols.push(getSettingCol(h))
  1057. }
  1058. for (let l of setting.view.lockColumns) {
  1059. treeSetting.cols[l].readOnly = true;
  1060. }
  1061. return treeSetting;
  1062. function getSettingCol(header) {
  1063. let aMap = { left: 0, center: 1, right: 2 };
  1064. let hAlign = header.hAlign ? aMap[header.hAlign] : 0;
  1065. let col = {
  1066. "width": header.headerWidth ? header.headerWidth : 100,
  1067. "head": {
  1068. "titleNames": Array.isArray(header.headerName) ? header.headerName : [header.headerName],
  1069. "spanCols": header.spanCols ? header.spanCols : [1],
  1070. "spanRows": header.spanRows ? header.spanRows : [1],
  1071. "vAlign": [1],
  1072. "hAlign": [1],
  1073. "font": ["Arial"]
  1074. },
  1075. "data": {
  1076. "field": header.dataCode,
  1077. "vAlign": 1,
  1078. "hAlign": hAlign,
  1079. "font": "Arial"
  1080. }
  1081. };
  1082. if (header.showHint == true) {
  1083. col.showHint = true;
  1084. }
  1085. if (header.cellType) {
  1086. col.data.cellType = getCellType(header);
  1087. }
  1088. if (header.decimalField) {//设置formatter
  1089. let decimal = getDecimal(header.decimalField);
  1090. col.formatter = getFormatter(decimal);
  1091. }
  1092. if (header.getText && treeCol) {
  1093. col.data.getText = treeCol.getEvent(header.getText);
  1094. }
  1095. /*col.readOnly = function (node) {
  1096. if(node.data.ParentID == -1 || node.data.id == 'GJ'){//三材类别项不能编辑)
  1097. return true;
  1098. }
  1099. return false;
  1100. };*/
  1101. return col;
  1102. }
  1103. function getCellType(header) {
  1104. return function () {
  1105. if (header.cellType === "checkBox") {
  1106. return new GC.Spread.Sheets.CellTypes.CheckBox();
  1107. }
  1108. if (header.cellType === "comboBox") {
  1109. let dynamicCombo = sheetCommonObj.getDynamicCombo(true);
  1110. if (header.options) {
  1111. dynamicCombo.itemHeight(header.options.length).items(header.options);
  1112. if (header.editorValueType == true) {
  1113. dynamicCombo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1114. }
  1115. }
  1116. return dynamicCombo
  1117. }
  1118. }
  1119. }
  1120. },
  1121. //注册自定义回车键事件
  1122. bindEnterKey: function (workBook, operation) {
  1123. workBook.commandManager().register('myEnter', operation);
  1124. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
  1125. workBook.commandManager().setShortcutKey('myEnter', GC.Spread.Commands.Key.enter, false, false, false, false);
  1126. },
  1127. //解决esc后触发了编辑结束的保存事件,显示与实际数据不同问题
  1128. bindEscKey: function (workBook, sheets) {
  1129. function isDef(v) {
  1130. return typeof v !== 'undefined' && v !== null;
  1131. }
  1132. workBook.commandManager().register('myEsc', function () {
  1133. let activeSheet = workBook.getActiveSheet();
  1134. let hasTheSheet = false;
  1135. for (let sheetObj of sheets) {
  1136. let sheet = sheetObj.sheet;
  1137. if (sheet === activeSheet) {
  1138. hasTheSheet = true;
  1139. let editStarting = sheetObj.editStarting;
  1140. let editEnded = sheetObj.editEnded;
  1141. if (editStarting) {
  1142. sheet.unbind(GC.Spread.Sheets.Events.EditStarting);
  1143. }
  1144. if (editEnded) {
  1145. sheet.unbind(GC.Spread.Sheets.Events.EditEnded);
  1146. }
  1147. let row = sheet.getActiveRowIndex();
  1148. let col = sheet.getActiveColumnIndex();
  1149. let orgV = sheet.getValue(row, col);
  1150. let orgText = sheet.getText(row, col);
  1151. if (!isDef(orgV)) {
  1152. orgV = '';
  1153. }
  1154. if (sheet.isEditing()) {
  1155. sheet.endEdit();
  1156. sheet.setValue(row, col, orgV);
  1157. }
  1158. if (editStarting) {
  1159. sheet.bind(GC.Spread.Sheets.Events.EditStarting, editStarting);
  1160. }
  1161. if (editEnded) {
  1162. sheet.bind(GC.Spread.Sheets.Events.EditEnded, editEnded);
  1163. }
  1164. }
  1165. }
  1166. //容错处理,以防没把所有工作簿的表格信息传入参数
  1167. if (!hasTheSheet) {
  1168. if (activeSheet.isEditing()) {
  1169. activeSheet.endEdit();
  1170. }
  1171. }
  1172. });
  1173. workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.esc, false, false, false, false);
  1174. workBook.commandManager().setShortcutKey('myEsc', GC.Spread.Commands.Key.esc, false, false, false, false);
  1175. },
  1176. //设置默认样式
  1177. spreadDefaultStyle: function (workBook) {
  1178. let defaultStyle = new GC.Spread.Sheets.Style();
  1179. defaultStyle.font = '14px Calibri';
  1180. let sheetCount = workBook.getSheetCount();
  1181. for (let i = 0; i < sheetCount; i++) {
  1182. let sheet = workBook.getSheet(i);
  1183. sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.viewport);
  1184. sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.colHeader);
  1185. sheet.setDefaultStyle(defaultStyle, GC.Spread.Sheets.SheetArea.rowHeader);
  1186. }
  1187. },
  1188. //动态根据工作簿宽度和各列宽度比例设置宽度
  1189. setColumnWidthByRate: function (workBookWidth, workBook, headers) {
  1190. if (workBook) {
  1191. const sheet = workBook.getActiveSheet();
  1192. sheet.suspendEvent();
  1193. sheet.suspendPaint();
  1194. for (let col = 0; col < headers.length; col++) {
  1195. if (headers[col]['rateWidth'] !== undefined && headers[col]['rateWidth'] !== null && headers[col]['rateWidth'] !== '') {
  1196. sheet.setColumnWidth(col, workBookWidth * headers[col]['rateWidth'], GC.Spread.Sheets.SheetArea.colHeader)
  1197. }
  1198. else {
  1199. if (headers[col]['headerWidth'] !== undefined && headers[col]['headerWidth'] !== null && headers[col]['headerWidth'] !== '') {
  1200. sheet.setColumnWidth(col, headers[col]['headerWidth'], GC.Spread.Sheets.SheetArea.colHeader)
  1201. }
  1202. }
  1203. }
  1204. sheet.resumeEvent();
  1205. sheet.resumePaint();
  1206. }
  1207. },
  1208. drowRect: function (ctx, x, y, w, h, rectW, rectH, margin) {
  1209. ctx.save();
  1210. ctx.strokeStyle = "gray";
  1211. ctx.translate(0.5, 0.5);
  1212. ctx.beginPath();
  1213. let rectX = x + margin;
  1214. let rectY = y + Math.round(h / 2) - rectH / 2;
  1215. ctx.moveTo(rectX, rectY);
  1216. ctx.lineTo(rectX, rectY + rectH);
  1217. ctx.lineTo(rectX + rectW, rectY + rectH);
  1218. ctx.lineTo(rectX + rectW, rectY);
  1219. ctx.lineTo(rectX, rectY);
  1220. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1221. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1222. ctx.stroke();
  1223. ctx.restore();
  1224. },
  1225. drawLine: function (ctx, x1, y1, x2, y2, color) {
  1226. let l_color = color ? color : "#ababab";
  1227. ctx.save();
  1228. ctx.translate(0.5, 0.5);
  1229. ctx.beginPath();
  1230. ctx.moveTo(x1, y1);
  1231. ctx.lineTo(x2, y2);
  1232. ctx.strokeStyle = l_color;
  1233. ctx.stroke();
  1234. ctx.restore();
  1235. },
  1236. drowSymbol: function (ctx, x, y, w, h, rectW, rectH, margin, collapsed) {
  1237. ctx.save();
  1238. ctx.strokeStyle = "#000000";
  1239. ctx.translate(0.5, 0.5);
  1240. ctx.beginPath();
  1241. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1242. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1243. let rectY = y + Math.round(h / 2) - rectH / 2;
  1244. if (collapsed) {
  1245. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1246. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1247. }
  1248. ctx.stroke();
  1249. ctx.restore();
  1250. },
  1251. drowTriangle: function (ctx, x, y) {//画向下三角形
  1252. ctx.save();
  1253. ctx.fillStyle = "black";
  1254. ctx.beginPath();
  1255. ctx.moveTo(x, y);
  1256. ctx.lineTo(x - 3, y - 6);
  1257. ctx.lineTo(x + 3, y - 6);
  1258. ctx.fill();
  1259. ctx.restore();
  1260. },
  1261. drowSubItem: function (ctx, x, y, w, h, offset, hasNext, step) {
  1262. let t_step = step ? step : 6;
  1263. offset += t_step;
  1264. ctx.save();
  1265. ctx.strokeStyle = "#ababab";
  1266. ctx.translate(0.5, 0.5);
  1267. ctx.beginPath();
  1268. ctx.moveTo(x + offset, y);
  1269. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1270. offset += 9;
  1271. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1272. if (hasNext) {
  1273. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1274. ctx.lineTo(x + offset - 9, y + h);
  1275. }
  1276. ctx.stroke();
  1277. ctx.restore();
  1278. return offset;
  1279. },
  1280. checkData: function (col, setting, value) {
  1281. let result = true;
  1282. let validator = setting.header[col].validator !== undefined ? setting.header[col].validator : null;
  1283. if (validator === null) {
  1284. return result;
  1285. }
  1286. switch (validator) {
  1287. case 'number':
  1288. let regular = /^\d+(\.\d+)?$/;
  1289. result = regular.test(value);
  1290. break;
  1291. case 'boolean':
  1292. let booleanValue = [true, false];
  1293. result = booleanValue.indexOf(value) >= 0;
  1294. break;
  1295. }
  1296. return result;
  1297. },
  1298. getSelectedRecode: function (sheet, datas) {
  1299. let sel = sheet.getSelections()[0];
  1300. let srow = sel.row == -1 || sel.row == "" ? 0 : sel.row;
  1301. if (gljUtil.isDef(srow) && datas.length > srow) {
  1302. return datas[srow];
  1303. }
  1304. return null;
  1305. },
  1306. disableSpread(spread) {
  1307. spread.unbind(GC.Spread.Sheets.Events.ButtonClicked);
  1308. let sheetCount = spread.getSheetCount();
  1309. for(let i = 0; i < sheetCount; i++){
  1310. let sheet = spread.getSheet(i);
  1311. sheet.unbind(GC.Spread.Sheets.Events.ButtonClicked);
  1312. sheet.unbind(GC.Spread.Sheets.Events.EditStarting);
  1313. sheet.unbind(GC.Spread.Sheets.Events.EditEnded);
  1314. sheet.unbind(GC.Spread.Sheets.Events.RangeChanged);
  1315. sheet.unbind(GC.Spread.Sheets.Events.ClipboardChanging);
  1316. sheet.unbind(GC.Spread.Sheets.Events.ClipboardChanged);
  1317. sheet.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
  1318. sheet.unbind(GC.Spread.Sheets.Events.CellClick);
  1319. sheet.unbind(GC.Spread.Sheets.Events.ValueChanged);
  1320. sheet.suspendPaint();
  1321. sheet.suspendEvent();
  1322. sheet.options.isProtected = true;
  1323. let rowCount = sheet.getRowCount();
  1324. let colCount = sheet.getColumnCount();
  1325. for(let row = 0; row < rowCount; row++){
  1326. for(let col = 0; col < colCount; col++){
  1327. sheet.getCell(row, col).locked(true);
  1328. }
  1329. }
  1330. sheet.resumePaint();
  1331. sheet.resumeEvent();
  1332. }
  1333. },
  1334. // 延迟一段时间刷新表格,因为有的弹窗里面有表格,马上刷新可能会造成,弹窗界面还未完全显示完就完成了表格刷新,导致表格显示不完整
  1335. refreshWorkbookDelDefer(workbook, time) {
  1336. if (workbook) {
  1337. setTimeout(() => workbook.refresh(), time);
  1338. }
  1339. },
  1340. setRowsAutoFit(sheet, rows, col, wordWrap) {
  1341. rows.forEach(row => {
  1342. sheet.getCell(row, col).wordWrap(wordWrap);
  1343. sheet.autoFitRow(row);
  1344. });
  1345. },
  1346. // 获取带输入框的右键子目
  1347. registerInputContextMenuItem(name, html, icon, callback) {
  1348. $.contextMenu.types[name] = function (item, opt, root) {
  1349. // 因为contextMenu有自己的键盘事件处理,因此输入框的键盘控制光标需要自己定义事件实现覆盖。
  1350. const Direction = {
  1351. BACKWARD: 'backward',
  1352. FORWARD: 'forward'
  1353. };
  1354. function moveLeft(input, isShifting) {
  1355. const start = input.selectionStart;
  1356. const end = input.selectionEnd;
  1357. const direction = end === start ? Direction.BACKWARD : input.selectionDirection;
  1358. if (isShifting) {
  1359. if (direction === Direction.FORWARD) {
  1360. const curEnd = end - 1;
  1361. input.setSelectionRange(start, curEnd);
  1362. } else {
  1363. const curStart = start - 1 < 0 ? 0 : start - 1;
  1364. input.setSelectionRange(curStart, end, Direction.BACKWARD);
  1365. }
  1366. } else {
  1367. const idx = end > start
  1368. ? start
  1369. : start - 1 < 0
  1370. ? 0
  1371. : start - 1;
  1372. input.setSelectionRange(idx, idx);
  1373. }
  1374. }
  1375. function moveRight(input, isShifting) {
  1376. const start = input.selectionStart;
  1377. const end = input.selectionEnd;
  1378. const direction = start === end ? Direction.FORWARD : input.selectionDirection;
  1379. if (isShifting) {
  1380. if (direction === Direction.BACKWARD) {
  1381. const curStart = start + 1;
  1382. input.setSelectionRange(curStart, end);
  1383. } else {
  1384. const curEnd = end + 1;
  1385. input.setSelectionRange(start, curEnd, Direction.FORWARD);
  1386. }
  1387. } else {
  1388. const idx = start < end
  1389. ? end
  1390. : end + 1
  1391. input.setSelectionRange(idx, idx);
  1392. }
  1393. }
  1394. function handleConfirm() {
  1395. if (callback) {
  1396. callback();
  1397. }
  1398. root.$menu.trigger('contextmenu:hide');
  1399. }
  1400. $(html)
  1401. .appendTo(this)
  1402. .on('input', 'input', function () {
  1403. const number = +$(this).val();
  1404. if (isNaN(number)) {
  1405. $(this).val(1);
  1406. } else if (number > 99) {
  1407. $(this).val(99);
  1408. }
  1409. })
  1410. .on('keydown', 'input', function (e) {
  1411. const key = e.key;
  1412. if (key === 'ArrowUp' || key === 'ArrowDown') {
  1413. return false;
  1414. }
  1415. if (key === 'Enter') {
  1416. handleConfirm();
  1417. return false;
  1418. }
  1419. const input = $(this)[0];
  1420. if (key === 'ArrowLeft') {
  1421. moveLeft(input, e.shiftKey);
  1422. } else if (key === 'ArrowRight') {
  1423. moveRight(input, e.shiftKey);
  1424. }
  1425. })
  1426. .parent().on('click', function (e) {
  1427. if (e.target.tagName === 'INPUT') {
  1428. return false;
  1429. }
  1430. handleConfirm();
  1431. });
  1432. this.addClass(`context-menu-icon context-menu-icon--fa fa ${icon}`);
  1433. };
  1434. return name;
  1435. }
  1436. }