hookFunction.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /** @format */
  2. export function getRequest() {
  3. var urlStr = location.href;
  4. if (typeof urlStr == "undefined") {
  5. var url = decodeURI(location.search); //获取url中"?"符后的字符串
  6. } else {
  7. var url = "?" + urlStr.split("?")[1];
  8. }
  9. var theRequest = new Object();
  10. if (url.indexOf("?") != -1) {
  11. var str = url.substr(1);
  12. let strs = str.split("&");
  13. for (var i = 0; i < strs.length; i++) {
  14. theRequest[strs[i].split("=")[0]] = decodeURIComponent(
  15. strs[i].split("=")[1]
  16. );
  17. }
  18. }
  19. return theRequest;
  20. } //获取url地址
  21. //获取通讯ID号
  22. export function kg_uuid(len, radix) {
  23. var chars =
  24. "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  25. var uuid = [],
  26. i;
  27. radix = radix || chars.length;
  28. if (len) {
  29. for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
  30. } else {
  31. var r;
  32. uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
  33. uuid[14] = "4";
  34. for (i = 0; i < 36; i++) {
  35. if (!uuid[i]) {
  36. r = 0 | (Math.random() * 16);
  37. uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
  38. }
  39. }
  40. }
  41. return uuid.join("");
  42. }
  43. export function GetUrlbasePath() {
  44. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  45. var curWwwPath = window.document.location.href;
  46. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  47. var pathName = window.document.location.pathname;
  48. var pos = curWwwPath.indexOf(pathName);
  49. //获取主机地址,如: http://localhost:8080
  50. var localhostPath = curWwwPath.substring(0, pos);
  51. //获取带"/"的项目名,如:/ems
  52. var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
  53. //获取项目的basePath http://localhost:8080/ems/
  54. var basePath = localhostPath + projectName + "/";
  55. return basePath;
  56. }