Browse Source

fix: single page table cannot be refreshed by decrease

Casper Dai 3 years ago
parent
commit
a1ca47bf2c

+ 1 - 1
src/components/table/GridTable/index.vue

@@ -79,6 +79,7 @@
         :item-render="itemRender"
       />
       <pagination
+        v-if="needPagination"
         :total="options.totalCount"
         :page.sync="options.params.pageNum"
         :limit.sync="options.params.pageSize"
@@ -102,7 +103,6 @@ export default {
   data () {
     return {
       pageSize: 8,
-      needPagination: true,
       itemRender: null
     }
   },

+ 0 - 3
src/components/table/Table/index.vue

@@ -114,9 +114,6 @@ export default {
     }
   },
   computed: {
-    needPagination () {
-      return !this.schema.singlePage
-    },
     preventCopy () {
       return !!this.$listeners['row-dblclick']
     }

+ 6 - 4
src/components/table/mixins/table.js

@@ -69,6 +69,9 @@ export default {
           this.onPagination()
         }
       }
+    },
+    needPagination () {
+      return !this.schema.singlePage
     }
   },
   watch: {
@@ -214,17 +217,16 @@ export default {
       if (this.needPagination && pageNum >= 1) {
         return this.mergeCondition({ pageNum })
       }
-      return this.mergeCondition()
+      this.mergeCondition()
     },
     decrease (count) {
       if (this.needPagination) {
         const options = this.options
         if (options.list.length <= count) {
-          this.pageTo(options.params.pageNum - 1)
-        } else {
-          this.pageTo()
+          return this.pageTo(options.params.pageNum - 1)
         }
       }
+      this.pageTo()
     }
   }
 }

+ 5 - 1
src/views/device/detail/components/external/Sensors/Sensor.vue

@@ -40,7 +40,10 @@
       :visible.sync="show"
       custom-class="c-dialog"
     >
-      <schema-table :schema="schema" />
+      <schema-table
+        ref="table"
+        :schema="schema"
+      />
     </el-dialog>
   </div>
 </template>
@@ -119,6 +122,7 @@ export default {
   methods: {
     onUpdate (list) {
       this.list = list
+      this.$refs.table.pageTo()
     },
     getSensors () {
       return Promise.resolve({ data: this.list })

+ 3 - 3
src/views/device/mixins/index.js

@@ -1,19 +1,18 @@
 export default {
   data () {
     return {
+      isAdd: false,
       currObj: {}
     }
   },
   computed: {
-    isAdd () {
-      return !this.currObj.id
-    },
     dialogTitle () {
       return this.isAdd ? `新增${this.type}` : `编辑${this.type}`
     }
   },
   methods: {
     onAdd () {
+      this.isAdd = true
       this.currObj = this.getDefaults()
       this.$refs.editDialog.show()
     },
@@ -21,6 +20,7 @@ export default {
       return { name: '', remark: '' }
     },
     onEdit (item) {
+      this.isAdd = false
       this.currObj = this.beforeEdit(item)
       this.$currObj = item
       this.$refs.editDialog.show()