فهرست منبع

添加appkey等

zhouna 5 سال پیش
والد
کامیت
4f64872a29
1فایلهای تغییر یافته به همراه20 افزوده شده و 1 حذف شده
  1. 20 1
      src/js/api.js

+ 20 - 1
src/js/api.js

@@ -4,9 +4,25 @@ const api = {
   getNode:'/api/ltkg/kg/getNode',
   getSchema:'/api/ltkg/kg/getSchema',
   getTree:'/api/ltkg/kg/getTree'
-}
+};
 
+const getUrlArgObject = function(name) {
+  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
+  var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
+  var r = window.location.search.substr(1).match(reg);
+  var q = window.location.pathname.substr(1).match(reg_rewrite);
+  if (r != null) {
+    return decodeURIComponent(r[2]);
+  } else if (q != null) {
+    return decodeURIComponent(q[2]);
+  } else {
+    return null;
+  }
+}
 const post = function (url, data) {
+  const securityCode = getUrlArgObject("code");
+  const appKeyId = getUrlArgObject("appI");
+  const appKeySecret = getUrlArgObject("appS");
     return new Promise((resolve, reject) => {
       $.ajax({
         method: 'post',
@@ -16,6 +32,9 @@ const post = function (url, data) {
         beforeSend: function (xmlHttp) {
           xmlHttp.setRequestHeader("If-Modified-Since", "0");
           xmlHttp.setRequestHeader("Cache-Control", "no-cache");
+          xmlHttp.setRequestHeader("appKeyId", appKeyId);
+          xmlHttp.setRequestHeader("appKeySecret", appKeySecret);
+          xmlHttp.setRequestHeader("securityCode", securityCode);
         },
         success: function (res) {
           resolve({ data: res });