Explorar el Código

翻页信息保存

wolyshaw hace 4 años
padre
commit
cd89193d45

+ 25 - 1
src/components/Pagination/index.vue

@@ -15,6 +15,7 @@
 
 <script>
 import { scrollTo } from '@/utils/scroll-to'
+import { Searchs } from '@/helpers'
 export default {
   name: 'Pagination',
   props: {
@@ -51,6 +52,10 @@ export default {
     hidden: {
       type: Boolean,
       default: false
+    },
+    sync: {
+      type: Boolean,
+      default: false
     }
   },
   computed: {
@@ -59,7 +64,6 @@ export default {
         return this.page
       },
       set (val) {
-        console.log(this)
         this.$emit('update:page', val)
       }
     },
@@ -72,18 +76,38 @@ export default {
       }
     }
   },
+  mounted() {
+    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.$emit('update:' + key, item)
+        }
+      }
+    }
+  },
   methods: {
+    syncStore() {
+      if (this.sync) {
+        const searchs = new Searchs(this.$route.fullPath)
+        searchs.update(this._props, undefined, 'page')
+      }
+    },
     handleSizeChange (val) {
       this.$emit('pagination', { page: this.currentPage, limit: val })
       if (this.autoScroll) {
         scrollTo(0, 800)
       }
+      this.syncStore()
     },
     handleCurrentChange (val) {
       this.$emit('pagination', { page: val, limit: this.pageSize })
       if (this.autoScroll) {
         scrollTo(0, 800)
       }
+      this.syncStore()
     }
   }
 }

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

@@ -8,7 +8,7 @@
   </el-form>
 </template>
 <script>
-import { saveToStorage, getSearchs, Searchs } from '@/helpers'
+import { Searchs } from '@/helpers'
 export default {
   name: 'save-form',
   props: ['model'],

+ 3 - 2
src/views/save-form-test/index.vue

@@ -76,6 +76,7 @@
                 :page.sync="rules.page"
                 :limit.sync="rules.limit"
                 :page-sizes="rules.page_size"
+                :sync="true"
                 @pagination="getList" />
     <el-dialog :visible.sync="testvisible" destroy-on-close>
       <test v-if="testvisible"/>
@@ -102,7 +103,7 @@ export default {
         // 分页规则
         limit: 10, // 限制显示条数
         page: 1, // 当前页
-        total: 0, // 总条数
+        total: 30, // 总条数
         page_size: [10, 20, 40, 50] // 选择限制显示条数
       },
       form: {
@@ -124,7 +125,7 @@ export default {
   },
   methods: {
     getList() {
-      return new Promise.resolve()
+      return Promise.resolve()
     },
     submit() {
       this.$refs.form.validate(valid => {