mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-07 14:16:52 +08:00
feat: 在组件中加入输入框
This commit is contained in:
parent
0ac47cf6fa
commit
ce65b110a1
@ -1,29 +1,44 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Row, Input, Radio, Icon } from 'antd';
|
import { Row, Radio, Icon, Input, Select } from 'antd';
|
||||||
import common from 'common/power-string.js'
|
import common from 'common/power-string.js'
|
||||||
import { autobind } from 'core-decorators';
|
const Option = Select.Option;
|
||||||
|
|
||||||
const RadioButton = Radio.Button;
|
const RadioButton = Radio.Button;
|
||||||
const RadioGroup = Radio.Group;
|
const RadioGroup = Radio.Group;
|
||||||
const Search = Input.Search;
|
|
||||||
|
|
||||||
|
// const list = METHODS_LIST.slice(0,4);
|
||||||
|
const inputComponent = () => {
|
||||||
|
return <Input size="small" placeholder="small size" />
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectComponent = (value) => {
|
||||||
|
// console.log('props', props);
|
||||||
|
// const subname = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512'];
|
||||||
|
return <Select defaultValue="sha1" style={{ width: 150 }} size="small" >
|
||||||
|
{
|
||||||
|
value.map((item, index) => {
|
||||||
|
return <Option value={item} key={index}>{item}</Option>
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
}
|
||||||
|
|
||||||
const METHODS_LIST = [
|
const METHODS_LIST = [
|
||||||
{ name: 'md5', type: false },
|
{ name: 'md5', type: false },
|
||||||
{ name: 'lower', type: false },
|
{ name: 'lower', type: false },
|
||||||
{ name: 'length', type: false },
|
{ name: 'length', type: false },
|
||||||
{ name: 'substr', type: true },
|
{ name: 'substr', type: true },
|
||||||
{ name: 'sha', type: false, subname: ['sha1', 'sha224', 'sha256', 'sha384', 'sha512'] },
|
{ name: 'sha', type: true, component: selectComponent(['sha1', 'sha224', 'sha256', 'sha384', 'sha512']), subname: ['sha1', 'sha224', 'sha256', 'sha384', 'sha512'] },
|
||||||
{ name: 'base64', type: false },
|
{ name: 'base64', type: false },
|
||||||
{ name: 'unbase64', type: false },
|
{ name: 'unbase64', type: false },
|
||||||
{ name: 'concat', type: true },
|
{ name: 'concat', type: true, component: inputComponent() },
|
||||||
{ name: 'lconcat', type: true },
|
{ name: 'lconcat', type: true, component: inputComponent() },
|
||||||
{ name: 'upper', type: false }
|
{ name: 'upper', type: false }
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
// const list = METHODS_LIST.slice(0,4);
|
|
||||||
|
|
||||||
|
|
||||||
class MethodsList extends Component {
|
class MethodsList extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@ -48,20 +63,14 @@ class MethodsList extends Component {
|
|||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
// console.log("nextProps",nextProps);
|
// console.log("nextProps",nextProps);
|
||||||
if(this.props.show !==nextProps.show){
|
if (this.props.show !== nextProps.show) {
|
||||||
this.unshowMore();
|
this.unshowMore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
|
||||||
onFilter() {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
showMore = () => {
|
||||||
|
|
||||||
|
|
||||||
@autobind
|
|
||||||
showMore() {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
list: METHODS_LIST,
|
list: METHODS_LIST,
|
||||||
moreFlag: false
|
moreFlag: false
|
||||||
@ -69,8 +78,8 @@ class MethodsList extends Component {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
|
||||||
unshowMore() {
|
unshowMore = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
list: METHODS_LIST.slice(0, 4),
|
list: METHODS_LIST.slice(0, 4),
|
||||||
moreFlag: true
|
moreFlag: true
|
||||||
@ -79,15 +88,21 @@ class MethodsList extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { list, moreFlag } = this.state;
|
const { list, moreFlag } = this.state;
|
||||||
const {click, clickValue} = this.props;
|
const { click } = this.props;
|
||||||
return (
|
return (
|
||||||
<div className="modal-postman-form-method">
|
<div className="modal-postman-form-method">
|
||||||
<h3 className="methods-title title">方法</h3>
|
<h3 className="methods-title title">方法</h3>
|
||||||
<RadioGroup onChange={click} value={clickValue}>
|
<RadioGroup onChange={click}>
|
||||||
{
|
{
|
||||||
list.map((item, index) => {
|
list.map((item, index) => {
|
||||||
return <Row key={index} type="flex" align="middle" className="row methods-row" >
|
return <Row key={index} type="flex" align="middle" className="row methods-row" >
|
||||||
<RadioButton value={item.name}>{item.name}</RadioButton>
|
<RadioButton value={item.name}>
|
||||||
|
<span>{item.name}</span>
|
||||||
|
<span className="input-component">
|
||||||
|
{item.type && item.component}
|
||||||
|
</span>
|
||||||
|
</RadioButton>
|
||||||
|
|
||||||
</Row>
|
</Row>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ import React, { Component } from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Row, Input, Radio } from 'antd';
|
import { Row, Input, Radio } from 'antd';
|
||||||
import constants from '../../constants/variable.js'
|
import constants from '../../constants/variable.js'
|
||||||
import { autobind } from 'core-decorators';
|
|
||||||
const wordList = constants.MOCK_SOURCE;
|
const wordList = constants.MOCK_SOURCE;
|
||||||
const RadioButton = Radio.Button;
|
const RadioButton = Radio.Button;
|
||||||
const RadioGroup = Radio.Group;
|
const RadioGroup = Radio.Group;
|
||||||
@ -31,8 +30,8 @@ class MockList extends Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
|
||||||
onFilter(e) {
|
onFilter= (e)=> {
|
||||||
|
|
||||||
const list = wordList.filter(item => {
|
const list = wordList.filter(item => {
|
||||||
return item.mock.indexOf(e.target.value) !== -1
|
return item.mock.indexOf(e.target.value) !== -1
|
||||||
@ -43,10 +42,10 @@ class MockList extends Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
|
||||||
onSearch(v){
|
onSearch=(v)=>{
|
||||||
console.log(v);
|
console.log("v",v);
|
||||||
this.props.click();
|
// this.props.click(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -5,7 +5,7 @@ import PropTypes from 'prop-types'
|
|||||||
import './index.scss'
|
import './index.scss'
|
||||||
// import { withRouter } from 'react-router-dom';
|
// import { withRouter } from 'react-router-dom';
|
||||||
import { Modal, Row, Col, Icon } from 'antd';
|
import { Modal, Row, Col, Icon } from 'antd';
|
||||||
import { autobind } from 'core-decorators';
|
// import { autobind } from 'core-decorators';
|
||||||
import MockList from './MockList.js';
|
import MockList from './MockList.js';
|
||||||
import MethodsList from './MethodsList.js'
|
import MethodsList from './MethodsList.js'
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ class ModalPostman extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
clickValue: '',
|
clickValue: [],
|
||||||
methodsShow: false,
|
methodsShow: false,
|
||||||
methodsShowMore: false,
|
methodsShowMore: false,
|
||||||
arr: [],
|
arr: [],
|
||||||
@ -33,18 +33,19 @@ class ModalPostman extends Component {
|
|||||||
mockClick(index) {
|
mockClick(index) {
|
||||||
|
|
||||||
return (e) => {
|
return (e) => {
|
||||||
this.setState({
|
if (index === 0) {
|
||||||
clickValue: e.target.value
|
|
||||||
})
|
|
||||||
if (index === -1) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
|
clickValue: [].concat([], e.target.value ),
|
||||||
arr: []
|
arr: []
|
||||||
})
|
})
|
||||||
this.createArrList([]);
|
this.createArrList([]);
|
||||||
} else {
|
} else {
|
||||||
let newArr = [].concat(this.state.arr);
|
let newArr = [].concat(this.state.arr);
|
||||||
|
let newValue = [].concat(this.state.clickValue);
|
||||||
newArr.splice(index + 1, newArr.length - index - 1)
|
newArr.splice(index + 1, newArr.length - index - 1)
|
||||||
|
newValue.splice(index + 1, newValue.length - index - 1)
|
||||||
this.setState({
|
this.setState({
|
||||||
|
clickValue: [].concat(newValue, e.target.value ),
|
||||||
arr: newArr
|
arr: newArr
|
||||||
})
|
})
|
||||||
this.createArrList(newArr)
|
this.createArrList(newArr)
|
||||||
@ -56,16 +57,15 @@ class ModalPostman extends Component {
|
|||||||
|
|
||||||
|
|
||||||
createArrList(arr) {
|
createArrList(arr) {
|
||||||
// let arr = [];
|
|
||||||
const ListSource = (props) => {
|
const ListSource = (props) => {
|
||||||
console.log(props)
|
|
||||||
return <MethodsList
|
return <MethodsList
|
||||||
show={this.state.methodsShowMore}
|
show={this.state.methodsShowMore}
|
||||||
click={this.mockClick(props.index)}
|
click={this.mockClick(props.index)}
|
||||||
clickValue={this.state.clickValue}
|
clickValue={this.state.clickValue[props.index]}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
// this.state.arr.push(ListSource)
|
|
||||||
this.setState({
|
this.setState({
|
||||||
arr: [].concat(arr, ListSource)
|
arr: [].concat(arr, ListSource)
|
||||||
})
|
})
|
||||||
@ -75,8 +75,8 @@ class ModalPostman extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { visible, handleCancel, handleOk } = this.props
|
const { visible, handleCancel, handleOk } = this.props
|
||||||
const { clickValue, count } = this.state;
|
const { clickValue } = this.state;
|
||||||
console.log('count', count);
|
console.log('clickValue', clickValue);
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={<p><Icon type="edit" /> 高级参数设置</p>}
|
title={<p><Icon type="edit" /> 高级参数设置</p>}
|
||||||
@ -87,24 +87,18 @@ class ModalPostman extends Component {
|
|||||||
width={800}
|
width={800}
|
||||||
>
|
>
|
||||||
|
|
||||||
<Row className="modal-postman-form" type="flex" flex-flow="row nowrap">
|
<Row className="modal-postman-form" type="flex">
|
||||||
<Col span={8} className="modal-postman-col">
|
<Col span={8} className="modal-postman-col">
|
||||||
<MockList click={this.mockClick(-1)} clickValue={clickValue}></MockList>
|
<MockList click={this.mockClick(0)} clickValue={clickValue[0]}></MockList>
|
||||||
<h3>变量</h3>
|
<h3>变量</h3>
|
||||||
</Col>
|
</Col>
|
||||||
{
|
{
|
||||||
this.state.arr.map((ListSourceComponent, index) => {
|
this.state.arr.map((ListSourceComponent, index) => {
|
||||||
return <Col span={8} className="modal-postman-col" key={index}>
|
return <Col span={8} className="modal-postman-col" key={index}>
|
||||||
<ListSourceComponent index={index} />
|
<ListSourceComponent index={index+1} />
|
||||||
</Col>
|
</Col>
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
{/* <Col span={8} className="modal-postman-col">
|
|
||||||
{
|
|
||||||
methodsShow ? <MethodsList show={methodsShowMore} click={this.mockClick} clickValue={clickValue}></MethodsList> : <div>没有值</div>
|
|
||||||
}
|
|
||||||
</Col> */}
|
|
||||||
</Row>
|
</Row>
|
||||||
<Row className="modal-postman-expression">
|
<Row className="modal-postman-expression">
|
||||||
<Col span={6}><h3 className="title">输入值</h3></Col>
|
<Col span={6}><h3 className="title">输入值</h3></Col>
|
||||||
|
@ -67,7 +67,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.methods-row{
|
.methods-row{
|
||||||
|
position: relative;
|
||||||
// border-bottom: 1px solid #e9e9e9;
|
// border-bottom: 1px solid #e9e9e9;
|
||||||
|
label{
|
||||||
|
position: unset;
|
||||||
|
}
|
||||||
|
.ant-radio-button-wrapper{
|
||||||
|
position: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-select-selection__rendered{
|
||||||
|
height: 26px;
|
||||||
|
line-height: 26px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-postman-col{
|
.modal-postman-col{
|
||||||
@ -83,5 +95,12 @@
|
|||||||
.ant-row-flex {
|
.ant-row-flex {
|
||||||
flex-wrap: nowrap
|
flex-wrap: nowrap
|
||||||
}
|
}
|
||||||
|
.input-component {
|
||||||
|
position: absolute;
|
||||||
|
top: 2px;
|
||||||
|
right: 0;
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user