| | |
| | | componentDidMount() { |
| | | MKEmitter.addListener('insertInterface', this.insertInterface) |
| | | setTimeout(() => { |
| | | Api.getInterfaces().then(res => { |
| | | if (!res || !res.rows) return |
| | | |
| | | let rows = [...res.rows] |
| | | rows.sort((a,b) => { |
| | | return a.createDate < b.createDate ? 1 : -1 |
| | | }) |
| | | |
| | | let list = [] |
| | | let item = null |
| | | |
| | | rows.forEach(m => { |
| | | let date = m.createDate.substring(0, 10) |
| | | |
| | | if (m.params) { |
| | | try { |
| | | m.params = JSON.parse(m.params) |
| | | } catch (e) { |
| | | m.params = [] |
| | | } |
| | | } else { |
| | | m.params = [] |
| | | } |
| | | |
| | | if (m.headers) { |
| | | try { |
| | | m.headers = JSON.parse(m.headers) |
| | | } catch (e) { |
| | | m.headers = [] |
| | | } |
| | | } else { |
| | | m.headers = [] |
| | | } |
| | | |
| | | if (m.formData) { |
| | | try { |
| | | m.formData = JSON.parse(m.formData) |
| | | } catch (e) { |
| | | m.formData = [] |
| | | } |
| | | } else { |
| | | m.formData = [] |
| | | } |
| | | |
| | | if (item && item.date !== date) { |
| | | list.push(item) |
| | | item = null |
| | | } |
| | | |
| | | if (!item) { |
| | | item = {date, sublist: []} |
| | | item.sublist.push(m) |
| | | } else if (item && item.date === date) { |
| | | item.sublist.push(m) |
| | | } |
| | | }) |
| | | |
| | | if (item) { |
| | | list.push(item) |
| | | } |
| | | |
| | | this.setState({list, historys: fromJS(list).toJS()}) |
| | | }) |
| | | if (window.GLOB.IndexDB) { |
| | | this.getHistory() |
| | | } else { |
| | | setTimeout(() => { |
| | | this.getHistory() |
| | | }, 1000) |
| | | } |
| | | }, 200) |
| | | } |
| | | |
| | |
| | | confirm({ |
| | | content: 'Are you sure you want to clear all your history requests?', |
| | | onOk() { |
| | | Api.clearInterfaces().then(res => { |
| | | if (res && res.rows.length === 0) { |
| | | _this.setState({list: [], historys: []}) |
| | | Modal.success({ |
| | | title: '清除成功。' |
| | | }) |
| | | } else { |
| | | Modal.error({ |
| | | title: '清除失败!请刷新重试。' |
| | | }) |
| | | } |
| | | }) |
| | | Api.clearInterfaces() |
| | | |
| | | _this.setState({list: [], historys: []}) |
| | | }, |
| | | onCancel() {} |
| | | }) |
| | | } |
| | | |
| | | delete = (m) => { |
| | | const { searchKey } = this.state |
| | | Api.delInterface(m.uuid).then(res => { |
| | | if (res) { |
| | | let list = this.state.list.filter(item => { |
| | | item.sublist = item.sublist.filter(cell => cell.uuid !== m.uuid) |
| | | |
| | | return item.sublist.length > 0 |
| | | }) |
| | | getHistory = () => { |
| | | Api.getInterfaces().then(res => { |
| | | if (!res) return |
| | | |
| | | let historys = fromJS(list).toJS() |
| | | if (searchKey) { |
| | | historys = historys.filter(item => { |
| | | item.sublist = item.sublist.filter(cell => cell.interface.indexOf(searchKey) > -1) |
| | | |
| | | return item.sublist.length > 0 |
| | | }) |
| | | res.sort((a,b) => { |
| | | return a.createDate < b.createDate ? 1 : -1 |
| | | }) |
| | | |
| | | let list = [] |
| | | let item = null |
| | | |
| | | res.forEach(m => { |
| | | let date = m.createDate.substring(0, 10) |
| | | |
| | | if (m.params) { |
| | | try { |
| | | m.params = JSON.parse(m.params) |
| | | } catch (e) { |
| | | m.params = [] |
| | | } |
| | | } else { |
| | | m.params = [] |
| | | } |
| | | |
| | | this.setState({list, historys}) |
| | | } else { |
| | | Modal.error({ |
| | | title: '删除失败!请刷新重试。' |
| | | }) |
| | | if (m.headers) { |
| | | try { |
| | | m.headers = JSON.parse(m.headers) |
| | | } catch (e) { |
| | | m.headers = [] |
| | | } |
| | | } else { |
| | | m.headers = [] |
| | | } |
| | | |
| | | if (m.formData) { |
| | | try { |
| | | m.formData = JSON.parse(m.formData) |
| | | } catch (e) { |
| | | m.formData = [] |
| | | } |
| | | } else { |
| | | m.formData = [] |
| | | } |
| | | |
| | | if (item && item.date !== date) { |
| | | list.push(item) |
| | | item = null |
| | | } |
| | | |
| | | if (!item) { |
| | | item = {date, sublist: []} |
| | | item.sublist.push(m) |
| | | } else if (item && item.date === date) { |
| | | item.sublist.push(m) |
| | | } |
| | | }) |
| | | |
| | | if (item) { |
| | | list.push(item) |
| | | } |
| | | |
| | | this.setState({list, historys: fromJS(list).toJS()}) |
| | | }) |
| | | } |
| | | |
| | | delete = (m) => { |
| | | const { searchKey } = this.state |
| | | |
| | | Api.delInterface(m.id) |
| | | |
| | | let list = this.state.list.filter(item => { |
| | | item.sublist = item.sublist.filter(cell => cell.id !== m.id) |
| | | |
| | | return item.sublist.length > 0 |
| | | }) |
| | | |
| | | let historys = fromJS(list).toJS() |
| | | if (searchKey) { |
| | | historys = historys.filter(item => { |
| | | item.sublist = item.sublist.filter(cell => cell.interface.indexOf(searchKey) > -1) |
| | | |
| | | return item.sublist.length > 0 |
| | | }) |
| | | } |
| | | |
| | | this.setState({list, historys}) |
| | | } |
| | | |
| | | insertInterface = (item) => { |
| | | item.uuid = Utils.getuuid() |
| | | item.id = Utils.getuuid() |
| | | item.createDate = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | |
| | | Api.writeInWebSql([item.uuid, item.createDate, item.method, item.interface, JSON.stringify(item.params), JSON.stringify(item.headers), item.active, item.raw, JSON.stringify(item.formData)]).then(res => { |
| | | if (res) { |
| | | let list = fromJS(this.state.list).toJS() |
| | | Api.writeInIndexDB(item) |
| | | |
| | | if (list[0]) { |
| | | if (list[0].date === item.createDate.substring(0, 10)) { |
| | | list[0].sublist.unshift(item) |
| | | } else { |
| | | list.unshift({ |
| | | date: item.createDate.substring(0, 10), |
| | | sublist: [item] |
| | | }) |
| | | } |
| | | } else { |
| | | list.push({ |
| | | date: item.createDate.substring(0, 10), |
| | | sublist: [item] |
| | | }) |
| | | } |
| | | let list = fromJS(this.state.list).toJS() |
| | | |
| | | let historys = fromJS(list).toJS() |
| | | if (this.state.searchKey) { |
| | | historys = historys.filter(item => { |
| | | item.sublist = item.sublist.filter(cell => cell.interface.indexOf(this.state.searchKey) > -1) |
| | | |
| | | return item.sublist.length > 0 |
| | | }) |
| | | } |
| | | |
| | | this.setState({ list, historys }) |
| | | if (list[0]) { |
| | | if (list[0].date === item.createDate.substring(0, 10)) { |
| | | list[0].sublist.unshift(item) |
| | | } else { |
| | | Modal.error({ |
| | | title: '添加失败!请刷新重试。' |
| | | list.unshift({ |
| | | date: item.createDate.substring(0, 10), |
| | | sublist: [item] |
| | | }) |
| | | } |
| | | }) |
| | | } else { |
| | | list.push({ |
| | | date: item.createDate.substring(0, 10), |
| | | sublist: [item] |
| | | }) |
| | | } |
| | | |
| | | let historys = fromJS(list).toJS() |
| | | if (this.state.searchKey) { |
| | | historys = historys.filter(item => { |
| | | item.sublist = item.sublist.filter(cell => cell.interface.indexOf(this.state.searchKey) > -1) |
| | | |
| | | return item.sublist.length > 0 |
| | | }) |
| | | } |
| | | |
| | | this.setState({ list, historys }) |
| | | } |
| | | |
| | | use = (m) => { |
| | |
| | | method: 'POST', |
| | | params: [], |
| | | raw: "{\n \"UserName\":\"******\",\n \"Password\":\"******\",\n \"systemType\":\"local\",\n \"Type\":\"公钥\",\n \"privatekey\":\"私钥\",\n \"timestamp\":\"" + moment().format('YYYY-MM-DD HH:mm:ss') + "\",\n \"appkey\":\"" + window.GLOB.appkey + "\"\n}", |
| | | uuid: 'dologon' |
| | | id: 'dologon' |
| | | } |
| | | |
| | | if (window.GLOB.mainSystemApi) { |
| | |
| | | method: 'POST', |
| | | params: [], |
| | | raw: "{\n \"func\":\"******\",\n \"LoginUID\":\"" + (sessionStorage.getItem('LoginUID') || "******") + "\",\n \"UserID\":\"" + (sessionStorage.getItem('UserID') || "******") + "\",\n \"nonc\":\"" + Utils.getguid() + "\",\n \"t\":" + parseInt(new Date().getTime() / 1000) + "\n}", |
| | | uuid: 'dologon' |
| | | id: 'dologon' |
| | | } |
| | | MKEmitter.emit('useInterface', m) |
| | | } |
| | |
| | | <div className="list-line" key={index}> |
| | | <div className="line-title">{item.date}</div> |
| | | {item.sublist.map(m => ( |
| | | <div className="line-item" key={m.uuid}> |
| | | <div className="line-item" key={m.id}> |
| | | <div className="method">POST</div> |
| | | <div className="inter">{m.interface}</div> |
| | | <div className="action"> |