mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-30 13:20:24 +08:00
feat: postman支持mock参数
This commit is contained in:
parent
bbed858700
commit
009ed08944
@ -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;
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user