useDict.ts 758 B

12345678910111213141516171819202122232425262728
  1. import {useDictStore} from "@/store/modules/dict";
  2. import {storeToRefs} from "pinia";
  3. import {listDetialByCodes} from "@/api/system/dict/";
  4. export const useDictCache = (type: string[]) => {
  5. const dictObj = useDictStore()
  6. const queryDictDetailByCodes = async () => {
  7. let newDictCode = []
  8. type.forEach(key => {
  9. let dictList = dictObj.getDict(key)
  10. if (!dictList || dictList.length <= 0) {
  11. newDictCode.push(key)
  12. }
  13. })
  14. if(newDictCode.length <= 0) return
  15. const res = await listDetialByCodes(newDictCode)
  16. newDictCode.forEach(key => {
  17. dictObj.setDict(key, res.result[key])
  18. })
  19. }
  20. return {
  21. queryDictDetailByCodes
  22. }
  23. }