diff --git a/CHANGELOG.md b/CHANGELOG.md index fd302a1c..74ab94dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ 1. Api 路径兼容 postman {varible} 2. View Response Height 问题 3. pathname 允许只有一个 / +4. 高级 Mock 期望支持 mockjs ### v1.2.8 diff --git a/exts/yapi-plugin-advanced-mock/MockCol/MockCol.js b/exts/yapi-plugin-advanced-mock/MockCol/MockCol.js index 43ee48d4..ee2e4237 100644 --- a/exts/yapi-plugin-advanced-mock/MockCol/MockCol.js +++ b/exts/yapi-plugin-advanced-mock/MockCol/MockCol.js @@ -5,7 +5,7 @@ import PropTypes from 'prop-types' import { withRouter } from 'react-router-dom'; import { Table, Button, message, Popconfirm, Tooltip, Icon } from 'antd'; import { fetchMockCol } from 'client/reducer/modules/mockCol' -import { formatTime, getMockText } from 'client/common.js'; +import { formatTime } from 'client/common.js'; import constants from 'client/constants/variable.js' import CaseDesModal from './CaseDesModal'; @@ -98,7 +98,7 @@ export default class MockCol extends Component { delay: 0, headers: [{name: '', value: ''}], params: {}, - res_body: currInterface.res_body && getMockText(currInterface.res_body) + res_body: currInterface.res_body } let ipFilters = []; diff --git a/exts/yapi-plugin-advanced-mock/server.js b/exts/yapi-plugin-advanced-mock/server.js index 6cd6eb7c..da3ba872 100644 --- a/exts/yapi-plugin-advanced-mock/server.js +++ b/exts/yapi-plugin-advanced-mock/server.js @@ -7,6 +7,7 @@ const _ = require('underscore'); const path = require('path'); const lib = require(path.resolve(yapi.WEBROOT, 'common/lib.js' )); const Mock = require('mockjs'); +const mockExtra = require(path.resolve(yapi.WEBROOT, 'common/mock-extra.js' )) function arrToObj(arr){ let obj = {'Set-Cookie': []}; @@ -74,7 +75,7 @@ module.exports = function(){ } - async function handleByCase(caseData, context){ + async function handleByCase(caseData){ let caseInst = yapi.getInst(caseModel); let result = await caseInst.get({ _id: caseData._id @@ -156,8 +157,18 @@ module.exports = function(){ let interfaceId = context.interfaceData._id; let caseData = await checkCase(context.ctx, interfaceId); if(caseData){ - let data = await handleByCase(caseData, context); + let data = await handleByCase(caseData); context.mockJson = yapi.commons.json_parse(data.res_body); + try{ + context.mockJson = Mock.mock(mockExtra(context.mockJson, { + query: context.ctx.query, + body: context.ctx.request.body, + params: Object.assign({}, context.ctx.query, context.ctx.request.body) + })); + }catch(err){ + yapi.commons.log(err, 'error') + } + context.resHeader = arrToObj(data.headers); context.httpCode = data.code; context.delay = data.delay;