From 90180fc913ee8c02ff9e374db7d3029bd4f31d3e Mon Sep 17 00:00:00 2001 From: tiantang Date: Tue, 11 Jul 2023 23:07:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:http=E5=8F=82=E6=95=B0=E6=8E=A5=E5=85=A5?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/example/src/App.tsx | 79 ++++++++++++++++++- .../example/src/component/step/http/Body.tsx | 12 ++- .../example/src/component/step/http/Check.tsx | 59 +++++++------- .../src/component/step/http/Extract.tsx | 40 ++++++---- .../src/component/step/http/Headers.tsx | 13 ++- .../example/src/component/step/http/Host.tsx | 2 + .../src/component/step/http/Options.tsx | 4 +- .../src/component/step/http/Params.tsx | 52 ++++++------ .../example/src/component/step/http/edit.tsx | 32 +++++--- .../example/src/component/step/http/type.d.ts | 29 +++++-- platform/example/src/component/step/type.d.ts | 5 +- 11 files changed, 233 insertions(+), 94 deletions(-) diff --git a/platform/example/src/App.tsx b/platform/example/src/App.tsx index 409fd30..9253adc 100644 --- a/platform/example/src/App.tsx +++ b/platform/example/src/App.tsx @@ -21,9 +21,82 @@ const TmpDndList: StepDragType[] = [ } }) const dndList = [ - {id: 1, label: "组件1", value: "组件1",}, - {id: 2, label: "组件2", value: "组件2"}, - {id: 3, label: "组件3", value: "组件3"}, + {id: 1, + label: "组件1", + value: "组件1", + header:[], + params:[], + extract:[], + body:{ + code:"string", + contentype:"string" + }, + host:{ + agreement:"string", + port:111, + host:"string" + }, + url:{ + path:"", + method:"GET" + }, + options:{ + code:"string", + uploadType:"string", + requestSwitch:true, + timeout:5000, + redirect:true + } + }, + {id: 2, + label: "组件2", + value: "组件2", + header:[], + body:{ + code:"string", + contentype:"string" + }, + host:{ + agreement:"string", + port:111, + host:"string" + }, + url:{ + path:"", + method:"GET" + }, + options:{ + code:"string", + uploadType:"string", + requestSwitch:true, + timeout:5000, + redirect:true + }}, + {id: 3, + label: "组件3", + value: "组件3", + header:[], + body:{ + code:"string", + contentype:"string" + }, + host:{ + agreement:"string", + port:111, + host:"string" + }, + url:{ + path:"", + method:"GET" + }, + options:{ + code:"string", + uploadType:"string", + requestSwitch:true, + timeout:5000, + redirect:true + } + }, ].map((item: any, index) => { let content: Content = {...item} content.label = content.label += Math.random() diff --git a/platform/example/src/component/step/http/Body.tsx b/platform/example/src/component/step/http/Body.tsx index 9d3d8fb..731b6f5 100644 --- a/platform/example/src/component/step/http/Body.tsx +++ b/platform/example/src/component/step/http/Body.tsx @@ -2,6 +2,7 @@ import React, {ChangeEvent, Component} from "react"; import {Input, InputNumber, Select, Switch} from "antd"; import style from "./Http.module.less" import MonacoEditor from 'react-monaco-editor'; +import {BodyData, HttpProps, HttpState} from "@/component/step/http/type"; // import "monaco-editor/min/vs/editor/editor.main.css" // import scheme from "monaco-editor/min/vs/basic-languages/scheme/scheme" // import js from "monaco-editor/min/vs/basic-languages/javascript/javascript" @@ -502,11 +503,16 @@ class Body extends Component,HttpState>{ } } editorDidMount(editor, monaco) { - console.log('editorDidMount', editor); editor.focus(); } + dataChange(){ + this.props.onchange("body",this.state.options) + } onChange(newValue, e) { - console.log('onChange', newValue, e); + const state = this.state + state.options.code = newValue + this.setState(state); + this.dataChange() } handleChange (value:string){ console.log(value) @@ -538,7 +544,7 @@ class Body extends Component,HttpState>{ theme="vs-dark" value={code} options={options} - onChange={this.onChange} + onChange={(newValue, e)=>this.onChange(newValue, e)} editorDidMount={this.editorDidMount} /> diff --git a/platform/example/src/component/step/http/Check.tsx b/platform/example/src/component/step/http/Check.tsx index 1c3fe2d..9850952 100644 --- a/platform/example/src/component/step/http/Check.tsx +++ b/platform/example/src/component/step/http/Check.tsx @@ -3,6 +3,7 @@ import {Dropdown, Form, Input, InputRef, LabeledValue, MenuProps, Select, Space, import {FormInstance} from "antd/es/form"; import style from "@/component/step/http/Http.module.less"; import {PlusOutlined} from "@ant-design/icons"; +import {CheckData, CheckDataType, HeaderData, HttpProps} from "@/component/step/http/type"; type EditableTableProps = Parameters[0]; type ColumnTypes = Exclude; @@ -12,24 +13,19 @@ interface EditableRowProps { index: number; } -type HandleSave = (record: DataType) => void; +type HandleSave = (record: CheckDataType) => void; interface EditableCellProps { title: React.ReactNode; editable: boolean; children: React.ReactNode; - dataIndex: keyof DataType; - record: DataType; + dataIndex: keyof CheckDataType; + record: CheckDataType; handleSave: HandleSave } -interface DataType { - key: number - obj: React.Key - condition: CheckEnum - check: string -} + enum SelectAddEnum { ADD, @@ -132,7 +128,6 @@ const EditableCell: React.FC = ({ ); } - console.log(children) return {childNode}; }; @@ -150,22 +145,26 @@ const addSelectItem: MenuProps['items'] = [ ), } ] - -const Check = () => { - const [dataSource, setDataSource] = useState([ - { - key: 0, - condition: CheckEnum.lessEqual, - check: '', - obj: '', - }, - ]); +const defaultData = [ + { + key: 0, + condition: CheckEnum.lessEqual, + check: '', + obj: '', + }, +] +const Check = (props:HttpProps) => { + const data = props?.data||defaultData + const [dataSource, setDataSource] = useState(data); const [count, setCount] = useState(1); - + const dataChange = ()=>{ + props.onchange("header",dataSource) + } const handleDelete = (key: React.Key) => { const newData = dataSource.filter((item) => item.key !== key); setDataSource(newData); + dataChange() }; // 用户操作 const TitleSelectClick: MenuProps['onClick'] = ({key}) => { @@ -180,16 +179,14 @@ const Check = () => { default: break } - console.log(key) } const funcChange = (key: number, value: number) => { - console.log(key, value) const data = dataSource[Number(key)] - console.log(data) data.condition = Number(value) handleSave(data) + dataChange() } - const paramsRender = (type: CheckEnum, value: DataType, handleSave: HandleSave) => { + const paramsRender = (type: CheckEnum, value: CheckDataType, handleSave: HandleSave) => { return
123123
} const defaultColumns: (ColumnTypes[number] & { editable?: boolean; dataIndex: string })[] = [ @@ -203,7 +200,7 @@ const Check = () => { title: '检查条件', dataIndex: 'condition', width: "200px", - render: (_, record:DataType) => { + render: (_, record:CheckDataType) => { return (
路径 - + this.domChange(e,"code")} value={this.state.data.url.path} placeholder="" />
) diff --git a/platform/example/src/component/step/http/type.d.ts b/platform/example/src/component/step/http/type.d.ts index 0ef8032..2530d05 100644 --- a/platform/example/src/component/step/http/type.d.ts +++ b/platform/example/src/component/step/http/type.d.ts @@ -34,8 +34,15 @@ interface HttpData { options:OptionsData extract:ExtractData body:BodyData - [key:string]:allData + path:PathData + url:UrlData + // [key:string]:allData } +interface UrlData { + method:string + path:string +} + interface HostData { agreement:string port:number @@ -48,7 +55,7 @@ type BodyData ={ } type BodyDataType = keyof BodyData interface CheckData { - + data:CheckDataType[] } interface HeaderDataType { key: React.Key; @@ -58,14 +65,20 @@ interface HeaderDataType { interface HeaderData { data:HeaderDataType[] } -interface ParamsData { - +interface ParamsDataType{ + key: React.Key; + name: string; + value: string; } +type ParamsData = ParamsDataType[] interface BeforeRequestData { } interface ResponseData { +} +interface PathData { + } type OptionsData = { @@ -76,8 +89,14 @@ type OptionsData = { redirect:boolean } type OptionsDataType = keyof OptionsData +interface CheckDataType { + key: number + obj: React.Key + condition: CheckEnum + check: string +} interface ExtractData { - + data:DataType[] } interface childrenProps { diff --git a/platform/example/src/component/step/type.d.ts b/platform/example/src/component/step/type.d.ts index d516dad..3a89e8e 100644 --- a/platform/example/src/component/step/type.d.ts +++ b/platform/example/src/component/step/type.d.ts @@ -1,8 +1,9 @@ -import {Content} from "@/component/type"; +import {Content, StepDragType} from "@/component/type"; +import {HttpData} from "@/component/step/http/type"; export interface stepProps { updateData:(data:string)=>void - data:Content + data:HttpData } export interface stepState { data:string