king
2023-03-15 3875da845b8fae679bd784d1246101a5fb1b61b5
src/views/interface/history/index.jsx
@@ -22,18 +22,51 @@
  componentDidMount() {
    MKEmitter.addListener('insertInterface', this.insertInterface)
    setTimeout(() => {
      Api.getInterfaces().then(res => {
        if (!res || !res.rows) return
      if (window.GLOB.IndexDB) {
        this.getHistory()
      } else {
        setTimeout(() => {
          this.getHistory()
        }, 1000)
      }
    }, 200)
  }
        let rows = [...res.rows]
        rows.sort((a,b) => {
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('insertInterface', this.insertInterface)
  }
  clear = () => {
    const _this = this
    confirm({
      content: 'Are you sure you want to clear all your history requests?',
      onOk() {
        Api.clearInterfaces()
        _this.setState({list: [], historys: []})
      },
      onCancel() {}
    })
  }
  getHistory = () => {
    Api.getInterfaces().then(res => {
      if (!res) return
      res.sort((a,b) => {
          return a.createDate < b.createDate ? 1 : -1
        })
        let list = []
        let item = null
        
        rows.forEach(m => {
      res.forEach(m => {
          let date = m.createDate.substring(0, 10)
          if (m.params) {
@@ -85,47 +118,15 @@
        this.setState({list, historys: fromJS(list).toJS()})
      })
    }, 200)
  }
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('insertInterface', this.insertInterface)
  }
  clear = () => {
    const _this = this
    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: '清除失败!请刷新重试。'
            })
          }
        })
      },
      onCancel() {}
    })
  }
  delete = (m) => {
    const { searchKey } = this.state
    Api.delInterface(m.uuid).then(res => {
      if (res) {
    Api.delInterface(m.id)
        let list = this.state.list.filter(item => {
          item.sublist = item.sublist.filter(cell => cell.uuid !== m.uuid)
      item.sublist = item.sublist.filter(cell => cell.id !== m.id)
  
          return item.sublist.length > 0
        })
@@ -140,20 +141,14 @@
        }
        this.setState({list, historys})
      } else {
        Modal.error({
          title: '删除失败!请刷新重试。'
        })
      }
    })
  }
  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) {
    Api.writeInIndexDB(item)
        let list = fromJS(this.state.list).toJS()
        if (list[0]) {
@@ -182,12 +177,6 @@
        }
        this.setState({ list, historys })
      } else {
        Modal.error({
          title: '添加失败!请刷新重试。'
        })
      }
    })
  }
  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">