root 2 лет назад
Родитель
Сommit
eed96d3e35
1 измененных файлов с 42 добавлено и 6 удалено
  1. 42 6
      app.html

+ 42 - 6
app.html

@@ -43,12 +43,7 @@
         // // api: '/pages/site.json'
         header,
         api: {
-          "url": 'http://localhost:8081/page/menu',
-          "dataType":"form",
-          "method":"post",
-          "headers": {
-            "Authorization": 'Bearer ' + getToken()
-          },
+          "url": 'http://localhost:8081/page/menu'
         }
       };
 
@@ -127,6 +122,47 @@
           // watchRouteChange: fn => {
           //   return history.listen(fn);
           // },
+          fetcher: (params) => {
+            
+            var method = params.method;
+            var data = params.data;
+            var body = params.body;
+            var url = params.url;
+
+            var form = new FormData();
+            form = JSON.stringify(params.data);
+            var ContentType = 'application/json';
+            let header = {
+              // "Content-Type": "application/json",
+              "Content-Type": ContentType,
+              "Authorization":'Bearer ' + getToken(),
+            }
+ 
+            let isFormData = (typeof FormData !== 'undefined') && (params['data'] instanceof FormData);
+            
+            if (isFormData) {
+              delete header['Content-Type'];
+              form = data;
+            }
+
+            let headers = new Headers(header);
+
+            return new Promise(function (resolve, reject) {
+                fetch(url,{
+                  method: method,
+                  body: form,
+                  headers: headers
+                }).then(function (response) {
+                  return response.json();
+                }).then(function (res) {
+                
+                  // if (isFormData) {
+                  //   data['data'] = res.data;
+                  // }
+                  resolve({ "data": res });
+                });
+            });
+          },
           updateLocation: (location, replace) => {
             location = normalizeLink(location);
             if (location === 'goBack') {