fix: mock支持RegExp

This commit is contained in:
qitmac000249 2017-08-02 16:55:13 +08:00
parent 48811ffca4
commit 90b962d2c8
4 changed files with 42 additions and 3 deletions

View File

@ -46,3 +46,5 @@ export function getInterfaceGroupList (value) {
payload: value
}
}

View File

@ -268,7 +268,6 @@ class AddInterface extends Component {
res_body_type: 'json',
res_body: resParams
}
if (ifTrue) {
params.id = interfaceId
postURL = '/interface/up'

View File

@ -56,6 +56,8 @@ class ResParams extends Component {
return json
}
}
var langTools = window.ace.require("ace/ext/language_tools");
let editor = this.editor = window.ace.edit("res-cover")
editor.getSession().setMode("ace/mode/json");
@ -97,7 +99,9 @@ class ResParams extends Component {
langTools.addCompleter(rhymeCompleter);
editor.getSession().on('change', () => {
this.props.getResParams(editor.getValue())
// console.log( JSON.parse(editor.getValue()));
this.props.getResParams(editor.getValue());
});
setTimeout(() => {

View File

@ -4,6 +4,40 @@ import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import Mock from 'mockjs'
function regexp_parse(p,c) {
c = c || {};
for (let i in p) {
if(! p.hasOwnProperty(i)){
continue;
}
if (typeof p[i] === 'object') {
c[i] = (p[i].constructor === Array) ? [] : {};
regexp_parse(p[i], c[i]);
} else {
if(/^\/.+\/$/.test(p[i])){
try{
let regexpStr = p[i].substring(1,p[i].length-1);
// for(let i = 0;i<regexpStr.length;i++){
// if("* . ? + $ ^ [ ] ( ) { } | \ /".indexOf(regexpStr[i])>-1){
// regexpStr[i] = "\\"+regexpStr[i];
// }
// }
c[i] = new RegExp(regexpStr);
}
catch(e)
{
c[i] = p[i];
}
}else{
c[i] = p[i];
}
}
}
return c;
}
@connect(
state => {
return {
@ -12,7 +46,6 @@ import Mock from 'mockjs'
}
}
)
class Result extends Component {
static propTypes = {
resParams: PropTypes.string,
@ -30,6 +63,7 @@ class Result extends Component {
let json, j;
try{
json = JSON.parse(resParams);
json = regexp_parse(json);
}catch(e){
json = false;
}