1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { defineStore } from 'pinia'
 
interface State {
  pageCache: any[]  // 页面缓存数据
}
export const useCommonNonpersistence = defineStore('commonNonpersistence', {
  state: (): State => {
    return {
      pageCache: []
    };
  },
 
  actions: {
    // 添加页面缓存
    addPageCache(data: any) {
      const result = this.pageCache.findIndex((res: any) => {
        return res.code == data.code
      })
      if (result < 0) {
        this.pageCache.push(data)
      } else {
        this.pageCache[result] = data
      }
    },
    //移除页面缓存
    removePageCache(data: any) {
      this.pageCache = this.pageCache.filter((res: any) => {
        return res.code != data.code
      })
    },
    // 清空页面缓存
    clearPageCache() {
      this.pageCache = []
    }
  },
  getters: {
  },
});