common_util.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. function seqString(num, length) {
  23. var numstr = num.toString();
  24. var l = numstr.length;
  25. if (numstr.length >= length) {
  26. return numstr;
  27. }
  28. for (var i = 0; i < length - l; i++) {
  29. numstr = "0" + numstr;
  30. }
  31. return numstr;
  32. }
  33. function customRowHeader(sheet, dataLength) {
  34. sheet.suspendPaint(); //提升焦点变换性能 2019年4月15日
  35. for (let i = 0; i < dataLength; i++) {
  36. sheet.setValue(i, 0, `F${i + 1}`, GC.Spread.Sheets.SheetArea.rowHeader);
  37. }
  38. sheet.resumePaint(); //提升焦点变换性能 2019年4月12日
  39. }
  40. function changePropNames(object, oldNames, newNames) {
  41. if (!object) return;
  42. for (let i = 0; i < oldNames.length; i++) {
  43. if (object[oldNames[i]]) {
  44. object[newNames[i]] = object[oldNames[i]];
  45. delete object[oldNames[i]];
  46. }
  47. }
  48. }
  49. function changePropNames(object, oldNames, newNames) {
  50. if (!object) return;
  51. for (let i = 0; i < oldNames.length; i++) {
  52. if (object[oldNames[i]]) {
  53. object[newNames[i]] = object[oldNames[i]];
  54. delete object[oldNames[i]];
  55. }
  56. }
  57. }
  58. function deletePropNames(object, namesArr) {
  59. if (!object) return;
  60. for (let name of namesArr) {
  61. if (object[name]) delete object[name];
  62. }
  63. }