common.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const utils_cryptoJs_min = require("./crypto-js.min.js");
  4. let loading = false;
  5. let count = 0;
  6. const showLoading = function(title = "") {
  7. if (!loading) {
  8. common_vendor.index.showLoading({
  9. title: title || "",
  10. mask: true
  11. });
  12. loading = true;
  13. }
  14. count += 1;
  15. };
  16. const hideLoading = function() {
  17. let timer = setTimeout(() => {
  18. if (count === 1 && loading) {
  19. common_vendor.index.hideLoading();
  20. loading = false;
  21. }
  22. count -= 1;
  23. clearTimeout(timer);
  24. timer = null;
  25. }, 0);
  26. };
  27. const showToast = function(msg, fn = () => {
  28. }, duration = 1500) {
  29. common_vendor.index.showToast({
  30. title: msg,
  31. mask: true,
  32. icon: "none",
  33. duration
  34. });
  35. if (fn) {
  36. setTimeout(() => {
  37. fn();
  38. }, duration);
  39. }
  40. };
  41. const showModal = function(content, callBack = () => {
  42. }, data = {}) {
  43. common_vendor.index.showModal({
  44. content,
  45. title: data.title || "",
  46. confirmText: data.confirmText || "确定",
  47. confirmColor: data.confirmColor || "",
  48. cancelColor: data.cancelColor || "",
  49. cancelText: data.cancelText || "",
  50. showCancel: data.cancelText ? true : false,
  51. success: (res) => {
  52. if (res.confirm && callBack instanceof Function) {
  53. callBack();
  54. }
  55. if (!res.confirm && data.callBack instanceof Function) {
  56. data.callBack();
  57. }
  58. }
  59. });
  60. };
  61. const isEmpty = function(obj) {
  62. if (obj == void 0 || obj == null || obj == "") {
  63. return true;
  64. } else if (obj instanceof Array) {
  65. return obj.length <= 0;
  66. } else if (obj instanceof Object) {
  67. return Object.keys(obj).length <= 0;
  68. }
  69. return false;
  70. };
  71. const isNotEmpty = function(obj) {
  72. return !isEmpty(obj);
  73. };
  74. const desEncrypt = function(message, key) {
  75. let keyHex = utils_cryptoJs_min.CryptoJS.enc.Utf8.parse(key);
  76. let encrypted = utils_cryptoJs_min.CryptoJS.DES.encrypt(message, keyHex, {
  77. mode: utils_cryptoJs_min.CryptoJS.mode.ECB,
  78. padding: utils_cryptoJs_min.CryptoJS.pad.Pkcs7
  79. });
  80. return encrypted.toString();
  81. };
  82. const desDecrypt = function(str, key, exportType) {
  83. let keyHex = utils_cryptoJs_min.CryptoJS.enc.Utf8.parse(key);
  84. let decrypted = utils_cryptoJs_min.CryptoJS.DES.decrypt(
  85. exportType == "hex" ? {
  86. ciphertext: utils_cryptoJs_min.CryptoJS.enc.Hex.parse(str)
  87. } : str,
  88. keyHex,
  89. {
  90. mode: utils_cryptoJs_min.CryptoJS.mode.ECB,
  91. padding: utils_cryptoJs_min.CryptoJS.pad.Pkcs7
  92. }
  93. );
  94. return decrypted.toString(utils_cryptoJs_min.CryptoJS.enc.Utf8);
  95. };
  96. const turnToMap = (list) => {
  97. let map = {};
  98. list.map((item) => {
  99. map[item.routePath] = JSON.parse(item.infoJson || "{}");
  100. });
  101. return map;
  102. };
  103. exports.desDecrypt = desDecrypt;
  104. exports.desEncrypt = desEncrypt;
  105. exports.hideLoading = hideLoading;
  106. exports.isEmpty = isEmpty;
  107. exports.isNotEmpty = isNotEmpty;
  108. exports.showLoading = showLoading;
  109. exports.showModal = showModal;
  110. exports.showToast = showToast;
  111. exports.turnToMap = turnToMap;
  112. //# sourceMappingURL=../../.sourcemap/mp-alipay/utils/common.js.map