spreadjs_zh.js 68 KB

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