Ben Lin
2024-11-12 a42c6f16bbb177dfcc754d53d925afddead38eba
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * @Description: 页面查询Store
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-18 15:09:47
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-10-23 22:52:45
 */
import { defineStore } from 'pinia';
import { store } from '@/store';
import { isNullOrEmpty } from '/@/utils/is';
import { useUserStore } from './user';
 
interface QueryState {
  curSearchInfo: any[];
  curPageName: string;
  curCPInfo: any[];
}
 
export const useQueryStore = defineStore({
  id: 'app-query',
  state: (): QueryState => ({
    curSearchInfo: [],
    curPageName: '',
    curCPInfo: [],
  }),
  getters: {
    getCurSearchInfo(state): any[] {
      return state.curSearchInfo;
    },
    getCurPageName(state): string {
      return state.curPageName;
    },
    getCurCPInfo(state): any[] {
      return state.curCPInfo;
    },
  },
  actions: {
    setCurSearchInfo(val: any) {
      if (!isNullOrEmpty(val)) {
        if (!this.curSearchInfo.some((q) => q.name == val.name)) {
          this.curSearchInfo.push(val);
        } else {
          this.curSearchInfo.map((item) => {
            if (item.name == val.name) {
              item.searchInfo = val.searchInfo;
              item.ByOrg = isNullOrEmpty(val.ByOrg) ? false : val.ByOrg;
              item.searchInfo.option = !item.ByOrg
                ? ''
                : {
                    //根据据点查询,必需带这个参数
                    UserId: useUserStore().getUserInfo.userId,
                    ByOrg: true,
                    CurOrg: useUserStore().getUserInfo.orgCode,
                  };
            }
          });
        }
      }
    },
    setCurCPInfo(val: any) {
      if (!isNullOrEmpty(val)) {
        if (!this.curCPInfo.some((q) => q.name == val.name)) {
          this.curCPInfo.push(val);
        } else {
          this.curCPInfo.map((item) => {
            if (item.name == val.name) {
              item.treeInfo = val.treeInfo;
              item.navInfo = val.navInfo;
              item.config = val.config;
            }
          });
        }
      }
    },
    setCurPageName(val: string) {
      this.curPageName = val;
    },
    resetState() {
      this.curSearchInfo = [];
      this.curPageName = '';
      this.curCPInfo = [];
    },
    /**
     * @description: 查询提交
     * @param {string} tid
     * @return {*}
     */
    async submitFunc(name, f, ByOrg: boolean) {
      this.setCurSearchInfo({ name: name, searchInfo: f.getFieldsValue(), ByOrg: ByOrg });
    },
    async resetFunc(name, f, ByOrg: boolean) {
      this.setCurSearchInfo({ name: name, searchInfo: f.getFieldsValue(), ByOrg: ByOrg });
    },
  },
});
 
// Need to be used outside the setup
export function useQueryWithOut() {
  return useQueryStore(store);
}