useSetDictStore.js 820 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {
  2. defineStore
  3. } from 'pinia';
  4. export const useSetDictStore = defineStore('dict', {
  5. state: () => ({
  6. dicts: []
  7. }),
  8. getters: {
  9. getData: (state) => {
  10. state.dicts
  11. },
  12. },
  13. actions: {
  14. // 仓库列表数据
  15. getList(state) {
  16. return new Promise((resolve, reject) => {
  17. uni.$reqGet('getDictDataAllPage')
  18. .then(({
  19. code,
  20. data,
  21. msg
  22. }) => {
  23. if (code === 0) {
  24. this.dicts = data
  25. // data?.forEach(item => {
  26. // this.dicts.push({
  27. // id: item.id,
  28. // text: item.name,
  29. // value: item.id
  30. // })
  31. // })
  32. resolve(this.dicts)
  33. } else {
  34. reject(msg)
  35. }
  36. })
  37. })
  38. }
  39. },
  40. persist: true, // 设置持久化
  41. // 单独设置存储位置
  42. // persist: {
  43. // storage: window.localStorage,
  44. // },
  45. })