wolyshaw 4 年之前
父节点
当前提交
026d13ae90

+ 8 - 11
src/components/Pagination/index.vue

@@ -61,7 +61,6 @@ export default {
   computed: {
     currentPage: {
       get () {
-        console.log(this.page)
         return this.page
       },
       set (val) {
@@ -81,16 +80,14 @@ export default {
     if (this.sync) {
       const searchs = new Searchs(this.$route.fullPath)
       const active = searchs.get()
-      // for (const key in active.page) {
-      //   if (active.page.hasOwnProperty(key)) {
-      //     const item = active.page[key];
-      //     this[key] = item
-      //     // this.$emit('update:' + key, item)
-      //   }
-      // }
-      this.$emit('update:page', active.page.page)
-      this.$emit('currentPage', active.page.page)
-      // this.page = active.page.page
+      if (active && active.page) {
+        for (const key in active.page) {
+          if (active.page.hasOwnProperty(key)) {
+            const item = active.page[key]
+            this.$emit('update:' + key, item)
+          }
+        }
+      }
     }
   },
   methods: {

+ 33 - 0
src/components/save-form/README.md

@@ -0,0 +1,33 @@
+#### save-form
+
+背景:为保存当页搜索数据,并且不使用keepAlive
+
+###### 使用方法:
+
+``` html
+<saveform :model="form">
+  <el-form-item prop="input">
+    <el-input v-model="form.input">
+  </el-form-item>
+</saveform>
+```
+
+使用时改动较小,仅须将`el-form`修改为`saveform`即可,组件会在验证通过后自动保存当前表单数据,在reset时自动清空数据
+
+数据保存使用的是`sessionStorage`故关闭标签后数据会自动清空
+
+###### 翻页保存:
+``` html
+<pagination
+  :total.sync="rules.total"
+  :page.sync="rules.page"
+  :limit.sync="rules.limit"
+  :page-sizes="rules.page_size"
+  :sync="true"
+  @pagination="getList"
+/>
+```
+请按照以上示例使用翻页,添加了`sync`字段使用此字段才会保存翻页数据
+
+###### 其他:
+请在`@/router/notKeepAliveList`中添加当页路由,保证当前页面不会keepAlive

+ 2 - 1
src/components/save-form/index.vue

@@ -40,8 +40,9 @@ export default {
       })
     },
     resetFields() {
-      this.$refs.form.resetFields()
       this.searchs.update(this.model, undefined, 'form')
+      this.searchs.update({}, undefined, 'page')
+      this.$refs.form.resetFields()
     }
   },
 }

+ 5 - 1
src/views/HumanResources/index.vue

@@ -291,7 +291,7 @@
             </template>
           </el-table-column>
         </el-table>
-        <pagination :total="pageInfo.total"
+        <pagination :total.sync="pageInfo.total"
                     :page.sync="pageInfo.page"
                     :limit.sync="pageInfo.limit"
                     :page-sizes="pageInfo.page_size"
@@ -508,6 +508,10 @@ export default {
       })
     },
     onReSet () {
+      this.pageInfo = {
+        ...this.pageInfo,
+        page: 1
+      }
       this.$refs.searchForm.resetFields()
       this.getList()