sheet_common.js 67 KB

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