You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.2 KiB
122 lines
4.2 KiB
import { defineStore } from 'pinia' |
|
import { listDictDataAll, listDictProblemSourceTree } from '@/api/system/dict' |
|
import { listDictContentTree } from '@/api/system/dictContent' |
|
import { departTree } from '@/api/system/depart' |
|
import { listFlowNode } from '@/api/work/flowNode' |
|
|
|
export interface CatchState { |
|
dict: Record<string, any>, |
|
dictContent: any[], |
|
dictProblemSources: any[], |
|
departs: any[], |
|
flowNodes: any[] |
|
} |
|
// 判定是否已请求缓存 |
|
let departCatchFlag = true; |
|
const dictCatchFlag = {}; |
|
let dictProblemSourcesFlag = true; |
|
const useCatchStore = defineStore({ |
|
id: 'catch', |
|
state: ():CatchState => ({ |
|
dict: {}, |
|
dictContent: [], |
|
dictProblemSources: [], |
|
departs: [], |
|
flowNodes: [] |
|
}), |
|
getters: {}, |
|
actions: { |
|
setDict(key:string, list:any[]) { |
|
this.dict[key] = list |
|
}, |
|
getDicts(keys:string[]) { |
|
keys.forEach(key => { |
|
this.getDict(key); |
|
}) |
|
return this.dict; |
|
}, |
|
getDict(key:string) { |
|
if (!this.dict[key] && !dictCatchFlag[key]) { |
|
dictCatchFlag[key] = true |
|
const refresh = async () => { |
|
const res = await Promise.allSettled<Promise<any>>([listDictDataAll(key)]) |
|
res.forEach((item) => { |
|
if (item.status == 'fulfilled') { |
|
this.setDict(key, item.value) |
|
} |
|
}) |
|
} |
|
refresh() |
|
} |
|
return this.dict[key] |
|
}, |
|
getDictContent() { |
|
if (!this.dictProblemSources.length) { |
|
const refresh = async () => { |
|
const res = await Promise.allSettled<Promise<any>>([listDictContentTree()]) |
|
res.forEach((item) => { |
|
if (item.status == 'fulfilled') { |
|
item.value.forEach(item => { |
|
this.dictContent.push(item) |
|
}) |
|
} |
|
}) |
|
} |
|
refresh() |
|
} |
|
return this.dictContent |
|
}, |
|
getDictProblemSources() { |
|
if (!this.dictProblemSources.length && dictProblemSourcesFlag) { |
|
dictProblemSourcesFlag = false; |
|
const refresh = async () => { |
|
const res = await Promise.allSettled<Promise<any>>([listDictProblemSourceTree()]) |
|
res.forEach((item) => { |
|
if (item.status == 'fulfilled') { |
|
item.value.forEach(item => { |
|
this.dictProblemSources.push(item) |
|
}) |
|
} |
|
}) |
|
} |
|
refresh() |
|
} |
|
return this.dictProblemSources |
|
}, |
|
getDeparts() { |
|
if (!this.departs.length && departCatchFlag) { |
|
departCatchFlag = false |
|
const refresh = async () => { |
|
const res = await Promise.allSettled<Promise<any>>([departTree()]) |
|
res.forEach((item) => { |
|
if (item.status == 'fulfilled') { |
|
item.value.forEach(item => { |
|
this.departs.push(item) |
|
}) |
|
} |
|
}) |
|
} |
|
refresh() |
|
} |
|
return this.departs; |
|
}, |
|
getFlowNodes() { |
|
if (!this.flowNodes.length) { |
|
const refresh = async () => { |
|
const res = await Promise.allSettled<Promise<any>>([listFlowNode()]) |
|
res.forEach((item) => { |
|
if (item.status == 'fulfilled') { |
|
item.value.forEach(item => { |
|
this.flowNodes.push(item) |
|
}) |
|
} |
|
}) |
|
} |
|
refresh() |
|
} |
|
return this.flowNodes; |
|
} |
|
} |
|
}) |
|
|
|
export default useCatchStore |