king
2021-09-01 31ec63f0419895876cbaba99637a884a32d33d0d
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, '&nbsp;')
      } catch {
      } catch (e) {
        body = null
      }
    }
@@ -193,7 +196,7 @@
      body = `请求异常${status === 'Network Error' ? ',可能原因:1、网络异常;2、接口跨域。' : '!'}`
    }
    this.setState({response: res, body, status})
    this.setState({response: res, body, status, loading: false})
  }
  encryptParam (param) {
@@ -237,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
@@ -297,6 +300,7 @@
            <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>
    )