fix: postman 导入数据不会转换动态路由

This commit is contained in:
suxiaoxin 2017-11-03 16:32:33 +08:00
parent 70abd4ec7e
commit afad424574
2 changed files with 26 additions and 30 deletions

View File

@ -1,5 +1,6 @@
import {message} from 'antd'
import URL from 'url';
function json_format(json){
try{
@ -12,16 +13,7 @@ function json_format(json){
function postman(importDataModule){
function parseUrl(url){
let parser = document.createElement('a');
parser.href = url;
return {
protocol: parser.protocol,
hostname: parser.hostname,
port: parser.port,
pathname: parser.pathname,
search: parser.search,
host: parser.host
}
return URL.parse(url)
}
function checkInterRepeat(interData){
@ -78,14 +70,20 @@ function postman(importDataModule){
}
function handlePath(path){
path = path.replace(/{{(\w*)}}/,"");
path = parseUrl(path).pathname;
if(path.charAt(0) != "/"){
path = decodeURIComponent(path);
if(!path) return '';
path = path.replace(/{{\w*}}/g, '');
path = path.replace(/{(\w*)}/,function(data, match){
if(match){
return ':' + match;
}
return '';
});
if(path[0] != "/"){
path = "/" + path;
}
if(path.charAt(path.length-1) === "/"){
path = path.substr(0,path.length-1);
}
return path;
}

View File

@ -1,19 +1,11 @@
import {message} from 'antd'
import URL from 'url';
function postman(importDataModule){
function parseUrl(url){
let parser = document.createElement('a');
parser.href = url;
return {
protocol: parser.protocol,
hostname: parser.hostname,
port: parser.port,
pathname: parser.pathname,
search: parser.search,
host: parser.host
}
return URL.parse(url)
}
function checkInterRepeat(interData){
@ -72,14 +64,20 @@ function postman(importDataModule){
}
function handlePath(path){
path = path.replace(/{{(\w*)}}/,"");
path = parseUrl(path).pathname;
if(path.charAt(0) != "/"){
path = decodeURIComponent(path);
if(!path) return '';
path = path.replace(/{{\w*}}/g, '');
path = path.replace(/{(\w*)}/,function(data, match){
if(match){
return ':' + match;
}
return '';
});
if(path[0] != "/"){
path = "/" + path;
}
if(path.charAt(path.length-1) === "/"){
path = path.substr(0,path.length-1);
}
return path;
}