api.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const api = {
  2. getGraph:'/api/ltkg/kg/getGraph',
  3. getNode:'/api/ltkg/kg/getNode',
  4. getSchema:'/api/ltkg/kg/getSchema',
  5. getTree:'/api/ltkg/kg/getTree',
  6. entity_predict:'api/ltkg/nlp/getNlp',
  7. getMrInfo:'/api/ltkg/presetInfo/getMrInfo',
  8. getAnswer:'/api/ltkg/qa/charBot',
  9. getTerm:'/api/ltkg/term/getTerm',
  10. check:'http://192.168.2.121:7010/test/testStandConvert',
  11. };
  12. const getUrlArgObject = function(name) {//
  13. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  14. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  15. var r = window.location.search.substr(1).match(reg);
  16. var q = window.location.pathname.substr(1).match(reg_rewrite);
  17. if (r != null) {
  18. return decodeURIComponent(r[2]);
  19. } else if (q != null) {
  20. return decodeURIComponent(q[2]);
  21. } else {
  22. return null;
  23. }
  24. }
  25. const post = function (url, data,pId) {
  26. const securityCode = getUrlArgObject("code");
  27. const appKeyId = getUrlArgObject("appI");
  28. const appKeySecret = getUrlArgObject("appS");
  29. const productId = getUrlArgObject("productId");
  30. return new Promise((resolve, reject) => {
  31. $.ajax({
  32. method: 'post',
  33. url: url,
  34. data: JSON.stringify(data),
  35. contentType: "application/json; charset=UTF-8",
  36. beforeSend: function (xmlHttp) {
  37. xmlHttp.setRequestHeader("If-Modified-Since", "0");
  38. xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  39. xmlHttp.setRequestHeader("appKeyId", appKeyId);
  40. xmlHttp.setRequestHeader("appKeySecret", appKeySecret);
  41. xmlHttp.setRequestHeader("securityCode", securityCode);
  42. xmlHttp.setRequestHeader("productId", productId);
  43. },
  44. success: function (res) {
  45. resolve({ data: res });
  46. },
  47. error: function (error) {
  48. reject(error);
  49. },
  50. });
  51. });
  52. }
  53. module.exports ={
  54. post,
  55. api,
  56. getUrlArgObject
  57. }