Переглянути джерело

修复导出含params属性对象参数问题

RuoYi 3 роки тому
батько
коміт
892065003d
2 змінених файлів з 16 додано та 21 видалено
  1. 1 16
      ruoyi-ui/src/utils/request.js
  2. 15 5
      ruoyi-ui/src/utils/ruoyi.js

+ 1 - 16
ruoyi-ui/src/utils/request.js

@@ -23,22 +23,7 @@ service.interceptors.request.use(config => {
   }
   // get请求映射params参数
   if (config.method === 'get' && config.params) {
-    let url = config.url + '?';
-    for (const propName of Object.keys(config.params)) {
-      const value = config.params[propName];
-      var part = encodeURIComponent(propName) + "=";
-      if (value !== null && typeof(value) !== "undefined") {
-        if (typeof value === 'object') {
-          for (const key of Object.keys(value)) {
-            let params = propName + '[' + key + ']';
-            var subPart = encodeURIComponent(params) + "=";
-            url += subPart + encodeURIComponent(value[key]) + "&";
-          }
-        } else {
-          url += part + encodeURIComponent(value) + "&";
-        }
-      }
-    }
+    let url = config.url + '?' + tansParams(config.params);
     url = url.slice(0, -1);
     config.params = {};
     config.url = url;

+ 15 - 5
ruoyi-ui/src/utils/ruoyi.js

@@ -179,11 +179,21 @@ export function handleTree(data, id, parentId, children) {
 * @param {*} params  参数
 */
 export function tansParams(params) {
-	let result = ''
-	Object.keys(params).forEach((key) => {
-		if (!Object.is(params[key], undefined) && !Object.is(params[key], null) && !Object.is(JSON.stringify(params[key]), '{}')) {
-			result += encodeURIComponent(key) + '=' + encodeURIComponent(params[key]) + '&'
+    let result = ''
+    for (const propName of Object.keys(params)) {
+        const value = params[propName];
+        var part = encodeURIComponent(propName) + "=";
+        if (value !== null && typeof(value) !== "undefined") {
+            if (typeof value === 'object') {
+				for (const key of Object.keys(value)) {
+					let params = propName + '[' + key + ']';
+					var subPart = encodeURIComponent(params) + "=";
+					result += subPart + encodeURIComponent(value[key]) + "&";
+				}
+            } else {
+				result += part + encodeURIComponent(value) + "&";
+            }
 		}
-	})
+    }
 	return result
 }