common.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. function setAlign(sheet, headers) {
  2. const fuc = () => {
  3. headers.forEach(({ hAlign, vAlign }, index) => {
  4. sheetCommonObj.setAreaAlign(sheet.getRange(-1, index, -1, 1), hAlign, vAlign)
  5. });
  6. };
  7. sheetCommonObj.renderSheetFunc(sheet, fuc);
  8. }
  9. function setFormatter(sheet, headers) {
  10. const fuc = () => {
  11. headers.forEach(({ formatter }, index) => {
  12. if (formatter) {
  13. sheet.setFormatter(-1, index, formatter);
  14. }
  15. });
  16. };
  17. sheetCommonObj.renderSheetFunc(sheet, fuc);
  18. }
  19. function initSheet(dom, setting) {
  20. const workBook = sheetCommonObj.buildSheet(dom, setting);
  21. const sheet = workBook.getSheet(0);
  22. setAlign(sheet, setting.header);
  23. setFormatter(sheet, setting.header);
  24. return workBook;
  25. }
  26. function showData(sheet, data, headers, emptyRows) {
  27. const fuc = () => {
  28. sheet.setRowCount(data.length);
  29. data.forEach((item, row) => {
  30. headers.forEach(({ dataCode }, col) => {
  31. sheet.setValue(row, col, item[dataCode] || '');
  32. });
  33. });
  34. if (emptyRows) {
  35. sheet.addRows(data.length, emptyRows);
  36. }
  37. };
  38. sheetCommonObj.renderSheetFunc(sheet, fuc);
  39. }
  40. // 获取当前表中行数据
  41. function getRowData(sheet, row, headers) {
  42. const item = {};
  43. headers.forEach(({ dataCode }, index) => {
  44. const value = sheet.getValue(row, index) || '';
  45. if (value) {
  46. item[dataCode] = value;
  47. }
  48. });
  49. return item;
  50. }
  51. // 获取表数据和缓存数据的不同数据
  52. function getRowDiffData(curRowData, cacheRowData, headers) {
  53. let item = null;
  54. headers.forEach(({ dataCode }) => {
  55. const curValue = curRowData[dataCode];
  56. const cacheValue = cacheRowData[dataCode];
  57. if (!cacheValue && !curValue) {
  58. return;
  59. }
  60. if (cacheValue !== curValue) {
  61. if (!item) {
  62. item = {};
  63. }
  64. item[dataCode] = curValue || '';
  65. }
  66. });
  67. return item;
  68. }
  69. function getRowAllData(curRowData, headers) {
  70. let item = {};
  71. headers.forEach(({ dataCode }) => {
  72. const curValue = curRowData[dataCode];
  73. item[dataCode] = curValue || '';
  74. });
  75. return item;
  76. }
  77. const TIME_OUT = 1000 * 20;
  78. const libID = window.location.search.match(/libID=([^&]+)/)[1];
  79. const UpdateType = {
  80. UPDATE: 'update',
  81. DELETE: 'delete',
  82. CREATE: 'create',
  83. };
  84. const DEBOUNCE_TIME = 200;
  85. const locked = lockUtil.getLocked();