From 3875da845b8fae679bd784d1246101a5fb1b61b5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 15 三月 2023 16:33:20 +0800 Subject: [PATCH] 2023-03-15 --- src/views/interface/history/index.jsx | 251 ++++++++++++++++++++++++-------------------------- 1 files changed, 120 insertions(+), 131 deletions(-) diff --git a/src/views/interface/history/index.jsx b/src/views/interface/history/index.jsx index 0db24fe..c9c9143 100644 --- a/src/views/interface/history/index.jsx +++ b/src/views/interface/history/index.jsx @@ -22,69 +22,13 @@ 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) } @@ -103,91 +47,136 @@ 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) => { @@ -204,7 +193,7 @@ 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) { @@ -223,7 +212,7 @@ 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) } @@ -258,7 +247,7 @@ <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"> -- Gitblit v1.8.0