home.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import store, { AppDispatch } from ".."
  2. import http from "@/utils/http"
  3. import { HomeSortType } from "@/types"
  4. // 获取分类
  5. export const getSortAction = () => {
  6. return async (dispatch: AppDispatch) => {
  7. const res = await http.post('/api/show/getTree', { type: 'texture' })
  8. let data = res.data.map((v: HomeSortType) => ({
  9. ...v,
  10. value: v.id,
  11. label: v.name
  12. }))
  13. data.unshift({ value: -1, label: '全部分类' })
  14. dispatch({ type: 'home/setSort', payload: data })
  15. }
  16. }
  17. // 获取年代
  18. export const getAgeAction = () => {
  19. return async (dispatch: AppDispatch) => {
  20. const res = await http.post('/api/show/getTree', { type: 'age' })
  21. let data = res.data.map((v: HomeSortType) => ({
  22. ...v,
  23. value: v.id,
  24. label: v.name
  25. }))
  26. data.unshift({ value: -1, label: '全部年代' })
  27. dispatch({ type: 'home/setAge', payload: data })
  28. }
  29. }
  30. // 获取列表数据
  31. export const getListAction = (data: any, flag?: boolean) => {
  32. return async (dispatch: AppDispatch) => {
  33. const res = await http.post('/api/show/goods/list', data)
  34. let list
  35. if (flag) list = [...store.getState().homeStore.modelInfo.list, ...res.data.records]
  36. else list = res.data.records
  37. const total = res.data.total
  38. dispatch({ type: 'home/setList', payload: { list, total } })
  39. }
  40. }
  41. // 扫码进页面获取的单个文物详情
  42. export const getModelInfo = (id: string) => {
  43. return async (dispatch: AppDispatch) => {
  44. const res = await http.get(`/api/show/goods/detail/${id}`)
  45. dispatch({ type: 'home/Model', payload: res.data })
  46. }
  47. }