common_util.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Created by CSL on 2017-06-06.
  3. * public functions for web.
  4. */
  5. // 忽略大小写判断字符串是否和参数指定的字符串相同
  6. String.prototype.sameText = function (str) {
  7. return this.toLowerCase() == str.toLowerCase();
  8. };
  9. // 忽略大小写判断字符串是否有参数指定的子串
  10. String.prototype.hasSubStr = function (str) {
  11. return this.toLowerCase().indexOf(str.toLowerCase()) > -1;
  12. };
  13. // 判断字符串是否是数字形式的字符串
  14. String.prototype.isNumberStr = function () {
  15. return this == +this;
  16. };
  17. // 树结点计算时,取费会出现值为NaN的情况,导致往父节点汇总(递归相加)会出现错误。
  18. function parseFloatPlus(value) {
  19. let rst = parseFloat(value);
  20. return isNaN(rst) ? 0 : rst;
  21. }
  22. // 数组合并,并去重复。
  23. Array.prototype.merge = function (arr) {
  24. if (arr.length > 0) {
  25. for (let e of arr) {
  26. if (!this.includes(e)) this.push(e);
  27. }
  28. }
  29. };
  30. function mergeArr(arr1, arr2) { //
  31. if (arr2.length > 0) {
  32. for (let e of arr2) {
  33. if (arr1.includes(e)) arr1.push(e);
  34. }
  35. }
  36. };
  37. function seqString(num, length) {
  38. var numstr = num.toString();
  39. var l = numstr.length;
  40. if (numstr.length >= length) {
  41. return numstr;
  42. }
  43. for (var i = 0; i < length - l; i++) {
  44. numstr = "0" + numstr;
  45. }
  46. return numstr;
  47. }
  48. function customRowHeader(sheet, dataLength) {
  49. sheet.suspendPaint(); //提升焦点变换性能 2019年4月15日
  50. for (let i = 0; i < dataLength; i++) {
  51. sheet.setValue(i, 0, `F${i + 1}`, GC.Spread.Sheets.SheetArea.rowHeader);
  52. }
  53. sheet.resumePaint(); //提升焦点变换性能 2019年4月12日
  54. }
  55. function changePropNames(object, oldNames, newNames) {
  56. if (!object) return;
  57. for (let i = 0; i < oldNames.length; i++) {
  58. if (object[oldNames[i]]) {
  59. object[newNames[i]] = object[oldNames[i]];
  60. delete object[oldNames[i]];
  61. }
  62. }
  63. }
  64. function changePropNames(object, oldNames, newNames) {
  65. if (!object) return;
  66. for (let i = 0; i < oldNames.length; i++) {
  67. if (object[oldNames[i]]) {
  68. object[newNames[i]] = object[oldNames[i]];
  69. delete object[oldNames[i]];
  70. }
  71. }
  72. }
  73. function deletePropNames(object, namesArr) {
  74. if (!object) return;
  75. for (let name of namesArr) {
  76. if (object[name]) delete object[name];
  77. }
  78. }