mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-12 15:10:23 +08:00
feat: 完善可视化表达式,可根据焦点编辑表达式
This commit is contained in:
parent
88ffc90560
commit
0a04fb8719
@ -2,6 +2,7 @@
|
||||
|
||||
* 支持自定义域名邮箱登录
|
||||
* 测试用例支持导入不同项目接口
|
||||
* 完善可视化表达式,可根据焦点编辑表达式
|
||||
|
||||
|
||||
#### Bug Fixed
|
||||
|
47
a.markdown
47
a.markdown
@ -1,4 +1,49 @@
|
||||
|
||||
<h1 class="curproject-name"> eererer </h1>
|
||||
<h1 class="curproject-name"> test_22(copy_copy) </h1>
|
||||
|
||||
|
||||
|
||||
# %u516C%u5171%u5206%u7C7B
|
||||
[TOC]
|
||||
|
||||
|
||||
## cluster%0A%3Ca%20id%3Dcluster%3E%20%3C/a%3E
|
||||
[TOC]
|
||||
|
||||
### 基本信息
|
||||
|
||||
**Path:** /cluster
|
||||
|
||||
**Method:** POST
|
||||
|
||||
**接口描述:**
|
||||
|
||||
|
||||
### 请求参数
|
||||
**Headers**
|
||||
|
||||
| 参数名称 | 参数值 | 是否必须 | 示例 | 备注 |
|
||||
| ------------ | ------------ | ------------ | ------------ | ------------ |
|
||||
| X-Auth-User | | 是 | | |
|
||||
| X-Auth-Project | | 是 | | |
|
||||
| X-Auth-token | | 是 | | |
|
||||
| Content-Type | multipart/form-data | 是 | | |
|
||||
**Query**
|
||||
|
||||
| 参数名称 | 是否必须 | 示例 | 备注 |
|
||||
| ------------ | ------------ | ------------ | ------------ |
|
||||
| qw | 是 | | |
|
||||
**Body**
|
||||
|
||||
| 参数名称 | 参数类型 | 是否必须 | 示例 | 备注 |
|
||||
| ------------ | ------------ | ------------ | ------------ | ------------ |
|
||||
| 1 | text | 是 | | |
|
||||
| 2 | file | 是 | | |
|
||||
|
||||
|
||||
|
||||
### 返回数据
|
||||
|
||||
```javascript
|
||||
{"type":"object","title":"empty object","properties":{"id":{"type":"object","properties":{"field_1":{"type":"object","properties":{"field_2":{"type":"object","properties":{"field_3":{"type":"object","properties":{"field_4":{"type":"object","properties":{"field_5":{"type":"object","properties":{"field_6":{"type":"object","properties":{"field_7额 u 俄 u 俄 u 茹茹茹茹茹茹茹rrururuueueue ":{"type":"string"}},"required":[]}}}}}}}}}}}}},"msg":{"type":"string"}},"required":[]}
|
||||
```
|
@ -85,6 +85,7 @@ export default class Run extends Component {
|
||||
test_script: '',
|
||||
hasPlugin: true,
|
||||
inputValue: '',
|
||||
cursurPosition: -1,
|
||||
envModalVisible: false,
|
||||
test_res_header: null,
|
||||
test_res_body: null,
|
||||
@ -141,21 +142,25 @@ export default class Run extends Component {
|
||||
const { req_body_other, req_body_type, req_body_is_json_schema } = data;
|
||||
let body = req_body_other;
|
||||
// 运行时才会进行转换
|
||||
if (this.props.type === 'inter' && req_body_type === 'json' && req_body_other && req_body_is_json_schema) {
|
||||
|
||||
let schema = {}
|
||||
if (
|
||||
this.props.type === 'inter' &&
|
||||
req_body_type === 'json' &&
|
||||
req_body_other &&
|
||||
req_body_is_json_schema
|
||||
) {
|
||||
let schema = {};
|
||||
try {
|
||||
schema = json5.parse(req_body_other);
|
||||
} catch (e) {
|
||||
console.log('e',e)
|
||||
return ;
|
||||
console.log('e', e);
|
||||
return;
|
||||
}
|
||||
let result = await axios.post('/api/interface/schema2json', {
|
||||
schema: schema,
|
||||
required: true
|
||||
});
|
||||
body = JSON.stringify(result.data);
|
||||
console.log('body',body);
|
||||
console.log('body', body);
|
||||
}
|
||||
|
||||
this.setState(
|
||||
@ -322,28 +327,67 @@ export default class Run extends Component {
|
||||
|
||||
// 模态框的相关操作
|
||||
showModal = (val, index, type) => {
|
||||
let oTxt1 = document.getElementById(`${type}_${index}`);
|
||||
let cursurPosition = oTxt1.selectionStart;
|
||||
|
||||
let inputValue = this.getInstallValue(val || '', cursurPosition).val
|
||||
this.setState({
|
||||
modalVisible: true,
|
||||
inputIndex: index,
|
||||
inputValue: val,
|
||||
inputValue,
|
||||
cursurPosition,
|
||||
modalType: type
|
||||
});
|
||||
};
|
||||
|
||||
// 点击插入
|
||||
handleModalOk = val => {
|
||||
const { inputIndex, modalType } = this.state;
|
||||
switch (modalType) {
|
||||
case 'req_body_form':
|
||||
this.changeBody(val, inputIndex);
|
||||
break;
|
||||
default:
|
||||
this.changeParam(modalType, val, inputIndex);
|
||||
break;
|
||||
}
|
||||
this.changeInstallParam(modalType, val, inputIndex);
|
||||
this.setState({ modalVisible: false });
|
||||
};
|
||||
|
||||
handleModalCancel = () => {
|
||||
this.setState({ modalVisible: false });
|
||||
this.setState({ modalVisible: false, cursurPosition: -1 });
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 获取截取的字符串
|
||||
getInstallValue = (oldValue, cursurPosition) => {
|
||||
let left = oldValue.substr(0, cursurPosition);
|
||||
let right = oldValue.substr(cursurPosition);
|
||||
|
||||
let leftPostion = left.lastIndexOf('{{');
|
||||
let leftPostion2 = left.lastIndexOf('}}');
|
||||
let rightPostion = right.indexOf('}}');
|
||||
// console.log(leftPostion, leftPostion2,rightPostion, rightPostion2);
|
||||
let val = '';
|
||||
// 需要切除原来的变量
|
||||
if (leftPostion !== -1 && rightPostion !==-1 && leftPostion > leftPostion2) {
|
||||
left = left.substr(0, leftPostion);
|
||||
right = right.substr(rightPostion + 2);
|
||||
val = oldValue.substring(leftPostion, cursurPosition+rightPostion+2)
|
||||
}
|
||||
return {
|
||||
left,
|
||||
right,
|
||||
val
|
||||
};
|
||||
}
|
||||
|
||||
// 根据鼠标位置动态插入数据
|
||||
changeInstallParam = (name, v, index, key) => {
|
||||
key = key || 'value';
|
||||
const pathParam = deepCopyJson(this.state[name]);
|
||||
let oldValue = pathParam[index][key] || '';
|
||||
let newValue = this.getInstallValue(oldValue, this.state.cursurPosition)
|
||||
let left = newValue.left;
|
||||
let right = newValue.right;
|
||||
pathParam[index][key] = `${left}${v}${right}`;
|
||||
this.setState({
|
||||
[name]: pathParam
|
||||
});
|
||||
};
|
||||
|
||||
// 环境变量模态框相关操作
|
||||
@ -492,6 +536,7 @@ export default class Run extends Component {
|
||||
className="value"
|
||||
onChange={e => this.changeParam('req_params', e.target.value, index)}
|
||||
placeholder="参数值"
|
||||
id={`req_params_${index}`}
|
||||
addonAfter={
|
||||
<Icon
|
||||
type="edit"
|
||||
@ -538,6 +583,7 @@ export default class Run extends Component {
|
||||
className="value"
|
||||
onChange={e => this.changeParam('req_query', e.target.value, index)}
|
||||
placeholder="参数值"
|
||||
id={`req_query_${index}`}
|
||||
addonAfter={
|
||||
<Icon
|
||||
type="edit"
|
||||
@ -564,6 +610,7 @@ export default class Run extends Component {
|
||||
className="value"
|
||||
onChange={e => this.changeParam('req_headers', e.target.value, index)}
|
||||
placeholder="参数值"
|
||||
id={`req_headers_${index}`}
|
||||
addonAfter={
|
||||
!item.abled && (
|
||||
<Icon
|
||||
@ -638,6 +685,7 @@ export default class Run extends Component {
|
||||
className="value"
|
||||
onChange={e => this.changeBody(e.target.value, index)}
|
||||
placeholder="参数值"
|
||||
id={`req_body_form_${index}`}
|
||||
addonAfter={
|
||||
<Icon
|
||||
type="edit"
|
||||
|
@ -229,10 +229,10 @@ function createSchemaTable(body) {
|
||||
return template;
|
||||
}
|
||||
|
||||
function createResponse(res_body, res_body_is_json_schema) {
|
||||
function createResponse(res_body, res_body_is_json_schema, res_body_type) {
|
||||
let resTitle = `\n### 返回数据\n\n`;
|
||||
if (res_body) {
|
||||
if (res_body_is_json_schema) {
|
||||
if (res_body_is_json_schema && res_body_type === 'json') {
|
||||
let resBody = createSchemaTable(res_body);
|
||||
return resTitle + resBody;
|
||||
} else {
|
||||
@ -268,7 +268,7 @@ function createInterMarkdown(basepath, listItem, isToc) {
|
||||
);
|
||||
// Response
|
||||
// Response-body
|
||||
mdTemplate += createResponse(listItem.res_body, listItem.res_body_is_json_schema);
|
||||
mdTemplate += createResponse(listItem.res_body, listItem.res_body_is_json_schema, listItem.res_body_type);
|
||||
|
||||
return mdTemplate;
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ class exportController extends baseController {
|
||||
return '';
|
||||
}
|
||||
);
|
||||
console.log('left', left);
|
||||
|
||||
return createHtml5(left || '', content);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user