| | |
| | | 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' |
| | |
| | | active: 'raw', |
| | | body: null, |
| | | response: null, |
| | | status: '' |
| | | status: '', |
| | | loading: false |
| | | } |
| | | |
| | | UNSAFE_componentWillMount() { |
| | |
| | | } else if (config.active === 'raw') { |
| | | if (config.raw) { |
| | | try { |
| | | raws = JSON.parse(config.raw) |
| | | } catch { |
| | | raws = config.raw.replace(/@userid@/ig, sessionStorage.getItem('UserID') || '').replace(/@LoginUID@/ig, sessionStorage.getItem('LoginUID') || '') |
| | | raws = JSON.parse(raws) |
| | | } catch (e) { |
| | | Modal.error({ |
| | | title: '参数格式错误,必须为JSON格式!' |
| | | }) |
| | |
| | | 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) |
| | | }, (err) => { |
| | | this.handleResponse(err) |
| | | }) |
| | | } else if (/dostars/ig.test(url)) { |
| | | } else if (/dostars|exstars/ig.test(url)) { |
| | | if (n) { |
| | | n = JSON.parse(n) |
| | | |
| | | n = this.encryptParam(n) |
| | | n = JSON.stringify(n) |
| | | } |
| | |
| | | |
| | | body = body.replace(/\n/ig, '<br/>') |
| | | body = body.replace(/\s/ig, ' ') |
| | | } catch { |
| | | } catch (e) { |
| | | body = null |
| | | } |
| | | } |
| | |
| | | body = `请求异常${status === 'Network Error' ? ',可能原因:1、网络异常;2、接口跨域。' : '!'}` |
| | | } |
| | | |
| | | this.setState({response: res, body, status}) |
| | | this.setState({response: res, body, status, loading: false}) |
| | | } |
| | | |
| | | encryptParam (param) { |
| | | param.nonc = Utils.getuuid() |
| | | param.nonc = param.nonc || Utils.getuuid() |
| | | |
| | | let keys = Object.keys(param).sort() |
| | | let values = '' |
| | | keys.forEach(key => { |
| | | if (key.toLowerCase() === 'rduri') return |
| | | if (key.toLowerCase() === 't' || key.toLowerCase() === 'sign' || param[key] === undefined) { |
| | | if (key.toLowerCase() === 'rduri' || key === 't') return |
| | | if (key.toLowerCase() === 'sign' || param[key] === undefined) { |
| | | delete param[key] |
| | | return |
| | | } |
| | |
| | | values += key + param[key] |
| | | } |
| | | }) |
| | | |
| | | param.sign = md5(values) |
| | | param.t = new Date().getTime() |
| | | param.t = param.t || new Date().getTime() |
| | | |
| | | window.mkInfo(values) |
| | | window.mkInfo(param.sign) |
| | | |
| | | return param |
| | | } |
| | |
| | | } |
| | | |
| | | 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 |
| | |
| | | <Radio value={'formData'}>formData</Radio> |
| | | <Radio value={'raw'}>raw</Radio> |
| | | </Radio.Group> |
| | | {active === 'raw' ? <span style={{float: 'right', color: '#a5a5a5', fontSize: '13px'}}>注:使用@userid@、@loginuid@时将自动替换。</span> : null} |
| | | </div> |
| | | <div className={'body-content ' + (active === 'none' ? 'show' : '')}> |
| | | <div className="no-body">This request does not have a body</div> |
| | |
| | | <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> |
| | | ) |