Sfoglia il codice sorgente

搜索&清除缓存

panhui 4 anni fa
parent
commit
e95e1cb27f

+ 17 - 0
src/mixins/product.js

@@ -124,8 +124,25 @@ export default {
                 str = '...' + str.substr(-8, 8);
             }
             return str;
+        },
+        clearTime() {
+            if (this.timer) {
+                clearTimeout(this.timer);
+                this.timer = null;
+            }
+        },
+        updateTime() {
+            if (this.startTime) {
+                this.getTime(this.info.startTime);
+            }
         }
     },
+    deactivated() {
+        this.clearTime();
+    },
+    activated() {
+        this.updateTime();
+    },
     beforeUnmount() {
         if (this.timer) {
             clearTimeout(this.timer);

+ 24 - 3
src/views/asset/Search.vue

@@ -56,9 +56,9 @@ import asset from '../../mixins/asset';
 import list from '../../mixins/list';
 import search from '../../mixins/search';
 export default {
-    name: 'discover',
+    name: 'assetSearch',
     mixins: [asset, list, search],
-    inject: ['bar'],
+    inject: ['bar', 'setKeeps', 'scrollWrapper', 'changeScroll'],
     components: {
         AssetInfo
     },
@@ -85,7 +85,8 @@ export default {
             ],
             search: '',
             url: '/asset/all',
-            status: ''
+            status: '',
+            scrollTop: 0
         };
     },
     mounted() {
@@ -103,6 +104,26 @@ export default {
                 search: this.search
             };
         }
+    },
+    watch: {
+        isSearch() {
+            this.changeScroll(0);
+        }
+    },
+    activated() {
+        this.$nextTick(() => {
+            this.changeScroll(this.scrollTop);
+        });
+    },
+    beforeRouteLeave(to, from, next) {
+        if (!to.meta.menuPage) {
+            this.scrollTop = this.scrollWrapper.value.scrollTop;
+            this.setKeeps(['productSearch']);
+        } else {
+            this.scrollTop = 0;
+            this.setKeeps([]);
+        }
+        next();
     }
 };
 </script>

+ 24 - 3
src/views/creator/Search.vue

@@ -53,10 +53,10 @@ import CreatorInfo from '../../components/creator/CreatorInfo.vue';
 import list from '../../mixins/list';
 import search from '../../mixins/search';
 export default {
-    name: 'Search',
+    name: 'creatorSearch',
+    inject: ['bar', 'setKeeps', 'scrollWrapper', 'changeScroll'],
     mixins: [list, search],
     components: { CreatorInfo },
-    inject: ['bar'],
     data() {
         return {
             list: [],
@@ -64,9 +64,15 @@ export default {
             search: '',
             stiky: null,
             type: '',
-            url: '/user/all'
+            url: '/user/all',
+            scrollTop: 0
         };
     },
+    watch: {
+        isSearch() {
+            this.changeScroll(0);
+        }
+    },
     methods: {
         beforeData() {
             return {
@@ -74,6 +80,21 @@ export default {
                 search: this.search
             };
         }
+    },
+    activated() {
+        this.$nextTick(() => {
+            this.changeScroll(this.scrollTop);
+        });
+    },
+    beforeRouteLeave(to, from, next) {
+        if (!to.meta.menuPage) {
+            this.scrollTop = this.scrollWrapper.value.scrollTop;
+            this.setKeeps(['productSearch']);
+        } else {
+            this.scrollTop = 0;
+            this.setKeeps([]);
+        }
+        next();
     }
 };
 </script>

+ 24 - 3
src/views/product/Search.vue

@@ -54,9 +54,9 @@ import product from '../../mixins/product';
 import list from '../../mixins/list';
 import search from '../../mixins/search';
 export default {
-    name: 'Search',
+    name: 'productSearch',
     components: { ProductInfo },
-    inject: ['bar'],
+    inject: ['bar', 'setKeeps', 'scrollWrapper', 'changeScroll'],
     mixins: [product, list, search],
     data() {
         return {
@@ -67,9 +67,15 @@ export default {
             type: '',
             source: '',
             minterId: '',
-            url: '/collection/all'
+            url: '/collection/all',
+            scrollTop: 0
         };
     },
+    watch: {
+        isSearch() {
+            this.changeScroll(0);
+        }
+    },
     mounted() {
         if (this.$route.query.type) {
             this.type = this.$route.query.type;
@@ -94,6 +100,21 @@ export default {
                 search: this.search
             };
         }
+    },
+    activated() {
+        this.$nextTick(() => {
+            this.changeScroll(this.scrollTop);
+        });
+    },
+    beforeRouteLeave(to, from, next) {
+        if (!to.meta.menuPage) {
+            this.scrollTop = this.scrollWrapper.value.scrollTop;
+            this.setKeeps(['productSearch']);
+        } else {
+            this.scrollTop = 0;
+            this.setKeeps([]);
+        }
+        next();
     }
 };
 </script>