global.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * 提示框
  3. *
  4. * @param string message
  5. * @param string type
  6. * @param string icon
  7. * @return void
  8. */
  9. function toast(message, type, icon) {
  10. var toast = $(".toast");
  11. toast.addClass(type);
  12. toast.children('.message').html(message);
  13. var iconClass = 'fa-' + icon;
  14. toast.children('.icon').addClass(iconClass);
  15. toast.fadeIn(500);
  16. setTimeout(function() {
  17. toast.fadeOut('fast');
  18. toast.children('.message').text('');
  19. toast.children('.icon').removeClass(iconClass);
  20. }, 3000);
  21. }
  22. /**
  23. * 获取url中参数
  24. * @param variable
  25. * @returns {*}
  26. */
  27. function getQueryVariable(variable) {
  28. var query = window.location.search.substring(1);
  29. var vars = query.split("&");
  30. for (var i=0;i<vars.length;i++) {
  31. var pair = vars[i].split("=");
  32. if(pair[0] == variable){return pair[1];}
  33. }
  34. return(false);
  35. }
  36. const zeroRange = 0.00000001;
  37. function checkZero(value) {
  38. return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
  39. }
  40. function checkFieldChange(o, n) {
  41. return o == n || ((!o || o === '') && (n === ''));
  42. }
  43. /**
  44. * 设置本地缓存
  45. *
  46. * @param {String} key
  47. * @param {String|Number} value
  48. * @return {void}
  49. */
  50. function setLocalCache(key, value) {
  51. const storage = window.localStorage;
  52. if (!storage || key === '' || value === '') {
  53. return;
  54. }
  55. storage.setItem(key, value);
  56. }
  57. /**
  58. * 获取本地缓存
  59. *
  60. * @param {String} key
  61. * @return {String}
  62. */
  63. function getLocalCache(key) {
  64. const storage = window.localStorage;
  65. if (!storage || key === '') {
  66. return null;
  67. }
  68. return storage.getItem(key);
  69. }
  70. /**
  71. * 移除本地缓存
  72. * @param {String} key
  73. * @returns {Boolean}
  74. */
  75. function removeLocalCache(key) {
  76. const storage = window.localStorage;
  77. if (!storage || key === '') {
  78. return null;
  79. }
  80. return storage.removeItem(key);
  81. }
  82. function trimInvalidChar(str) {
  83. return $.trim(str).replace(/\n/g, '').replace(/\r/g, '').replace(/\t/g, '');
  84. }
  85. function cleanSymbols(str) {
  86. return $.trim(str).replace(/\\/g, '').replace(/\'/g, '').replace(/\"/g, '').replace(/\</g, '').replace(/\|/g, '');
  87. }