浏览代码

save form edit

wolyshaw 4 年之前
父节点
当前提交
52a27a59ab
共有 3 个文件被更改,包括 39 次插入12 次删除
  1. 6 8
      src/components/save-form/index.vue
  2. 16 0
      src/helpers/index.js
  3. 17 4
      src/layout/components/TagsView.vue

+ 6 - 8
src/components/save-form/index.vue

@@ -20,15 +20,13 @@ export default {
   mounted() {
     const searchs = new Searchs(this.$route.fullPath)
     this.searchs = searchs
-    this.$nextTick(() => {
-      const active = searchs.get()
-      for (const key in active.form) {
-        if (active.form.hasOwnProperty(key)) {
-          const item = active.form[key]
-          this.model[key] = item
-        }
+    const active = searchs.get()
+    for (const key in active.form) {
+      if (active.form.hasOwnProperty(key)) {
+        const item = active.form[key]
+        this.model[key] = item
       }
-    })
+    }
   },
   methods: {
     validate(FC) {

+ 16 - 0
src/helpers/index.js

@@ -43,6 +43,22 @@ export class Searchs {
     return this.searchs
   }
 
+  getSearchs() {
+    return this.searchs
+  }
+
+  removeByKey(key) {
+    delete this.searchs[key]
+    this.save()
+    return this.searchs
+  }
+
+  removeAll() {
+    this.searchs = {}
+    sessionStorage.setItem(this.saveKey, JSON.stringify(this.searchs))
+    return this.searchs
+  }
+
   update(data, key, type) {
     const k = (key || this.key)
     if (type) {

+ 17 - 4
src/layout/components/TagsView.vue

@@ -29,7 +29,7 @@
 <script>
 import ScrollPane from '@/components/ScrollPane'
 import { generateTitle } from '@/utils/i18n'
-import { removeSearchByKey } from '@/helpers'
+import { Searchs } from '@/helpers'
 
 export default {
   name: 'TagsView',
@@ -79,13 +79,25 @@ export default {
     isActive (route) {
       return route.path === this.$route.path
     },
-    addViewTags () {
+    syncTagViewAndSaveForm() {
+      console.log(this.$store.state.tagsView.visitedViews)
+      const keys = this.$store.state.tagsView.visitedViews.map(item => item.fullPath)
+      const searchs = new Searchs()
+      const sks = Object.keys(searchs.getSearchs())
+      for (const item of sks) {
+        if (!keys.includes(item)) {
+          searchs.removeByKey(item)
+        }
+      }
+    },
+    async addViewTags () {
       const route = this.generateRoute()
       if (!route) {
         return false
       }
       // console.log(this.$route)
-      this.$store.dispatch('addVisitedViews', route)
+      await this.$store.dispatch('addVisitedViews', route)
+      this.syncTagViewAndSaveForm()
     },
     moveToCurrentTag () {
       const tags = this.$refs['tag']
@@ -99,7 +111,8 @@ export default {
       })
     },
     closeSelectedTag (view) {
-      removeSearchByKey(view.fullPath)
+      const searchs = new Searchs()
+      searchs.remove(this.$route.fullPath)
       this.$store.dispatch('delVisitedViews', view).then((views) => {
         if (this.isActive(view)) {
           const latestView = views.slice(-1)[0]