wangrong
2026-08-30 4c949c0dc9bcae785c281c9d8125295f09810b15
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { defineStore } from 'pinia'
import { store } from '@/store/index'
 
interface ViewSelectorState {
  enable: boolean
  viewIdList: string[]
}
 
export const viewSelectorStore = defineStore('viewSelectorStore', {
  state: (): ViewSelectorState => {
    return {
      enable: false,
      viewIdList: []
    }
  },
  getters: {
    getEnable(): boolean {
      return this.enable
    },
    getViewIdList(): string[] {
      return this.viewIdList
    }
  },
  actions: {
    setEnable(enable: boolean) {
      this.enable = enable
    },
    remove(id?: string) {
      let len = this.viewIdList.length
      if (!len) {
        return
      }
      if (!id) {
        this.viewIdList = []
        return
      }
      while (len--) {
        if (this.viewIdList[len] === id) {
          this.viewIdList.splice(len, 1)
        }
      }
    },
    add(id: string) {
      if (!this.viewIdList.includes(id)) {
        this.viewIdList.push(id)
      }
    },
    clear() {
      this.enable = false
      this.viewIdList = []
    }
  }
})
 
export const useViewSelectorStoreWithOut = () => {
  return viewSelectorStore(store)
}