表格分页点击下一页,搜索条件变化,查询不到数据

104 阅读1分钟

当查询时把上次提交的条件变为oldForm,新查询的条件设置newForm,当条件改变时,页码设置为1。

// 查询
    const pageConditionList = ['offset', 'limit', 'total']
    /**
     * 判断查询条件是不是 改变了
     * @param oldForm 上次提交的表单条件
     * @param newForm 新表单条件-
     * @returns {*}
     */
    static diffQueryCondition (oldForm, newForm) {
      if (oldForm) {
        for (let key in newForm) {
          // 当条件改变时,页码设置为1
          if (pageConditionList.indexOf(key) < 0) {
            if (newForm[key] !== oldForm[key]) {
              newForm.offset = 1
              break
            }
          }
        }
      }
      return newForm
    }
    onQuery () {
      this.form = Utils.diffQueryCondition(this.oldForm, this.form)
      this.oldForm = Object.assign({}, this.form)
      storeGameQueryApi(this.form).then(res => {
        console.log('', res)
        // 一系列操作
      })