From 31ec63f0419895876cbaba99637a884a32d33d0d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 01 九月 2021 10:31:45 +0800 Subject: [PATCH] 2021-09-01 --- src/views/interface/workspace/request/index.jsx | 32 +++++++++++++++++++++----------- 1 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/views/interface/workspace/request/index.jsx b/src/views/interface/workspace/request/index.jsx index 9e74b51..5c2536c 100644 --- a/src/views/interface/workspace/request/index.jsx +++ b/src/views/interface/workspace/request/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import { fromJS } from 'immutable' import md5 from 'md5' -import { Input, Select, Button, Tabs, Radio, Modal } from 'antd' +import { Input, Select, Button, Tabs, Radio, Modal, Spin } from 'antd' import Api from '@/views/interface/api' import Utils from '@/utils/utils.js' @@ -18,7 +18,8 @@ active: 'raw', body: null, response: null, - status: '' + status: '', + loading: false } UNSAFE_componentWillMount() { @@ -95,7 +96,7 @@ if (config.raw) { try { raws = JSON.parse(config.raw) - } catch { + } catch (e) { Modal.error({ title: '鍙傛暟鏍煎紡閿欒锛屽繀椤讳负JSON鏍煎紡锛�' }) @@ -145,6 +146,8 @@ n = JSON.stringify(n) } + this.setState({loading: true}) + if (/logon/ig.test(url)) { Api.dologon(url, config.method, header, n).then(res => { this.handleResponse(res) @@ -180,7 +183,7 @@ body = body.replace(/\n/ig, '<br/>') body = body.replace(/\s/ig, ' ') - } catch { + } catch (e) { body = null } } @@ -193,7 +196,7 @@ body = `璇锋眰寮傚父${status === 'Network Error' ? '锛屽彲鑳藉師鍥狅細1銆佺綉缁滃紓甯革紱2銆佹帴鍙h法鍩熴��' : '锛�'}` } - this.setState({response: res, body, status}) + this.setState({response: res, body, status, loading: false}) } encryptParam (param) { @@ -202,12 +205,18 @@ let keys = Object.keys(param).sort() let values = '' keys.forEach(key => { - if (key.toLowerCase() === 'rduri' || key.toLowerCase() === 't') return - if (param[key] === undefined) { + if (key.toLowerCase() === 'rduri') return + if (key.toLowerCase() === 't' || key.toLowerCase() === 'sign' || param[key] === undefined) { delete param[key] - } else if (typeof(param[key]) === 'object') { + return + } + + if (typeof(param[key]) === 'object') { values += key + JSON.stringify(param[key]) } else { + if (param[key] && /: =$/.test(param[key])) { + param[key] = param[key].replace(/: =$/, '==') + } values += key + param[key] } }) @@ -231,7 +240,7 @@ } render () { - const { active, config, response, body, status } = this.state + const { active, config, response, body, status, loading } = this.state let hasParam = config.params.filter(item => item.selected && item.key).length > 0 let hasHeader = config.headers.filter(item => item.selected && item.key).length @@ -256,7 +265,7 @@ <Button type="primary" onClick={this.send}>Send</Button> <Button onClick={this.save}>Save</Button> </div> - <Tabs animated={false}> + <Tabs animated={false} defaultActiveKey={hasBody ? 'Body' : 'Params'}> <Tabs.TabPane forceRender={true} tab={<span className={hasParam ? 'active' : ''}>Params</span>} key="Params"> <EditTable data={config.params} onChange={this.changeParams}/> </Tabs.TabPane> @@ -285,12 +294,13 @@ <div className="response"> {response ? <div className="header"> {body ? 'Body' : 'Response'} - {status ? <span className="status">Status: <span className={status === '200OK' ? 'green' : ''}>{status}</span></span> : null} + {status ? <span className="status">Status: <span className={status === '200OK' ? 'green' : 'yellow'}>{status}</span></span> : null} </div> : <div className="header"> Response <span className="empty">Hit the Send button to get a response.</span> </div>} <div style={{paddingLeft: '3px', paddingTop: '3px'}} dangerouslySetInnerHTML={{__html: body}}></div> + {loading ? <div className="pending"><Spin size="large"/></div> : null} </div> </div> ) -- Gitblit v1.8.0