feat: postman支持mock参数

This commit is contained in:
suxiaoxin 2017-09-19 20:35:59 +08:00
parent bbed858700
commit 009ed08944
2 changed files with 11 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import React from 'react';
import moment from 'moment';
import constants from './constants/variable';
import Mock from 'mockjs'
exports.formatTime = (timestamp) => {
@ -52,6 +53,11 @@ exports.debounce = (func, wait) => {
};
};
exports.handleMockWord =(word) =>{
if(!word || typeof word !== 'string' || word[0] !== '@') return word;
return Mock.mock(word);
}
// 从 Javascript 对象中选取随机属性
exports.pickRandomProperty = (obj) => {
let result;

View File

@ -10,6 +10,7 @@ import URL from 'url';
const MockExtra = require('common/mock-extra.js')
import './Postman.scss';
import json5 from 'json5'
import {handleMockWord} from '../../common.js'
function json_parse(data) {
try {
@ -428,11 +429,12 @@ export default class Run extends Component {
const obj = {};
arr.forEach(item => {
if (item.name && item.type !== 'file') {
obj[item.name] = item.value || '';
obj[item.name] = handleMockWord(item.value);
}
})
return obj;
}
getFiles(bodyForm) {
const files = {};
bodyForm.forEach(item => {
@ -446,7 +448,7 @@ export default class Run extends Component {
const queryObj = {};
query.forEach(item => {
if (item.name) {
queryObj[item.name] = item.value || '';
queryObj[item.name] = handleMockWord(item.value);
}
})
return queryObj;
@ -587,7 +589,7 @@ export default class Run extends Component {
onClick={this.props.save}
type="primary"
style={{ marginLeft: 10 }}
>{this.props.type === 'inter' ? '保存' : '更新'}</Button>
>{this.props.type === 'inter' ? '保存' : '保存'}</Button>
</Tooltip>
</div>