diff --git a/client/components/ModalPostman/index.js b/client/components/ModalPostman/index.js index 33c0a15b..946632e3 100644 --- a/client/components/ModalPostman/index.js +++ b/client/components/ModalPostman/index.js @@ -128,7 +128,7 @@ class ModalPostman extends Component { handleConstantsInput = (val) => { val = val.replace(/^\{\{(.+)\}\}$/g, '$1'); - console.log('val', val); + this.setState({ constantInput: val }) diff --git a/client/containers/Login/Login.js b/client/containers/Login/Login.js index b753548b..69df5f4a 100755 --- a/client/containers/Login/Login.js +++ b/client/containers/Login/Login.js @@ -53,7 +53,7 @@ class Login extends Component { form.validateFields((err, values) => { if (!err) { if (this.props.isLDAP && this.state.loginType === 'ldap') { - console.log('ldap'); + this.props.loginLdapActions(values).then((res) => { if (res.payload.data.errcode == 0) { this.props.history.replace('/group'); diff --git a/client/containers/News/NewsList/NewsList.js b/client/containers/News/NewsList/NewsList.js index 9721a9dd..f4453315 100755 --- a/client/containers/News/NewsList/NewsList.js +++ b/client/containers/News/NewsList/NewsList.js @@ -52,7 +52,7 @@ class NewsList extends Component { const that = this; this.props.setLoading(true); this.props.fetchNewsData(+this.props.uid,0,5).then(function(data){ - console.log(data.data); + that.props.setLoading(false); }) } diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js b/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js index 6a52e730..ce1696d2 100755 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js @@ -457,7 +457,6 @@ class InterfaceColContent extends Component { copyUrl =(url) =>{ - console.log('url',url); copy(url) message.success('已经成功复制到剪切板'); } diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js index 628563eb..258df7aa 100755 --- a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js @@ -1,39 +1,40 @@ -import React, { PureComponent as Component } from "react"; -import PropTypes from "prop-types"; -import { connect } from "react-redux"; -import _ from "underscore"; -import constants from "../../../../constants/variable.js"; -import { handlePath, nameLengthLimit } from "../../../../common.js"; -import { changeEditStatus } from "../../../../reducer/modules/interface.js"; -import json5 from "json5"; -import { message, Affix } from "antd"; -import EasyDragSort from "../../../../components/EasyDragSort/EasyDragSort.js"; -import mockEditor from "client/components/AceEditor/mockEditor"; -import axios from "axios"; -import formats from 'common/formats' -const jSchema = require("json-schema-editor-visual"); -const ResBodySchema = jSchema({lang: 'zh_CN', format: formats}); -const ReqBodySchema = jSchema({lang: 'zh_CN'}); +import React, { PureComponent as Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import _ from 'underscore'; +import constants from '../../../../constants/variable.js'; +import { handlePath, nameLengthLimit } from '../../../../common.js'; +import { changeEditStatus } from '../../../../reducer/modules/interface.js'; +import json5 from 'json5'; +import { message, Affix, Tabs } from 'antd'; +import EasyDragSort from '../../../../components/EasyDragSort/EasyDragSort.js'; +import mockEditor from 'client/components/AceEditor/mockEditor'; +import axios from 'axios'; +import formats from 'common/formats'; +const jSchema = require('json-schema-editor-visual'); +const ResBodySchema = jSchema({ lang: 'zh_CN', format: formats }); +const ReqBodySchema = jSchema({ lang: 'zh_CN' }); +const TabPane = Tabs.TabPane; -require("codemirror/lib/codemirror.css"); // codemirror -require("tui-editor/dist/tui-editor.css"); // editor ui -require("tui-editor/dist/tui-editor-contents.css"); // editor content -require("highlight.js/styles/github.css"); // code block highlight -require("./editor.css"); -var Editor = require("tui-editor"); +require('codemirror/lib/codemirror.css'); // codemirror +require('tui-editor/dist/tui-editor.css'); // editor ui +require('tui-editor/dist/tui-editor-contents.css'); // editor content +require('highlight.js/styles/github.css'); // code block highlight +require('./editor.css'); +var Editor = require('tui-editor'); function checkIsJsonSchema(json) { try { json = json5.parse(json); - if (json.properties && typeof json.properties === "object") { - if (!json.type) json.type = "object"; + if (json.properties && typeof json.properties === 'object') { + if (!json.type) json.type = 'object'; } - if (json.items && typeof json.items === "object") { - if (!json.type) json.type = "array"; + if (json.items && typeof json.items === 'object') { + if (!json.type) json.type = 'array'; } if (!json.type) return false; json.type = json.type.toLowerCase(); - let types = ["object", "string", "number", "array", "boolean", "integer"]; + let types = ['object', 'string', 'number', 'array', 'boolean', 'integer']; if (types.indexOf(json.type) === -1) return false; return JSON.stringify(json); } catch (e) { @@ -63,7 +64,7 @@ import { Icon, AutoComplete, Switch -} from "antd"; +} from 'antd'; const Json5Example = ` { @@ -83,15 +84,15 @@ const InputGroup = Input.Group; const RadioButton = Radio.Button; const RadioGroup = Radio.Group; const dataTpl = { - req_query: { name: "", required: "1", desc: "", example: "" }, - req_headers: { name: "", required: "1", desc: "", example: "" }, - req_params: { name: "", desc: "", example: "" }, + req_query: { name: '', required: '1', desc: '', example: '' }, + req_headers: { name: '', required: '1', desc: '', example: '' }, + req_params: { name: '', desc: '', example: '' }, req_body_form: { - name: "", - type: "text", - required: "1", - desc: "", - example: "" + name: '', + type: 'text', + required: '1', + desc: '', + example: '' } }; @@ -124,74 +125,70 @@ class InterfaceEditForm extends Component { }; initState(curdata) { - this.startTime = new Date().getTime() - if (curdata.req_query && curdata.req_query.length === 0) - delete curdata.req_query; - if (curdata.req_headers && curdata.req_headers.length === 0) - delete curdata.req_headers; - if (curdata.req_body_form && curdata.req_body_form.length === 0) - delete curdata.req_body_form; - if (curdata.req_params && curdata.req_params.length === 0) - delete curdata.req_params; + this.startTime = new Date().getTime(); + if (curdata.req_query && curdata.req_query.length === 0) delete curdata.req_query; + if (curdata.req_headers && curdata.req_headers.length === 0) delete curdata.req_headers; + if (curdata.req_body_form && curdata.req_body_form.length === 0) delete curdata.req_body_form; + if (curdata.req_params && curdata.req_params.length === 0) delete curdata.req_params; if (curdata.req_body_form) { curdata.req_body_form = curdata.req_body_form.map(item => { - item.type = item.type === "text" ? "text" : "file"; + item.type = item.type === 'text' ? 'text' : 'file'; return item; }); } // 设置标签的展开与折叠 - curdata["hideTabs"] = { + curdata['hideTabs'] = { req: { - body: "hide", - query: "hide", - headers: "hide" + body: 'hide', + query: 'hide', + headers: 'hide' } }; - curdata["hideTabs"]["req"][HTTP_METHOD[curdata.method].default_tab] = ""; + curdata['hideTabs']['req'][HTTP_METHOD[curdata.method].default_tab] = ''; return Object.assign( { submitStatus: false, - title: "", - path: "", - status: "undone", - method: "get", + title: '', + path: '', + status: 'undone', + method: 'get', req_params: [], req_query: [ { - name: "", - desc: "", - required: "1" + name: '', + desc: '', + required: '1' } ], req_headers: [ { - name: "", - value: "", - required: "1" + name: '', + value: '', + required: '1' } ], - req_body_type: "form", + req_body_type: 'form', req_body_form: [ { - name: "", - type: "text", - required: "1" + name: '', + type: 'text', + required: '1' } ], - req_body_other: "", + req_body_other: '', - res_body_type: "json", - res_body: "", - desc: "", - res_body_mock: "", - jsonType: "tpl", + res_body_type: 'json', + res_body: '', + desc: '', + res_body_mock: '', + jsonType: 'tpl', mockUrl: this.props.mockUrl, - req_radio_type: "req-query", - custom_field_value: "", + req_radio_type: 'req-query', + custom_field_value: '', api_opened: false }, curdata @@ -220,35 +217,25 @@ class InterfaceEditForm extends Component { if (!err) { values.desc = this.editor.getHtml(); values.markdown = this.editor.getMarkdown(); - if (values.res_body_type === "json") { - if ( - this.state.res_body && - validJson(this.state.res_body) === false - ) { - return message.error("返回body json格式有问题,请检查!"); + if (values.res_body_type === 'json') { + if (this.state.res_body && validJson(this.state.res_body) === false) { + return message.error('返回body json格式有问题,请检查!'); } try { - values.res_body = JSON.stringify( - JSON.parse(this.state.res_body), - null, - " " - ); + values.res_body = JSON.stringify(JSON.parse(this.state.res_body), null, ' '); } catch (e) { values.res_body = this.state.res_body; } } - if (values.req_body_type === "json") { - if ( - this.state.req_body_other && - validJson(this.state.req_body_other) === false - ) { - return message.error("响应Body json格式有问题,请检查!"); + if (values.req_body_type === 'json') { + if (this.state.req_body_other && validJson(this.state.req_body_other) === false) { + return message.error('响应Body json格式有问题,请检查!'); } try { values.req_body_other = JSON.stringify( JSON.parse(this.state.req_body_other), null, - " " + ' ' ); } catch (e) { values.req_body_other = this.state.req_body_other; @@ -260,57 +247,53 @@ class InterfaceEditForm extends Component { values.req_headers = values.req_headers || []; let isfile = false, isHavaContentType = false; - if (values.req_body_type === "form") { + if (values.req_body_type === 'form') { values.req_body_form.forEach(item => { - if (item.type === "file") { + if (item.type === 'file') { isfile = true; } }); values.req_headers.map(item => { - if (item.name === "Content-Type") { - item.value = isfile - ? "multipart/form-data" - : "application/x-www-form-urlencoded"; + if (item.name === 'Content-Type') { + item.value = isfile ? 'multipart/form-data' : 'application/x-www-form-urlencoded'; isHavaContentType = true; } }); if (isHavaContentType === false) { values.req_headers.unshift({ - name: "Content-Type", - value: isfile - ? "multipart/form-data" - : "application/x-www-form-urlencoded" + name: 'Content-Type', + value: isfile ? 'multipart/form-data' : 'application/x-www-form-urlencoded' }); } - } else if (values.req_body_type === "json") { + } else if (values.req_body_type === 'json') { values.req_headers ? values.req_headers.map(item => { - if (item.name === "Content-Type") { - item.value = "application/json"; - isHavaContentType = true; - } - }) + if (item.name === 'Content-Type') { + item.value = 'application/json'; + isHavaContentType = true; + } + }) : []; if (isHavaContentType === false) { values.req_headers = values.req_headers || []; values.req_headers.unshift({ - name: "Content-Type", - value: "application/json" + name: 'Content-Type', + value: 'application/json' }); } } values.req_headers = values.req_headers - ? values.req_headers.filter(item => item.name !== "") + ? values.req_headers.filter(item => item.name !== '') : []; values.req_body_form = values.req_body_form - ? values.req_body_form.filter(item => item.name !== "") + ? values.req_body_form.filter(item => item.name !== '') : []; values.req_params = values.req_params - ? values.req_params.filter(item => item.name !== "") + ? values.req_params.filter(item => item.name !== '') : []; values.req_query = values.req_query - ? values.req_query.filter(item => item.name !== "") + ? values.req_query.filter(item => item.name !== '') : []; if (HTTP_METHOD[values.method].request_body !== true) { @@ -320,13 +303,17 @@ class InterfaceEditForm extends Component { if (values.req_body_is_json_schema && values.req_body_other) { values.req_body_other = checkIsJsonSchema(values.req_body_other); if (!values.req_body_other) { - return message.error("请求参数 json-schema 格式有误"); + return message.error('请求参数 json-schema 格式有误'); } } - if (values.res_body_is_json_schema && values.res_body && values.res_body_type === 'json') { + if ( + values.res_body_is_json_schema && + values.res_body && + values.res_body_type === 'json' + ) { values.res_body = checkIsJsonSchema(values.res_body); if (!values.res_body) { - return message.error("返回数据 json-schema 格式有误"); + return message.error('返回数据 json-schema 格式有误'); } } @@ -344,12 +331,12 @@ class InterfaceEditForm extends Component { onChangeMethod = val => { let radio = []; if (HTTP_METHOD[val].request_body) { - radio = ["req", "body"]; + radio = ['req', 'body']; } else { - radio = ["req", "query"]; + radio = ['req', 'query']; } this.setState({ - req_radio_type: radio.join("-") + req_radio_type: radio.join('-') }); this.setState({ method: val }, () => { @@ -360,17 +347,15 @@ class InterfaceEditForm extends Component { componentDidMount() { EditFormContext = this; this.setState({ - req_radio_type: HTTP_METHOD[this.state.method].request_body - ? "req-body" - : "req-query" + req_radio_type: HTTP_METHOD[this.state.method].request_body ? 'req-body' : 'req-query' }); let that = this; const initReqBody = that.state.req_body_other; const initResBody = that.state.res_body; mockEditor({ - container: "req_body_json", + container: 'req_body_json', data: that.state.req_body_other, - onChange: function (d) { + onChange: function(d) { that.setState({ req_body_other: d.text }); @@ -380,9 +365,9 @@ class InterfaceEditForm extends Component { }); this.resBodyEditor = mockEditor({ - container: "res_body_json", + container: 'res_body_json', data: that.state.res_body, - onChange: function (d) { + onChange: function(d) { that.setState({ res_body: d.text }); @@ -391,16 +376,16 @@ class InterfaceEditForm extends Component { fullScreen: true }); - // this.mockPreview = mockEditor({ - // container: "mock-preview", - // data: "", - // readOnly: true - // }); + this.mockPreview = mockEditor({ + container: "mock-preview", + data: "", + readOnly: true + }); this.editor = new Editor({ - el: document.querySelector("#desc"), - initialEditType: "wysiwyg", - height: "500px", + el: document.querySelector('#desc'), + initialEditType: 'wysiwyg', + height: '500px', initialValue: this.state.markdown || this.state.desc }); } @@ -427,30 +412,30 @@ class InterfaceEditForm extends Component { }; handleMockPreview = async () => { - let str = ""; + let str = ''; try { - if (this.props.form.getFieldValue("res_body_is_json_schema")) { - let schema = json5.parse(this.props.form.getFieldValue("res_body")); - let result = await axios.post("/api/interface/schema2json", { + if (this.props.form.getFieldValue('res_body_is_json_schema')) { + let schema = json5.parse(this.props.form.getFieldValue('res_body')); + let result = await axios.post('/api/interface/schema2json', { schema: schema }); return this.mockPreview.setValue(JSON.stringify(result.data)); } if (this.resBodyEditor.curData.format === true) { - str = JSON.stringify(this.resBodyEditor.curData.mockData(), null, " "); + str = JSON.stringify(this.resBodyEditor.curData.mockData(), null, ' '); } else { - str = "解析出错: " + this.resBodyEditor.curData.format; + str = '解析出错: ' + this.resBodyEditor.curData.format; } } catch (err) { - str = "解析出错: " + err.message; + str = '解析出错: ' + err.message; } this.mockPreview.setValue(str); }; handleJsonType = key => { - key = key || "tpl"; - if (key === "preview") { + key = key || 'tpl'; + if (key === 'preview') { this.handleMockPreview(); } this.setState({ @@ -467,19 +452,19 @@ class InterfaceEditForm extends Component { if (findExist) { queue.push(findExist); } else { - queue.push({ name: name, desc: "" }); + queue.push({ name: name, desc: '' }); } }; val = handlePath(val); this.props.form.setFieldsValue({ path: val }); - if (val && val.indexOf(":") !== -1) { - let paths = val.split("/"), + if (val && val.indexOf(':') !== -1) { + let paths = val.split('/'), name, i; for (i = 1; i < paths.length; i++) { - if (paths[i][0] === ":") { + if (paths[i][0] === ':') { name = paths[i].substr(1); insertParams(name); } @@ -487,7 +472,7 @@ class InterfaceEditForm extends Component { } if (val && val.length > 3) { - val.replace(/\{(.+?)\}/g, function (str, match) { + val.replace(/\{(.+?)\}/g, function(str, match) { insertParams(match); }); } @@ -499,8 +484,8 @@ class InterfaceEditForm extends Component { // 点击切换radio changeRadioGroup = e => { - const res = e.target.value.split("-"); - if (res[0] === "req") { + const res = e.target.value.split('-'); + if (res[0] === 'req') { this.setState({ req_radio_type: e.target.value }); @@ -512,10 +497,10 @@ class InterfaceEditForm extends Component { const obj = {}; // 先全部隐藏 for (let key in this.state.hideTabs[group]) { - obj[key] = "hide"; + obj[key] = 'hide'; } // 再取消选中项目的隐藏 - obj[item] = ""; + obj[item] = ''; this.setState({ hideTabs: { ...this.state.hideTabs, @@ -545,19 +530,21 @@ class InterfaceEditForm extends Component { let res_body = ''; let req_body_other = ''; try { - res_body = this.state.res_body ? JSON.stringify(json5.parse(this.state.res_body), null, 2) : '' + res_body = this.state.res_body + ? JSON.stringify(json5.parse(this.state.res_body), null, 2) + : ''; } catch (e) { res_body = ''; } - try { - req_body_other = this.state.req_body_other ? JSON.stringify(json5.parse(this.state.req_body_other), null, 2) : ''; + req_body_other = this.state.req_body_other + ? JSON.stringify(json5.parse(this.state.req_body_other), null, 2) + : ''; } catch (e) { - req_body_other = '' + req_body_other = ''; } - const queryTpl = (data, index) => { return ( @@ -568,22 +555,13 @@ class InterfaceEditForm extends Component { > - - {getFieldDecorator("req_query[" + index + "].name", { + + {getFieldDecorator('req_query[' + index + '].name', { initialValue: data.name - })( -