Procházet zdrojové kódy

将路由抽出来配置

root před 2 roky
rodič
revize
775445f062
5 změnil soubory, kde provedl 60 přidání a 9 odebrání
  1. 6 3
      app.html
  2. 44 2
      login.html
  3. 3 3
      pages/app/header-json.js
  4. 1 1
      pages/login/login-json.js
  5. 6 0
      public/static/tools/common.js

+ 6 - 3
app.html

@@ -27,6 +27,7 @@
 <script src="./pages/app/header-json.js"></script>
 <script>
     (function () {
+      var systemUri = getSystemIp();
       let amis = amisRequire('amis/embed');
       const match = amisRequire('path-to-regexp').match;
       // 如果想用 browserHistory 请切换下这处代码, 其他不用变
@@ -41,9 +42,10 @@
         // asideBefore: '<div class="p-2 text-center">菜单前面区域</div>',
         // asideAfter: '<div class="p-2 text-center">菜单后面区域</div>',
         // // api: '/pages/site.json'
+        breadcrumb:false,
         header,
         api: {
-          "url": 'http://localhost:8081/page/menu'
+          "url": '/page/menu'
         }
       };
 
@@ -123,11 +125,12 @@
           //   return history.listen(fn);
           // },
           fetcher: (params) => {
-            
+            var systemUri = getSystemIp();
             var method = params.method;
             var data = params.data;
             var body = params.body;
-            var url = params.url;
+            var url = systemUri + params.url;
+            console.log('----------------'+url)
 
             var form = new FormData();
             form = JSON.stringify(params.data);

+ 44 - 2
login.html

@@ -38,8 +38,49 @@
           }, 
           { 
             replaceText: languageInfo.langReplaceText,
-            langReplaceTextIgnoreKeys: languageInfo.langReplaceTextIgnoreKeys
+            langReplaceTextIgnoreKeys: languageInfo.langReplaceTextIgnoreKeys,
+            fetcher: (params) => {
+            var systemUri = getSystemIp();
+            var method = params.method;
+            var data = params.data;
+            var body = params.body;
+            var url = systemUri + params.url;
+
+            var form = new FormData();
+            form = JSON.stringify(params.data);
+            var ContentType = 'application/x-www-form-urlencoded';
+            // var ContentType = 'application/json';
+            let header = {
+              "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: params.data,
+                  headers: headers
+                }).then(function (response) {
+                  return response.json();
+                }).then(function (res) {
+                
+                  // if (isFormData) {
+                  //   data['data'] = res.data;
+                  // }
+                  resolve({ "data": res });
+                });
+            });
           }
+          },
         );
 
         getVerify();
@@ -51,9 +92,10 @@
       // document.querySelector('.code_img').src = 'http://localhost:8081/login/verifyCode?' + Math.random();
     }
     function getVerify() {
+      var systemUri = getSystemIp();
       // 创建请求对象
       var request = new XMLHttpRequest()
-      request.open('post', 'http://localhost:8081/login/verifyCode')
+      request.open('post', systemUri+'/login/verifyCode')
       request.send()
       // 获取网络请求响应的数据
       request.onreadystatechange = function () {

+ 3 - 3
pages/app/header-json.js

@@ -1,7 +1,7 @@
 function getHeaderJson() {
     let headerJson = {
       "type": "page",
-      "initApi": "http://localhost:8081/api/userInfo",
+      "initApi": "/api/userInfo",
       "body": [
         {
           "type": "flex",
@@ -78,7 +78,7 @@ function getHeaderJson() {
                   "blank": false,
                   "label": "退出登录",
                   "id": "u:88d8afc464b5",
-                  "api": "http://localhost:8081/api/logout",
+                  "api": "/api/logout",
                   "onEvent": {
                     "click": {
                       "actions": [
@@ -88,7 +88,7 @@ function getHeaderJson() {
                               "silent": false
                             },
                             "api": {
-                              "url": "http://localhost:8081/api/logout",
+                              "url": "/api/logout",
                               "method": "post",
                               "messages": {
                               }

+ 1 - 1
pages/login/login-json.js

@@ -7,7 +7,7 @@ function getLoginJson() {
             "className": "h-full pc:p-9 m:p-4 m:pt-20",
             "api": {
                 "method":"post",
-                "url":"http://localhost:8081/api/login",
+                "url":"/api/login",
                 "dataType":"form",
                 "headers": {
                   "Authorization": 'Bearer ' + getToken()

+ 6 - 0
public/static/tools/common.js

@@ -48,4 +48,10 @@ function getLanguageInfo() {
       langReplaceText,
       langReplaceTextIgnoreKeys
     }
+}
+
+// 获取系统url
+function getSystemIp() {
+
+  return "http://localhost:8081";
 }