spreadjs_zh.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  1. /**
  2. * Spreadjs 通用方法集
  3. *
  4. * @author Mai
  5. * @date 2018/02/06
  6. * @version
  7. */
  8. // 定义画点线的方法
  9. const proto = window.CanvasRenderingContext2D && CanvasRenderingContext2D.prototype;
  10. proto.dottedLine = function (x1, y1, x2, y2, interval = 4) {
  11. const isHorizontal = x1 == x2 ? false : true;
  12. const dotLen = 1;
  13. let len = isHorizontal ? x2 - x1 : y2 - y1;
  14. this.moveTo(x1, y1);
  15. let progress = 0;
  16. while (len > progress) {
  17. if (progress > len) { progress = len; }
  18. if (isHorizontal) {
  19. this.moveTo(x1 + progress, y1);
  20. this.lineTo(x1 + progress + dotLen, y1);
  21. } else {
  22. this.moveTo(x1, y1 + progress);
  23. this.lineTo(x1, y1 + progress + dotLen);
  24. }
  25. progress += interval;
  26. }
  27. };
  28. // 简写Spread常量
  29. const spreadNS = GC.Spread.Sheets;
  30. // 授权码
  31. spreadNS.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";
  32. // SpreadJs常用方法
  33. const SpreadJsObj = {
  34. initSpreadSettingEvents: function (setting, events) {
  35. const getEvent = function (eventName) {
  36. const names = eventName.split('.');
  37. let event = events;
  38. for (let name of names) {
  39. if (event[name]) {
  40. event = event[name];
  41. } else {
  42. return null;
  43. }
  44. }
  45. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  46. return null;
  47. } else {
  48. return event;
  49. }
  50. };
  51. for (const col of setting.cols) {
  52. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  53. col.readOnly = getEvent(col.readOnly);
  54. }
  55. if (col.getValue && Object.prototype.toString.apply(col.getValue) === "[object String]") {
  56. col.getValue = getEvent(col.getValue);
  57. }
  58. }
  59. },
  60. DataType: {
  61. Data: 'data',
  62. Tree: 'tree',
  63. },
  64. /**
  65. * 创建Spread(默认1张表,3行数据)
  66. * @param obj 用于创建spreadjs的Dom元素
  67. * @returns {GC.Spread.Sheets.Workbook}
  68. */
  69. createNewSpread: function (obj) {
  70. const spread = new spreadNS.Workbook(obj, {sheetCount: 1});
  71. spread.options.tabStripVisible = false;
  72. spread.options.scrollbarMaxAlign = true;
  73. spread.options.cutCopyIndicatorVisible = false;
  74. spread.options.allowCopyPasteExcelStyle = false;
  75. spread.options.allowUserDragDrop = false;
  76. spread.options.allowUserEditFormula = false;
  77. spread.options.allowExtendPasteRange = true;
  78. spread.options.copyPasteHeaderOptions = spreadNS.CopyPasteHeaderOptions.noHeaders;
  79. spread.getActiveSheet().options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;//设置粘贴时只粘贴值
  80. spread.getActiveSheet().setRowCount(3);
  81. return spread;
  82. },
  83. addCutEvents: function (spread, fun) {
  84. const cut = spreadNS.Commands.cut.execute;
  85. spreadNS.Commands.cut.execute = function (context, options, isUndo) {
  86. const self = this, sheet = context.getActiveSheet();
  87. const sels = sheet.getSelections();
  88. const sel = sels ? sels[0] : null;
  89. if (sel) {
  90. return fun(sheet, sel, function () {
  91. cut(context, options, isUndo);
  92. });
  93. }
  94. }
  95. },
  96. /**
  97. * 保护sheet(需设置保护后, 单元格的locked等属性方可生效)
  98. * @param {GC.Spread.Sheets.Worksheet} sheet
  99. */
  100. protectedSheet: function (sheet) {
  101. const option = {
  102. allowSelectLockedCells: true,
  103. allowSelectUnlockedCells: true,
  104. allowResizeRows: true,
  105. allowResizeColumns: true
  106. };
  107. sheet.options.protectionOptions = option;
  108. sheet.options.isProtected = true;
  109. sheet.options.allowCellOverflow = false;
  110. },
  111. /**
  112. * sheet批量操作优化(sheet操作大批量数据时, 屏蔽数据刷新, 可优化大量时间)
  113. * @param {GC.Spread.Sheets.Worksheet} sheet
  114. * @param {function} operation
  115. */
  116. beginMassOperation: function (sheet) {
  117. sheet.suspendPaint();
  118. sheet.suspendEvent();
  119. },
  120. endMassOperation: function (sheet) {
  121. sheet.resumeEvent();
  122. sheet.resumePaint();
  123. },
  124. massOperationSheet: function (sheet, operation) {
  125. this.beginMassOperation(sheet);
  126. operation();
  127. this.endMassOperation(sheet);
  128. },
  129. /**
  130. * 获取Obj左顶点位置(部分功能需通过spreadjs左顶点位置计算)
  131. * @param obj
  132. * @returns {{x: number, y: number}}
  133. */
  134. getObjPos: function (obj) {
  135. if (!obj) return null;
  136. let target = obj;
  137. let pos = {x: obj.offsetLeft, y: obj.offsetTop};
  138. target = obj.offsetParent;
  139. while (target) {
  140. pos.x += target.offsetLeft;
  141. pos.y += target.offsetTop;
  142. target = target.offsetParent;
  143. }
  144. return pos;
  145. },
  146. /**
  147. * 以下四个方法来自Spread示例, 参见官网或文档
  148. */
  149. getHitTest: function (obj, e, sheet) {
  150. var offset = obj.offset(),
  151. x = e.pageX - offset.left,
  152. y = e.pageY - offset.top;
  153. return sheet.hitTest(x, y);
  154. },
  155. getTargetSelection: function (sheet, target) {
  156. if (target.hitTestType === spreadNS.SheetArea.colHeader) {
  157. return sheet.getRange(-1, target.col, sheet.getRowCount(), 1);
  158. } else if (target.hitTestType === spreadNS.SheetArea.rowHeader) {
  159. return sheet.getRange(target.row, -1, 1, sheet.getColumnCount());
  160. } else if (target.hitTestType === spreadNS.SheetArea.viewport) {
  161. return sheet.getRange(target.row, target.col, 1, 1);
  162. } else if (target.hitTestType === spreadNS.SheetArea.corner) {
  163. return sheet.getRange(-1, -1, sheet.getRowCount(), sheet.getColumnCount());
  164. };
  165. },
  166. getCellInSelections: function (selections, row, col) {
  167. const count = selections.length;
  168. let range;
  169. for (var i = 0; i < count; i++) {
  170. range = selections[i];
  171. if (range.contains(row, col)) {
  172. return range;
  173. }
  174. }
  175. return null;
  176. },
  177. checkTargetInSelection: function (selections, range) {
  178. var count = selections.length, sel;
  179. for (var i = 0; i < count; i++) {
  180. sel = selections[i];
  181. if (sel.containsRange(range)) {
  182. return true;
  183. }
  184. }
  185. return false;
  186. },
  187. /**
  188. * 获取 spread 在鼠标右键时, spread的选中区域
  189. * viewport, 选中鼠标点击单元格X, X不在原选中区域内, 则选中X
  190. * colHeader, 选中整列
  191. * rowHeader, 选中整行
  192. * corner, 全选
  193. * 该方法返回不符合需求时,可通过getHitTest/getTargetSelection/getCellInSelections/checkTargetInSelection来确定鼠标右键点击时,spread当前Sheet应选中的单元格
  194. * @param obj: 创建Spread的Dom元素(jquery-contextmenu.build方法的第一个变量可读取)
  195. * @param e: jquery-contextmenu.build方法的第二个变量
  196. * @param {GC.Spread.Sheets.Workbook} spread
  197. * @returns {*}
  198. */
  199. safeRightClickSelection: function (obj, e, spread) {
  200. const sheet = spread.getActiveSheet();
  201. const selections = sheet.getSelections(), target = this.getHitTest(obj, e, sheet), range = this.getTargetSelection(sheet, target);
  202. if (!this.checkTargetInSelection(selections, range)) {
  203. sheet.setSelection(range.row, range.col, range.rowCount, range.colCount);
  204. }
  205. return target;
  206. },
  207. /**
  208. * 禁用右键菜单
  209. * @param selector
  210. * @param spread
  211. */
  212. forbiddenSpreadContextMenu: function (selector, spread) {
  213. $.contextMenu({
  214. selector: selector,
  215. build: function ($trigger, e) {
  216. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spread);
  217. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  218. }
  219. });
  220. },
  221. /**
  222. * 获取写入sheet的数据序列
  223. * data:sheet.zh_data, tree: sheet.zh_tree.nodes
  224. * @param sheet
  225. * @returns {*}
  226. */
  227. getSortData: function (sheet) {
  228. if (sheet.zh_dataType) {
  229. if (sheet.zh_dataType === this.DataType.Data) {
  230. return sheet.zh_data;
  231. } else if (sheet.zh_dataType === this.DataType.Tree) {
  232. return sheet.zh_tree.nodes;
  233. } else {
  234. return null;
  235. }
  236. } else {
  237. return null;
  238. }
  239. },
  240. /**
  241. * sheet中 使用delete键,触发EndEdited事件
  242. * @param {GC.Spreads.Sheets.Workbook} spread
  243. * @param {function} fun
  244. */
  245. addDeleteBind: function (spread, fun) {
  246. spread.commandManager().register('deleteEvent', function () {
  247. fun(spread.getActiveSheet());
  248. });
  249. spread.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  250. spread.commandManager().setShortcutKey('deleteEvent', GC.Spread.Commands.Key.del, false, false, false, false);
  251. },
  252. _initSheetDeafult: function (sheet) {
  253. if (sheet.zh_setting.headerFont) {
  254. const vStyle = new spreadNS.Style();
  255. vStyle.font = sheet.zh_setting.headerFont;
  256. sheet.setDefaultStyle(vStyle, spreadNS.SheetArea.colHeader);
  257. }
  258. if (sheet.zh_setting.font) {
  259. const vStyle = new spreadNS.Style();
  260. vStyle.font = sheet.zh_setting.font;
  261. sheet.setDefaultStyle(vStyle, spreadNS.SheetArea.viewport);
  262. }
  263. },
  264. /**
  265. * 根据sheet.zh_setting初始化sheet表头
  266. * @param {GC.Spread.Sheets.Worksheet} sheet
  267. */
  268. _initSheetHeader: function (sheet) {
  269. if (!sheet.zh_setting) { return; }
  270. sheet.setColumnCount(sheet.zh_setting.cols.length);
  271. sheet.setRowCount(sheet.zh_setting.headRows, spreadNS.SheetArea.colHeader);
  272. for (let iRow = 0; iRow < sheet.zh_setting.headRowHeight.length; iRow ++) {
  273. sheet.setRowHeight(iRow, sheet.zh_setting.headRowHeight[iRow], spreadNS.SheetArea.colHeader);
  274. }
  275. for (let iCol = 0; iCol < sheet.zh_setting.cols.length; iCol++) {
  276. const col = sheet.zh_setting.cols[iCol];
  277. const title = col.title.split('|');
  278. const colSpan = col.colSpan ? col.colSpan.split('|'): ['1'], rowSpan = col.rowSpan ? col.rowSpan.split('|'): ['1'];
  279. for (let i = 0; i < title.length; i++) {
  280. const cell = sheet.getCell(i, iCol, spreadNS.SheetArea.colHeader);
  281. cell.text(title[i]).wordWrap(true);
  282. if ((colSpan[i] !== '' && colSpan[i] !== '1') || (rowSpan[i] !== '' && rowSpan[i] !== '1')) {
  283. sheet.addSpan(i, iCol, parseInt(rowSpan[i]), parseInt(colSpan[i]), spreadNS.SheetArea.colHeader);
  284. }
  285. }
  286. sheet.setColumnWidth(iCol, col.width);
  287. if (col.visible !== undefined && col.visible !== null) {
  288. sheet.setColumnVisible(iCol, col.visible);
  289. }
  290. }
  291. sheet.rowOutlines.direction(spreadNS.Outlines.OutlineDirection.backward);
  292. sheet.showRowOutline(false);
  293. if (sheet.zh_setting.defaultRowHeight) {
  294. sheet.defaults.rowHeight = sheet.zh_setting.defaultRowHeight;
  295. }
  296. },
  297. /**
  298. * 初始化sheet, 设置sheet.zh_setting, 并初始化表头
  299. * @param {GC.Spread.Sheets.Worksheet} sheet
  300. * @param setting
  301. */
  302. initSheet: function (sheet, setting) {
  303. this.beginMassOperation(sheet);
  304. setting.pos = sheet.getParent().pos;
  305. sheet.zh_setting = setting;
  306. this._initSheetDeafult(sheet);
  307. this._initSheetHeader(sheet);
  308. sheet.setRowCount(sheet.zh_setting.emptyRows);
  309. sheet.extendCellType = {};
  310. sheet.getRange(0, 0, sheet.getRowCount(), sheet.getColumnCount()).locked(setting.readOnly);
  311. this.endMassOperation(sheet);
  312. },
  313. _loadRowData: function (sheet, data, row) {
  314. // 单元格重新写入数据
  315. if (!data) { return }
  316. sheet.zh_setting.cols.forEach(function (col, j) {
  317. const cell = sheet.getCell(row, j);
  318. if (col.getValue && Object.prototype.toString.apply(col.getValue) === "[object Function]") {
  319. cell.value(col.getValue(data));
  320. } else if (col.field !== '' && data[col.field]) {
  321. cell.value(data[col.field]);
  322. }
  323. if (col.font) {
  324. cell.font(col.font);
  325. }
  326. if (col.foreColor) {
  327. if (Object.prototype.toString.apply(col.foreColor) === "[object Function]") {
  328. cell.foreColor(col.foreColor(data, sheet.getDefaultStyle().foreColor));
  329. } else {
  330. cell.foreColor(col.foreColor);
  331. }
  332. }
  333. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object Function]") {
  334. cell.locked(col.readOnly(data) || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
  335. } else {
  336. cell.locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
  337. }
  338. if (col.formatter) {
  339. cell.formatter(col.formatter);
  340. } else if (col.type === 'Number') {
  341. cell.formatter('0.######');
  342. }
  343. if (sheet.zh_setting.getColor && Object.prototype.toString.apply(sheet.zh_setting.getColor) === "[object Function]") {
  344. cell.backColor(sheet.zh_setting.getColor(data, col, sheet.getDefaultStyle().backColor));
  345. }
  346. });
  347. },
  348. _defineColCellType: function (sheet, col, colSetting) {
  349. if(colSetting.cellType === 'ellipsis') {
  350. if (!sheet.extendCellType.ellipsis) {
  351. sheet.extendCellType.ellipsis = this.CellType.getEllipsisTextCellType();
  352. }
  353. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.ellipsis);
  354. }
  355. if(colSetting.cellType === 'ellipsisAutoTip') {
  356. if (!sheet.extendCellType.ellipsisAutoTip) {
  357. sheet.extendCellType.ellipsisAutoTip = this.CellType.getEllipsisTextAutoTipCellType();
  358. }
  359. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.ellipsisAutoTip);
  360. }
  361. if(colSetting.cellType === 'html') {
  362. if (!sheet.extendCellType.html) {
  363. sheet.extendCellType.html = this.CellType.getHtmlCellType();
  364. }
  365. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.html);
  366. }
  367. if (colSetting.cellType === 'image') {
  368. if (!sheet.extendCellType.image) {
  369. sheet.extendCellType.image = this.CellType.getImageCellType();
  370. }
  371. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.image);
  372. }
  373. if (colSetting.cellType === 'imageBtn') {
  374. if (!sheet.extendCellType.image) {
  375. sheet.extendCellType.imageBtn = this.CellType.getImageButtonCellType();
  376. }
  377. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.imageBtn);
  378. }
  379. if (colSetting.cellType === 'tree') {
  380. if (!sheet.extendCellType.tree) {
  381. sheet.extendCellType.tree = this.CellType.getTreeNodeCellType();
  382. }
  383. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.tree);
  384. }
  385. if (colSetting.cellType === 'tip') {
  386. if (!sheet.extendCellType.tip) {
  387. sheet.extendCellType.tip = this.CellType.getTipCellType();
  388. }
  389. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.tip);
  390. }
  391. if (colSetting.cellType === 'autoTip') {
  392. if (!sheet.extendCellType.autoTip) {
  393. sheet.extendCellType.autoTip = this.CellType.getAutoTipCellType();
  394. }
  395. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.autoTip);
  396. }
  397. if (colSetting.cellType === 'checkbox') {
  398. if (!sheet.extendCellType.checkbox) {
  399. sheet.extendCellType.checkbox = new spreadNS.CellTypes.CheckBox();
  400. }
  401. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.checkbox);
  402. }
  403. if (colSetting.cellType === 'unit') {
  404. if (!sheet.extendCellType.unit) {
  405. sheet.extendCellType.unit = this.CellType.getUnitCellType();
  406. sheet.bind(spreadNS.Events.LeaveCell, function (e, info) {
  407. const cellType = info.sheet.getCell(info.row, info.col).cellType();
  408. if (cellType === sheet.extendCellType.unit) {
  409. info.sheet.leaveCell = {row: info.row, col: info.col};
  410. } else {
  411. delete info.sheet.leaveCell;
  412. }
  413. });
  414. sheet.bind(spreadNS.Events.EnterCell, function (e, info) {
  415. if (info.sheet.leaveCell) {
  416. info.sheet.repaint(info.sheet.getCellRect(info.sheet.leaveCell.row, info.sheet.leaveCell.col));
  417. }
  418. });
  419. }
  420. sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.unit);
  421. }
  422. if (colSetting.formatter) {
  423. sheet.getRange(-1, col, -1, 1).formatter(colSetting.formatter);
  424. }
  425. },
  426. /**
  427. * 整个sheet重新加载数据
  428. * @param {GC.Spread.Sheets.Worksheet} sheet
  429. */
  430. reLoadSheetData: function (sheet) {
  431. const self = this;
  432. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  433. this.beginMassOperation(sheet);
  434. try {
  435. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), spreadNS.SheetArea.viewport, spreadNS.StorageType.data);
  436. // 设置总行数
  437. const totalRow = sortData.length + sheet.zh_setting.emptyRows;
  438. sheet.setRowCount(totalRow, spreadNS.SheetArea.viewport);
  439. // 控制空白行
  440. const emptyRows = sheet.getRange(sortData.length, -1, sheet.zh_setting.emptyRows, -1);
  441. emptyRows.locked(sheet.zh_dataType === 'tree');
  442. if (sortData) {
  443. // 单元格写入数据
  444. sortData.forEach(function (data, i) {
  445. self._loadRowData(sheet, data, i);
  446. sheet.setRowVisible(i, data.visible);
  447. });
  448. }
  449. // 设置列单元格格式
  450. sheet.zh_setting.cols.forEach(function (col, j) {
  451. //if (!col.cellType) { return; }
  452. self._defineColCellType(sheet, j, col);
  453. });
  454. this.endMassOperation(sheet);
  455. } catch (err) {
  456. this.endMassOperation(sheet);
  457. }
  458. },
  459. /**
  460. * 重新加载部分数据行
  461. * @param {GC.Spread.Sheets.Worksheet} sheet
  462. * @param {Number} row
  463. * @param {Number} count
  464. */
  465. reLoadRowData: function (sheet, row, count = 1) {
  466. if (row < 0) { return; }
  467. const self = this;
  468. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  469. this.beginMassOperation(sheet);
  470. try {
  471. // 清空原单元格数据
  472. sheet.clear(row, -1, count, -1, spreadNS.SheetArea.viewport, spreadNS.StorageType.data);
  473. // 单元格重新写入数据
  474. for (let i = row; i < row + count; i++) {
  475. const data = sortData[i];
  476. if (!data) { continue; }
  477. this._loadRowData(sheet, data, i);
  478. }
  479. this.endMassOperation(sheet);
  480. } catch (err) {
  481. this.endMassOperation(sheet);
  482. }
  483. },
  484. /**
  485. * 重新加载部分行数据
  486. * @param {GC.Spread.Sheets.Worksheet} sheet
  487. * @param {Array} rows
  488. */
  489. reLoadRowsData: function (sheet, rows) {
  490. const self = this;
  491. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  492. this.beginMassOperation(sheet);
  493. try {
  494. for (const row of rows) {
  495. if (row < 0) { continue; }
  496. // 清空原单元格数据
  497. sheet.clear(row, -1, 1, -1, spreadNS.SheetArea.viewport, spreadNS.StorageType.data);
  498. const data = sortData[row];
  499. // 单元格重新写入数据
  500. this._loadRowData(sheet, data, row);
  501. };
  502. this.endMassOperation(sheet);
  503. } catch (err) {
  504. this.endMassOperation(sheet);
  505. }
  506. },
  507. /**
  508. * 重新加载部分列数据
  509. * @param {GC.Spread.Sheets.Worksheet} sheet
  510. * @param {Array} cols
  511. */
  512. reLoadColsData: function (sheet, cols) {
  513. const self = this;
  514. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  515. this.beginMassOperation(sheet);
  516. try {
  517. for (const iCol of cols) {
  518. // 清空原单元格数据
  519. sheet.clear(-1, iCol, -1, 1, spreadNS.SheetArea.viewport, spreadNS.StorageType.data);
  520. const col = sheet.zh_setting.cols[iCol];
  521. sortData.forEach(function (data, i) {
  522. // 设置值
  523. const cell = sheet.getCell(i, iCol);
  524. if (col.field !== '' && data[col.field]) {
  525. cell.value(data[col.field]).locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
  526. } else {
  527. cell.locked(col.readOnly || sheet.zh_setting.readOnly || false).vAlign(1).hAlign(col.hAlign);
  528. }
  529. // 设置单元格格式
  530. if (col.formatter) {
  531. cell.formatter(col.formatter);
  532. }
  533. });
  534. }
  535. this.endMassOperation(sheet);
  536. } catch (err) {
  537. this.endMassOperation(sheet);
  538. }
  539. },
  540. reLoadNodesData: function (sheet, nodes) {
  541. this.beginMassOperation(sheet);
  542. nodes = nodes instanceof Array ? nodes : [nodes];
  543. for (const node of nodes) {
  544. const sortData = sheet.zh_dataType === 'tree' ? sheet.zh_tree.nodes : sheet.zh_data;
  545. this._loadRowData(sheet, node, sortData.indexOf(node));
  546. }
  547. this.endMassOperation(sheet);
  548. },
  549. /**
  550. * 根据data加载sheet数据,合并了一般数据和树结构数据的加载
  551. * @param {GC.Spread.Sheets.Worksheet} sheet
  552. * @param {String} dataType - 1.'zh_data' 2.'zh_tree'
  553. * @param {Array|PathTree} data - 对dataType对应
  554. */
  555. loadSheetData: function (sheet, dataType, data){
  556. sheet.zh_dataType = dataType;
  557. if (dataType === 'tree') {
  558. sheet.zh_tree = data;
  559. } else {
  560. sheet.zh_data = data;
  561. }
  562. this.protectedSheet(sheet);
  563. this.reLoadSheetData(sheet);
  564. },
  565. /**
  566. * 获取复制数据HTML格式(过滤不可见单元格)
  567. * @param {GC.Spread.Sheets.Worksheet} sheet
  568. * @returns {string}
  569. */
  570. getFilterCopyHTML: function (sheet) {
  571. const sel = sheet.getSelections()[0];
  572. const html = [];
  573. html.push('<table>');
  574. for (let i = sel.row, iLen = sel.row + sel.rowCount; i < iLen; i++) {
  575. // 跳过隐藏行
  576. if (!sheet.getCell(i, -1).visible()) { continue; }
  577. const rowHtml = [];
  578. rowHtml.push('<tr>');
  579. for (let j = sel.col, jLen = sel.col + sel.colCount; j < jLen; j++) {
  580. const data = sheet.getText(i, j);
  581. rowHtml.push('<td>' + data + '</td>');
  582. }
  583. rowHtml.push('</tr>');
  584. html.push(rowHtml.join(''));
  585. }
  586. html.push('</table>');
  587. return html.join('');
  588. },
  589. /**
  590. * 获取复制数据Text格式(过滤不可见单元格)
  591. * @param {GC.Spread.Sheets.Worksheet} sheet
  592. * @returns {string}
  593. */
  594. getFilterCopyText: function (sheet) {
  595. const copyData = [];
  596. const sel = sheet.getSelections()[0];
  597. for(let i = sel.row, iLen = sel.row + sel.rowCount; i < iLen; i++) {
  598. // 跳过隐藏行
  599. if (!sheet.getCell(i, -1).visible()) { continue; }
  600. const rowText = [];
  601. for (let j = sel.col, jLen = sel.col + sel.colCount; j < jLen; j++) {
  602. const data = sheet.getText(i, j);
  603. rowText.push(data);
  604. }
  605. copyData.push(rowText.join('\t'));
  606. }
  607. return copyData.join('\n');
  608. },
  609. /**
  610. * 树表结构,定位至指定的节点
  611. * @param {GC.Spread.Sheets.Worksheet} sheet - 需要定位的sheet
  612. * @param {Number} id - 定位节点的id
  613. */
  614. locateTreeNode: function (sheet, id, autoExpand = false) {
  615. const tree = sheet.zh_tree;
  616. if (!tree) { return }
  617. const node = tree.getItems(id);
  618. if (!node) { return }
  619. if (autoExpand && !node.visible) {
  620. const parents = tree.autoExpandNode(node);
  621. if (parents && parents.length > 0) {
  622. SpreadJsObj.reLoadNodesData(sheet, parents);
  623. SpreadJsObj.refreshTreeRowVisible(sheet);
  624. }
  625. }
  626. const index = tree.nodes.indexOf(node);
  627. const sels = sheet.getSelections();
  628. sheet.setSelection(index, sels[0].col, 1, 1);
  629. sheet.showRow(index, spreadNS.VerticalPosition.center);
  630. },
  631. saveTopAndSelect: function (sheet, cacheKey) {
  632. const sel = sheet.getSelections()[0];
  633. const top = sheet.getViewportTopRow(1);
  634. setLocalCache(cacheKey, JSON.stringify({top: top, sel: sel}));
  635. },
  636. loadTopAndSelect: function (sheet, cacheKey) {
  637. let ts = getLocalCache(cacheKey);
  638. if (ts !== '') {
  639. ts = JSON.parse(ts);
  640. if (ts === undefined || ts === null) return;
  641. if (ts.sel) {
  642. sheet.setSelection(ts.sel.row, ts.sel.col, ts.sel.rowCount, ts.sel.colCount);
  643. }
  644. if (ts.top) {
  645. sheet.showRow(ts.top, spreadNS.VerticalPosition.top);
  646. }
  647. }
  648. },
  649. resetTopAndSelect: function (sheet) {
  650. sheet.setSelection(0, 0, 1, 1);
  651. sheet.showRow(0, spreadNS.VerticalPosition.top);
  652. },
  653. /**
  654. * 获取当前选行的数据对象
  655. * @param {GC.Spread.Sheets.Worksheet} sheet
  656. * @returns {Object}
  657. */
  658. getSelectObject: function (sheet) {
  659. if (!sheet) {
  660. return null;
  661. } else if (sheet.zh_dataType) {
  662. const sel = sheet.getSelections()[0];
  663. if (!sel) {
  664. return null;
  665. }
  666. if (sheet.zh_dataType === this.DataType.Tree) {
  667. return sheet.zh_tree.nodes[sel.row];
  668. } else if (sheet.zh_dataType === this.DataType.Data) {
  669. return sheet.zh_data[sel.row];
  670. } else {
  671. return null;
  672. }
  673. }
  674. },
  675. /**
  676. * 刷新列显示
  677. * @param sheet
  678. */
  679. refreshColumnVisible: function (sheet) {
  680. if(sheet.zh_setting) {
  681. sheet.zh_setting.cols.forEach(function (col, index) {
  682. if (col.visible !== undefined && col.visible !== null) {
  683. sheet.setColumnVisible(index, col.visible);
  684. }
  685. });
  686. }
  687. },
  688. /**
  689. * 刷新行显示
  690. * @param sheet
  691. */
  692. refreshTreeRowVisible: function (sheet) {
  693. this.beginMassOperation(sheet);
  694. const sortData = sheet.zh_dataType === this.DataType.Data ? sheet.zh_data : sheet.zh_tree.nodes;
  695. for (const iRow in sortData) {
  696. const node = sortData[iRow];
  697. if (node.visible !== undefined && node.visible !== null) {
  698. sheet.setRowVisible(iRow, node.visible);
  699. } else {
  700. sheet.setRowVisible(iRow, true);
  701. }
  702. }
  703. // if (sheet.zh_tree) {
  704. // for (const iRow in sheet.zh_tree.nodes) {
  705. // const node = sheet.zh_tree.nodes[iRow];
  706. // if (node.visible !== undefined && node.visible !== null) {
  707. // sheet.setRowVisible(iRow, node.visible);
  708. // } else {
  709. // sheet.setRowVisible(iRow, true);
  710. // }
  711. // }
  712. // }
  713. this.endMassOperation(sheet);
  714. },
  715. refreshColumnAlign: function (sheet) {
  716. if (sheet.zh_setting) {
  717. for (const iCol in sheet.zh_setting.cols) {
  718. const col = sheet.zh_setting.cols[iCol];
  719. sheet.getRange(-1, iCol, -1, 1).hAlign(col.hAlign);
  720. }
  721. }
  722. },
  723. /**
  724. * 刷新列是否只读
  725. * @param sheet
  726. * @param field
  727. * @param readonly
  728. */
  729. resetFieldReadOnly: function (sheet, field, readonly) {
  730. const fields = field instanceof Array ? field : [field];
  731. if (sheet.zh_setting) {
  732. sheet.zh_setting.cols.forEach(function (col, i) {
  733. if (fields.indexOf(col.field) !== -1) {
  734. col.readOnly = readonly;
  735. for (let iRow = 0; iRow < sheet.getRowCount(); iRow++) {
  736. sheet.getCell(iRow, i).locked(col.readOnly || sheet.zh_setting.readOnly || false);
  737. }
  738. //sheet.getRange(-1, i, -1, 1, GC.Spread.Sheets.SheetArea.viewport).locked(col.readOnly || sheet.zh_setting.readOnly || false);
  739. }
  740. });
  741. }
  742. },
  743. CellType: {
  744. /**
  745. * 获取树结构CellType
  746. * 通过SpreadJsObj.loadSheetData(sheet, 'tree', tree)加载树结构数据
  747. * 要求tree类型为PathTree, 节点必须含有{id, pid, level, order, is_leaf}数据
  748. * @returns {TreeNodeCellType}
  749. */
  750. getTreeNodeCellType: function () {
  751. const indent = 20;
  752. const levelIndent = -5;
  753. const halfBoxLength = 5;
  754. const halfExpandLength = 3;
  755. /**
  756. * 画一条点线段
  757. * @param canvas - 画布
  758. * @param x1 - 线段起点 x
  759. * @param y1 - 线段起点 y
  760. * @param x2 - 线段终点 x
  761. * @param y2 - 线段终点 y
  762. * @param color - 线段颜色
  763. */
  764. const drawDotLine = function (canvas, x1, y1, x2, y2, color) {
  765. canvas.save();
  766. // 设置偏移量
  767. canvas.translate(0.5, 0.5);
  768. canvas.beginPath();
  769. canvas.strokeStyle = color;
  770. canvas.dottedLine(x1, y1, x2, y2);
  771. canvas.stroke();
  772. canvas.restore();
  773. };
  774. /**
  775. * 画一条线段
  776. * @param canvas - 画布
  777. * @param x1 - 线段起点 x
  778. * @param y1 - 线段起点 y
  779. * @param x2 - 线段终点 x
  780. * @param y2 - 线段终点 y
  781. * @param color - 线段颜色
  782. */
  783. const drawLine = function (canvas, x1, y1, x2, y2, color) {
  784. canvas.save();
  785. // 设置偏移量
  786. canvas.translate(0.5, 0.5);
  787. canvas.beginPath();
  788. canvas.moveTo(x1, y1);
  789. canvas.lineTo(x2, y2);
  790. canvas.strokeStyle = color;
  791. canvas.stroke();
  792. canvas.restore();
  793. };
  794. /**
  795. * 画一个方框
  796. * @param {Object} canvas - 画布
  797. * @param {Object} rect - 方框区域
  798. * @param {String} lineColor - 画线颜色
  799. * @param {String} fillColor - 填充颜色
  800. */
  801. const drawBox = function (canvas, rect, lineColor, fillColor) {
  802. canvas.save();
  803. // 设置偏移量
  804. canvas.translate(0.5, 0.5);
  805. canvas.strokeStyle = lineColor;
  806. canvas.beginPath();
  807. canvas.moveTo(rect.left, rect.top);
  808. canvas.lineTo(rect.left, rect.bottom);
  809. canvas.lineTo(rect.right, rect.bottom);
  810. canvas.lineTo(rect.right, rect.top);
  811. canvas.lineTo(rect.left, rect.top);
  812. canvas.stroke();
  813. canvas.fillStyle = fillColor;
  814. canvas.fill();
  815. canvas.restore();
  816. };
  817. /**
  818. * 画树结构-展开收起按钮
  819. * @param {Object} canvas - 画布
  820. * @param {Number} x - 单元格左顶点坐标 x
  821. * @param {Number} y - 单元格左顶点坐标 y
  822. * @param {Number} w - 单元格宽度
  823. * @param {Number} h - 单元格高度
  824. * @param {Number} centerX - 按钮中央坐标
  825. * @param {Number} centerY - 按钮中央坐标
  826. * @param {Boolean} expanded - 当前节点展开收起状态
  827. */
  828. const drawExpandBox = function (canvas, x, y, w, h, centerX, centerY, expanded) {
  829. let rect = {
  830. top: centerY - halfBoxLength,
  831. bottom: centerY + halfBoxLength,
  832. left: centerX - halfBoxLength,
  833. right: centerX + halfBoxLength
  834. };
  835. let h1, h2, offset = 1;
  836. if (rect.left < x + w) {
  837. // 方框超出单元格宽度时,超出部分不画。
  838. rect.right = Math.min(rect.right, x + w);
  839. drawBox(canvas, rect, '#808080', 'white');
  840. // 画中心十字
  841. // 画十字横线
  842. h1 = centerX - halfExpandLength;
  843. h2 = Math.min(centerX + halfExpandLength, x + w);
  844. if (h2 > h1) {
  845. drawLine(canvas, h1, centerY, h2, centerY, '#808080');
  846. }
  847. // 画十字竖线
  848. if (!expanded && (centerX < x + w)) {
  849. drawLine(canvas, centerX, centerY - halfExpandLength, centerX, centerY + halfExpandLength, '#808080');
  850. }
  851. }
  852. };
  853. let TreeNodeCellType = function (){};
  854. TreeNodeCellType.prototype = new spreadNS.CellTypes.Text();
  855. const proto = TreeNodeCellType.prototype;
  856. /**
  857. * 绘制方法
  858. * @param {Object} canvas - 画布
  859. * @param value - cell.value
  860. * @param {Number} x - 单元格左顶点坐标 x
  861. * @param {Number} y - 单元格左顶点坐标 y
  862. * @param {Number} w - 单元格宽度
  863. * @param {Number} h - 单元格高度
  864. * @param {Object} style - cell.style
  865. * @param {Object} options
  866. */
  867. proto.paint = function (canvas, value, x, y, w, h, style, options) {
  868. // 清理 画布--单元格范围 旧数据
  869. if (style.backColor) {
  870. canvas.save();
  871. canvas.fillStyle = style.backColor;
  872. canvas.fillRect(x, y, w, h);
  873. canvas.restore();
  874. } else {
  875. canvas.clearRect(x, y, w, h);
  876. }
  877. const tree = options.sheet.zh_tree;
  878. // 使用TreeCellType前,需定义sheet.tree
  879. if (tree) {
  880. const node = options.row < tree.nodes.length ? tree.nodes[options.row] : null;
  881. if (node) {
  882. const showTreeLine = true;
  883. const centerX = Math.floor(x) + (node.level) * indent + (node.level) * levelIndent + indent / 2;
  884. const centerY = Math.floor((y + (y + h)) / 2);
  885. // Draw Sibling Line
  886. if (showTreeLine) {
  887. // Draw Horizontal Line
  888. if (centerX < x + w) {
  889. const x1 = centerX + indent / 2;
  890. //drawLine(canvas, centerX, centerY, Math.min(x1, x + w), centerY, 'gray');
  891. drawDotLine(canvas, centerX, centerY, Math.min(x1, x + w), centerY, '#b8b8b8');
  892. }
  893. // Draw Vertical Line
  894. if (centerX < x + w) {
  895. const y1 = tree.isLastSibling(node) ? centerY : y + h;
  896. const parent = tree.getParent(node);
  897. const y2 = y1 - centerY;
  898. if (node.order === 1 && !parent) {
  899. //drawLine(canvas, centerX, centerY, centerX, y1, 'gray');
  900. drawDotLine(canvas, centerX, centerY, centerX, y1, '#b8b8b8');
  901. } else {
  902. //drawLine(canvas, centerX, y, centerX, y1, 'gray');
  903. drawDotLine(canvas, centerX, y, centerX, y1, '#b8b8b8');
  904. }
  905. }
  906. }
  907. // Draw Expand Box
  908. if (!node.is_leaf) {
  909. drawExpandBox(canvas, x, y, w, h, centerX, centerY, node.expanded);
  910. }
  911. // Draw Parent Line
  912. if (showTreeLine) {
  913. let parent = tree.getParent(node), parentCenterX = centerX - indent - levelIndent;
  914. while (parent) {
  915. if (!tree.isLastSibling(parent)) {
  916. if (parentCenterX < x + w) {
  917. //drawLine(canvas, parentCenterX, y, parentCenterX, y + h, 'gray');
  918. drawDotLine(canvas, parentCenterX, y, parentCenterX, y + h, '#b8b8b8');
  919. }
  920. }
  921. parent = tree.getParent(parent);
  922. parentCenterX -= (indent + levelIndent);
  923. }
  924. };
  925. // 重定位x
  926. const move = (node.level + 1) * indent + (node.level) * levelIndent;
  927. x = x + move;
  928. w = w - move;
  929. }
  930. }
  931. // Drawing Text
  932. spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
  933. };
  934. /**
  935. * 获取点击信息
  936. * @param {Number} x
  937. * @param {Number} y
  938. * @param {Object} cellStyle
  939. * @param {Object} cellRect
  940. * @param {Object} context
  941. * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
  942. */
  943. proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  944. return {
  945. x: x,
  946. y: y,
  947. row: context.row,
  948. col: context.col,
  949. cellStyle: cellStyle,
  950. cellRect: cellRect,
  951. sheet: context.sheet,
  952. sheetArea: context.sheetArea
  953. };
  954. };
  955. /**
  956. * 鼠标点击 树结构按钮 响应展开收起(未加载子节点时,先加载子节点)
  957. * @param {Object} hitinfo - 见getHitInfo
  958. */
  959. proto.processMouseDown = function (hitinfo) {
  960. const offset = -1;
  961. const tree = hitinfo.sheet.zh_tree;
  962. if (!tree) { return; }
  963. const node = tree.nodes[hitinfo.row];
  964. if (!node) { return; }
  965. let centerX = hitinfo.cellRect.x + offset + (node.level) * indent + (node.level) * levelIndent + indent / 2;
  966. let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
  967. // 点击展开节点时,如果已加载子项,则展开,反之这加载子项,展开
  968. if (Math.abs(hitinfo.x - centerX) < halfBoxLength && Math.abs(hitinfo.y - centerY) < halfBoxLength) {
  969. const children = tree.getChildren(node);
  970. if (!node.expanded && !node.is_leaf && children.length === 0 && tree.loadChildren) {
  971. tree.loadChildren(node, function () {
  972. node.expanded = true;
  973. const children = tree.getChildren(node);
  974. hitinfo.sheet.addRows(hitinfo.row + 1, children.length);
  975. SpreadJsObj.reLoadRowData(hitinfo.sheet, hitinfo.row + 1, children.length);
  976. });
  977. } else {
  978. tree.setExpanded(node, !node.expanded);
  979. SpreadJsObj.massOperationSheet(hitinfo.sheet, function () {
  980. const posterity = tree.getPosterity(node);
  981. for (const child of posterity) {
  982. hitinfo.sheet.setRowVisible(tree.nodes.indexOf(child), child.visible, hitinfo.sheetArea);
  983. }
  984. });
  985. hitinfo.sheet.repaint();
  986. }
  987. }
  988. };
  989. return new TreeNodeCellType();
  990. },
  991. /**
  992. * 获取 带悬浮提示的CellType
  993. * @returns {TipCellType}
  994. */
  995. getTipCellType: function () {
  996. const maxHintWidth = 200, indent = 15, borderIndent = 10;
  997. const TipCellType = function () {};
  998. // 继承 SpreadJs定义的 普通的TextCellType
  999. TipCellType.prototype = new spreadNS.CellTypes.Text();
  1000. const proto = TipCellType.prototype;
  1001. proto.getTextDisplayWidth = function(hitinfo, str, font) {
  1002. const xs = hitinfo.sheet.getParent().xs;
  1003. const ctx = xs.childNodes[0].getContext("2d");
  1004. if (font && font !== '') {
  1005. ctx.font = font;
  1006. } else {
  1007. ctx.font = hitinfo.cellStyle.font;
  1008. }
  1009. return ctx.measureText(str).width;
  1010. };
  1011. proto.showTip = function (hitinfo, text) {
  1012. return text && text !== '';
  1013. };
  1014. /**
  1015. * 获取点击信息
  1016. * @param {Number} x
  1017. * @param {Number} y
  1018. * @param {Object} cellStyle
  1019. * @param {Object} cellRect
  1020. * @param {Object} context
  1021. * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
  1022. */
  1023. proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1024. return {
  1025. x: x,
  1026. y: y,
  1027. row: context.row,
  1028. col: context.col,
  1029. cellStyle: cellStyle,
  1030. cellRect: cellRect,
  1031. sheet: context.sheet,
  1032. sheetArea: context.sheetArea,
  1033. ctx: context.sheet.getParent().xs,
  1034. };
  1035. };
  1036. /**
  1037. * 鼠标进入单元格事件 - 显示悬浮提示
  1038. * @param {Object} hitinfo - 见getHitInfo返回值
  1039. */
  1040. proto.processMouseEnter = function (hitinfo) {
  1041. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  1042. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1043. if (col.getTip && Object.prototype.toString.apply(col.getTip) === "[object Function]") {
  1044. const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
  1045. text = col.getTip(sortData[hitinfo.row]);
  1046. }
  1047. const pos = SpreadJsObj.getObjPos(hitinfo.sheet.getParent().qo);
  1048. if (pos && this.showTip(hitinfo, text)) {
  1049. if (!this._toolTipElement) {
  1050. let div = $('#autoTip')[0];
  1051. if (!div) {
  1052. div = document.createElement("div");
  1053. $(div).css("position", "absolute")
  1054. .css("border", "1px #C0C0C0 solid")
  1055. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  1056. .css("font", "9pt Arial")
  1057. .css("background", "white")
  1058. .css("padding", 5)
  1059. .css("z-index", 999)
  1060. .css("max-width", maxHintWidth)
  1061. .css("word-wrap", "break-word")
  1062. .attr("id", 'autoTip');
  1063. document.body.insertBefore(div, null);
  1064. }
  1065. const validWidth = $(window).width() - (pos.x + hitinfo.x + indent) - borderIndent;
  1066. const textWidth = this.getTextDisplayWidth(hitinfo, text, "9pt Arial");
  1067. if (validWidth >= maxHintWidth || textWidth <= validWidth) {
  1068. $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x + indent);
  1069. } else if (textWidth > maxHintWidth) {
  1070. $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x - indent - maxHintWidth);
  1071. } else {
  1072. $(div).text(text).css("top", pos.y + hitinfo.y + indent).css("left", pos.x + hitinfo.x - indent - textWidth);
  1073. }
  1074. this._toolTipElement = div;
  1075. $(div).show("fast");
  1076. }
  1077. }
  1078. };
  1079. /**
  1080. * 鼠标移出单元格事件 - 隐藏悬浮提示
  1081. * @param {Object} hitinfo - 见getHitInfo返回值
  1082. */
  1083. proto.processMouseLeave = function (hitinfo) {
  1084. if (this._toolTipElement) {
  1085. $(this._toolTipElement).hide();
  1086. this._toolTipElement = null;
  1087. }
  1088. };
  1089. return new TipCellType();
  1090. },
  1091. getAutoTipCellType: function () {
  1092. const AutoTipCellType = function () {};
  1093. // 继承 TipCellType
  1094. AutoTipCellType.prototype = SpreadJsObj.CellType.getTipCellType();
  1095. const proto = AutoTipCellType.prototype
  1096. proto.showTip = function (hitinfo, text) {
  1097. return text && text !== '' && this.getTextDisplayWidth(hitinfo, text) > hitinfo.cellRect.width;
  1098. };
  1099. return new AutoTipCellType();
  1100. },
  1101. /**
  1102. * 获取 带图片的cellType(图片需在document中定义好img,并写入col的img属性)
  1103. *
  1104. * img:
  1105. * 1. 整列固定,则传入img的select
  1106. * e.g. {title: '附件', field: 'attachment', cellType: 'image', img = '#attachment-img'}
  1107. *
  1108. * 2. 各单元格自定义,则
  1109. * e.g. {title: '附件', field: 'attachment', cellType: 'image', img = getAttachmentImage}
  1110. * function getAttachmentImage (data) {
  1111. * $('#attachment-img').url = data.attachmentImageUrl;
  1112. * return $('#attachment-img')[0];
  1113. * }
  1114. *
  1115. * @returns {ImageCellType}
  1116. */
  1117. getImageCellType: function () {
  1118. const ImageCellType = function (){};
  1119. ImageCellType.prototype = new spreadNS.CellTypes.Text();
  1120. const proto = ImageCellType.prototype;
  1121. proto.getImage = function (sheet, iRow, iCol) {
  1122. const col = sheet.zh_setting.cols[iCol];
  1123. let imgSource = col.img;
  1124. if (imgSource && Object.prototype.toString.apply(imgSource) === "[object Function]") {
  1125. const sortData = SpreadJsObj.getSortData(sheet);
  1126. const data = sortData ? sortData[iRow] : null;
  1127. return data ? imgSource(data) : null;
  1128. } else {
  1129. return $(imgSource)[0] ? $(imgSource)[0] : null;
  1130. }
  1131. };
  1132. proto.paint = function (canvas, value, x, y, w, h, style, options) {
  1133. const col = options.sheet.zh_setting.cols[options.col];
  1134. const img = this.getImage(options.sheet, options.row, options.col);
  1135. const indent = col.indent ? col.indent : 10;
  1136. if (img) {
  1137. if (style.backColor) {
  1138. canvas.save();
  1139. canvas.fillStyle = style.backColor;
  1140. canvas.fillRect(x, y, indent + img.width, h);
  1141. canvas.restore();
  1142. }
  1143. canvas.drawImage(img, x + indent, y + (h - img.height) / 2);
  1144. if (style.hAlign !== spreadNS.HorizontalAlign.left) {
  1145. style.hAlign = spreadNS.HorizontalAlign.left;
  1146. }
  1147. x = x + indent + img.width;
  1148. w = w - indent - img.width;
  1149. }
  1150. // Drawing Text
  1151. spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
  1152. };
  1153. /**
  1154. * 获取点击信息
  1155. * @param {Number} x
  1156. * @param {Number} y
  1157. * @param {Object} cellStyle
  1158. * @param {Object} cellRect
  1159. * @param {Object} context
  1160. * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
  1161. */
  1162. proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1163. return {
  1164. x: x,
  1165. y: y,
  1166. row: context.row,
  1167. col: context.col,
  1168. cellStyle: cellStyle,
  1169. cellRect: cellRect,
  1170. sheet: context.sheet,
  1171. sheetArea: context.sheetArea
  1172. };
  1173. };
  1174. /**
  1175. * 鼠标点击
  1176. * @param {Object} hitinfo - 见getHitInfo
  1177. */
  1178. proto.processMouseDown = function (hitinfo) {
  1179. const img = this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
  1180. if (img) {
  1181. const halfX = img.width / 2, halfY = img.height / 2;
  1182. const centerX = hitinfo.cellRect.x + indent + halfX;
  1183. const centerY = hitinfo.cellRect.y + hitinfo.cellRect.height / 2;
  1184. // 点击展开节点时,如果已加载子项,则展开,反之这加载子项,展开
  1185. if (Math.abs(hitinfo.x - centerX) < halfX && Math.abs(hitinfo.y - centerY) < halfY) {
  1186. const imageClick = hitinfo.sheet.zh_setting ? hitinfo.sheet.zh_setting.imageClick : null;
  1187. if (imageClick && Object.prototype.toString.apply(imageClick) === "[object Function]") {
  1188. const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
  1189. const data = sortData ? sortData[hitinfo.row] : null;
  1190. imageClick(data);
  1191. }
  1192. }
  1193. }
  1194. };
  1195. return new ImageCellType();
  1196. },
  1197. /**
  1198. *
  1199. * 获取 带normal-hover-active按钮的cellType(需定义三张图片,须在document中定义好img,并写入col的normalImg, hoverImg, activeImg属性)
  1200. * 其中:normalImg必需,向下套用(不存在activeImg则使用hoverImg,不存在hoverImg则使用normalImg)
  1201. * 三个img均可像getImageCellType一样动态获取,参见getImageCellType注释
  1202. *
  1203. * @returns {ImageCellType}
  1204. */
  1205. getImageButtonCellType: function () {
  1206. let hover = 1, active = 2;
  1207. const ImageCellType = function (){};
  1208. ImageCellType.prototype = new spreadNS.CellTypes.Text();
  1209. const proto = ImageCellType.prototype;
  1210. proto.getImage = function (sheet, iRow, iCol) {
  1211. const col = sheet.zh_setting.cols[iCol];
  1212. let imgSource = col.normalImg;
  1213. const cell = sheet.getCell(iRow, iCol), tag = cell.tag();
  1214. if (tag === active) {
  1215. imgSource = col.activeImg ? col.activeImg : (col.hoverImg ? col.hoverImg : col.normalImg);
  1216. } else if (tag === hover) {
  1217. imgSource = col.hoverImg ? col.hoverImg : col.normalImg;
  1218. }
  1219. if (imgSource && Object.prototype.toString.apply(imgSource) === "[object Function]") {
  1220. const sortData = SpreadJsObj.getSortData(sheet);
  1221. const data = sortData ? sortData[iRow] : null;
  1222. return data ? imgSource(data) : null;
  1223. } else {
  1224. return $(imgSource)[0] ? $(imgSource)[0] : null;
  1225. }
  1226. };
  1227. proto.paint = function (canvas, value, x, y, w, h, style, options) {
  1228. const col = options.sheet.zh_setting.cols[options.col];
  1229. const sortData = SpreadJsObj.getSortData(options.sheet);
  1230. const data = sortData ? sortData[options.row] : null;
  1231. let showImage = true;
  1232. if (col.showImage && Object.prototype.toString.apply(col.showImage) === "[object Function]") {
  1233. showImage = col.showImage(data);
  1234. }
  1235. const img = showImage ? this.getImage(options.sheet, options.row, options.col) : null;
  1236. const indent = col.indent ? col.indent : 10;
  1237. if (style.hAlign === spreadNS.HorizontalAlign.right) {
  1238. if (img) {
  1239. if (style.backColor) {
  1240. canvas.save();
  1241. canvas.fillStyle = style.backColor;
  1242. canvas.fillRect(x + w - indent - img.width, y, img.width, h);
  1243. canvas.restore();
  1244. }
  1245. canvas.drawImage(img, x + w - indent - img.width, y + (h - img.height) / 2);
  1246. w = w - indent - img.width;
  1247. }
  1248. // Drawing Text
  1249. spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
  1250. } else {
  1251. if (img) {
  1252. if (style.backColor) {
  1253. canvas.save();
  1254. canvas.fillStyle = style.backColor;
  1255. canvas.fillRect(x, y, indent + img.width, h);
  1256. canvas.restore();
  1257. }
  1258. canvas.drawImage(img, x + 10, y + (h - img.height) / 2);
  1259. if (style.hAlign !== spreadNS.HorizontalAlign.left) {
  1260. style.hAlign = spreadNS.HorizontalAlign.left;
  1261. }
  1262. x = x + indent + img.width;
  1263. w = w - indent - img.width;
  1264. }
  1265. // Drawing Text
  1266. spreadNS.CellTypes.Text.prototype.paint.apply(this, [canvas, value, x, y, w, h, style, options]);
  1267. }
  1268. };
  1269. /**
  1270. * 获取点击信息
  1271. * @param {Number} x
  1272. * @param {Number} y
  1273. * @param {Object} cellStyle
  1274. * @param {Object} cellRect
  1275. * @param {Object} context
  1276. * @returns {{x: *, y: *, row: *, col: *|boolean|*[]|number|{}|UE.dom.dtd.col, cellStyle: *, cellRect: *, sheet: *|StyleSheet, sheetArea: *}}
  1277. */
  1278. proto.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1279. return {
  1280. x: x,
  1281. y: y,
  1282. row: context.row,
  1283. col: context.col,
  1284. cellStyle: cellStyle,
  1285. cellRect: cellRect,
  1286. sheet: context.sheet,
  1287. sheetArea: context.sheetArea
  1288. };
  1289. };
  1290. /**
  1291. * 鼠标点击
  1292. * @param {Object} hitinfo - 见getHitInfo
  1293. */
  1294. proto.processMouseEnter = function (hitinfo) {
  1295. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1296. // Drawing Image
  1297. if (col.hoverImg) {
  1298. const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1299. cell.tag(hover);
  1300. hitinfo.sheet.repaint(hitinfo.cellRect);
  1301. }
  1302. };
  1303. proto.processMouseLeave = function (hitinfo) {
  1304. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1305. // Drawing Image
  1306. if (col.hoverImg) {
  1307. const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1308. cell.tag(null);
  1309. hitinfo.sheet.repaint(hitinfo.cellRect);
  1310. }
  1311. };
  1312. proto.processMouseDown = function (hitinfo) {
  1313. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1314. if (col.activeImg) {
  1315. const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1316. cell.tag(active);
  1317. hitinfo.sheet.repaint(hitinfo.cellRect);
  1318. }
  1319. };
  1320. proto.processMouseUp = function (hitinfo) {
  1321. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  1322. const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
  1323. const data = sortData ? sortData[hitinfo.row] : null;
  1324. if (col.showImage && Object.prototype.toString.apply(col.showImage) === "[object Function]") {
  1325. if (!col.showImage(data)) {
  1326. return;
  1327. }
  1328. }
  1329. const imageClick = hitinfo.sheet.zh_setting ? hitinfo.sheet.zh_setting.imageClick : null;
  1330. if (imageClick && Object.prototype.toString.apply(imageClick) === "[object Function]") {
  1331. imageClick(data);
  1332. const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1333. cell.tag(null);
  1334. hitinfo.sheet.repaint(hitinfo.cellRect);
  1335. }
  1336. };
  1337. /*
  1338. 注释部分以进入鼠标进入图片,点击图片为基准更新图片,鼠标快速移动时,可能失效
  1339. */
  1340. // proto.processMouseDown = function (hitinfo) {
  1341. // const img = this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
  1342. // const halfX = img.width / 2, halfY = img.height / 2;
  1343. // const centerX = hitinfo.cellRect.x + indent + halfX;
  1344. // const centerY = hitinfo.cellRect.y + hitinfo.cellRect.height / 2;
  1345. //
  1346. // if (Math.abs(hitinfo.x - centerX) < halfX && Math.abs(hitinfo.y - centerY) < halfY) {
  1347. // const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1348. // cell.tag(down);
  1349. // hitinfo.sheet.repaint(hitinfo.cellRect);
  1350. // }
  1351. // };
  1352. // proto.processMouseUp = function (hitinfo) {
  1353. // const img = this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
  1354. // const halfX = img.width / 2, halfY = img.height / 2;
  1355. // const centerX = hitinfo.cellRect.x + indent + halfX;
  1356. // const centerY = hitinfo.cellRect.y + hitinfo.cellRect.height / 2;
  1357. //
  1358. // // 点击展开节点时,如果已加载子项,则展开,反之这加载子项,展开
  1359. // if (Math.abs(hitinfo.x - centerX) < halfX && Math.abs(hitinfo.y - centerY) < halfY) {
  1360. // const imageClick = hitinfo.sheet.zh_setting ? hitinfo.sheet.zh_setting.imageClick : null;
  1361. // if (imageClick && Object.prototype.toString.apply(imageClick) === "[object Function]") {
  1362. // const sortData = SpreadJsObj.getSortData(hitinfo.sheet);
  1363. // const data = sortData ? sortData[hitinfo.row] : null;
  1364. // imageClick(data);
  1365. // const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1366. // cell.tag(null);
  1367. // hitinfo.sheet.repaint(hitinfo.cellRect);
  1368. // }
  1369. // }
  1370. // };
  1371. // proto.processMouseMove = function (hitinfo) {
  1372. // const img = this.getImage(hitinfo.sheet, hitinfo.row, hitinfo.col);
  1373. // const halfX = img.width / 2, halfY = img.height / 2;
  1374. // const centerX = hitinfo.cellRect.x + indent + halfX;
  1375. // const centerY = hitinfo.cellRect.y + hitinfo.cellRect.height / 2;
  1376. // const cell = hitinfo.sheet.getCell(hitinfo.row, hitinfo.col);
  1377. // if (Math.abs(hitinfo.x - centerX) < halfX && Math.abs(hitinfo.y - centerY) < halfY) {
  1378. // if (cell.tag() !== hover) {
  1379. // cell.tag(hover);
  1380. // hitinfo.sheet.repaint(hitinfo.cellRect);
  1381. // }
  1382. // } else {
  1383. // if (cell.tag() === hover) {
  1384. // cell.tag(null);
  1385. // hitinfo.sheet.repaint(hitinfo.cellRect);
  1386. // }
  1387. // }
  1388. // };
  1389. return new ImageCellType();
  1390. },
  1391. /**
  1392. * 获取 嵌入Html的cellType
  1393. * @returns {HTMLCellType}
  1394. */
  1395. getHtmlCellType: function () {
  1396. const HTMLCellType = function (){};
  1397. HTMLCellType.prototype = new spreadNS.CellTypes.Text;
  1398. const proto = ImageCellType.prototype;
  1399. proto.paint = function (ctx, value, x, y, w, h, style, context) {
  1400. let DOMURL = window.URL || window.webkitURL || window;
  1401. let cell = context.sheet.getCell(context.row, context.col);
  1402. let img = cell.tag();
  1403. if (img) {
  1404. try {
  1405. ctx.save();
  1406. ctx.rect(x, y, w, h);
  1407. ctx.clip();
  1408. ctx.drawImage(img, x + 2, y + 2)
  1409. ctx.restore();
  1410. cell.tag(null);
  1411. return;
  1412. }
  1413. catch (err) {
  1414. GC.Spread.Sheets.CustomCellType.prototype.paint.apply(this, [ctx, "#HTMLError", x, y, w, h, style, context])
  1415. cell.tag(null);
  1416. return;
  1417. }
  1418. }
  1419. let svgPattern = '<svg xmlns="http://www.w3.org/2000/svg" width="{0}" height="{1}">' +
  1420. '<foreignObject width="100%" height="100%"><div xmlns="http://www.w3.org/1999/xhtml" style="font:{2}">{3}</div></foreignObject></svg>';
  1421. let data = svgPattern.replace("{0}", w).replace("{1}", h).replace("{2}", style.font).replace("{3}", value);
  1422. let doc = document.implementation.createHTMLDocument("");
  1423. doc.write(data);
  1424. // Get well-formed markup
  1425. data = (new XMLSerializer()).serializeToString(doc.body.children[0]);
  1426. img = new Image();
  1427. //var svg = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
  1428. //var url = DOMURL.createObjectURL(svg);
  1429. //img.src = url;
  1430. img.src = 'data:image/svg+xml;base64,' + window.btoa(data);
  1431. cell.tag(img);
  1432. img.onload = function () {
  1433. context.sheet.repaint(new GC.Spread.Sheets.Rect(x, y, w, h));
  1434. }
  1435. };
  1436. return new HTMLCellType();
  1437. },
  1438. /**
  1439. * 获取 字符超长缩略的cellType
  1440. * @returns {EllipsisTextCellType}
  1441. */
  1442. getEllipsisTextCellType: function () {
  1443. const EllipsisTextCellType = function (){};
  1444. EllipsisTextCellType.prototype = new spreadNS.CellTypes.Text;
  1445. const proto = EllipsisTextCellType.prototype;
  1446. proto.getEllipsisText = function(c, str, maxWidth) {
  1447. var width = c.measureText(str).width;
  1448. var ellipsis = '…';
  1449. var ellipsisWidth = c.measureText(ellipsis).width;
  1450. if (width <= maxWidth || width <= ellipsisWidth) {
  1451. return str;
  1452. } else {
  1453. var len = str.length;
  1454. while (width >= maxWidth - ellipsisWidth && len-- > 0) {
  1455. str = str.substring(0, len);
  1456. width = c.measureText(str).width;
  1457. }
  1458. return str + ellipsis;
  1459. }
  1460. };
  1461. proto.paint = function (ctx, value, x, y, w, h, style, context) {
  1462. ctx.font = style.font;
  1463. value = this.getEllipsisText(ctx, value, w - 2);
  1464. spreadNS.CellTypes.Text.prototype.paint.apply(this, [ctx, value, x, y, w, h, style, context]);
  1465. };
  1466. return new EllipsisTextCellType();
  1467. },
  1468. getEllipsisTextAutoTipCellType: function () {
  1469. const CellType = function () {};
  1470. // 继承 TipCellType
  1471. CellType.prototype = SpreadJsObj.CellType.getAutoTipCellType();
  1472. const proto = CellType.prototype;
  1473. const ellipsisTextCellType = SpreadJsObj.CellType.getEllipsisTextCellType();
  1474. proto.getEllipsisText = ellipsisTextCellType.getEllipsisText;
  1475. proto.paint = ellipsisTextCellType.paint;
  1476. return new CellType();
  1477. },
  1478. /**
  1479. * 获取 动态显示ComboBox的cellType
  1480. * @returns {ActiveComboCellType}
  1481. */
  1482. getActiveComboCellType: function () {
  1483. const ActiveComboCellType = function () {};
  1484. ActiveComboCellType.prototype = new spreadNS.CellTypes.ComboBox();
  1485. const proto = ActiveComboCellType.prototype;
  1486. proto.paintValue = function (ctx, value, x, y, w, h, style, options) {
  1487. const sheet = options.sheet;
  1488. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()
  1489. && !sheet.getCell(options.row, options.col).locked()) {
  1490. spreadNS.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
  1491. } else {
  1492. spreadNS.CellTypes.Base.prototype.paintValue.apply(this, arguments);
  1493. }
  1494. };
  1495. proto.getHitInfo = function (x, y, cellStyle, cellRect, options) {
  1496. const sheet = options.sheet;
  1497. if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()
  1498. && !sheet.getCell(options.row, options.col).locked()) {
  1499. return spreadNS.CellTypes.ComboBox.prototype.getHitInfo.apply(this, [x, y, cellStyle, cellRect, options]);
  1500. } else {
  1501. return {
  1502. x: x,
  1503. y: y,
  1504. row: options.row,
  1505. col: options.col,
  1506. cellStyle: cellStyle,
  1507. cellRect: cellRect,
  1508. sheetArea: options.sheetArea
  1509. };
  1510. }
  1511. };
  1512. return new ActiveComboCellType();
  1513. },
  1514. /**
  1515. * 获取 单位的CellType
  1516. * @returns {GC.Spread.Sheets.CellTypes.ComboBox}
  1517. */
  1518. getUnitCellType: function () {
  1519. let combo = this.getActiveComboCellType();
  1520. combo.itemHeight(10).items(['m', 'km', 'm2', 'm3', 'dm3', 'kg', 't', 'm3·km',
  1521. '总额', '月' ,'项', '处' ,'个', '根', '棵', '块', '台', '系统', '每一试桩',
  1522. '桥长米', '公路公里', '株', '组', '座', '元', '工日', '套', '台班', '艘班', '亩',
  1523. 'm/处', 'm/道', 'm/座', 'm2/m', 'm3/m', 'm3/处', '根/米', 'm3/m2']);
  1524. return combo;
  1525. }
  1526. }
  1527. };