brand.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { useMyRequest } from '~/composables/useFetchRequest'
  2. enum Api {
  3. BrandList = '/client/brand/list/default',
  4. BrandFavorite = '/client/brand/favorite',
  5. BrandGoodsList = '/client/merchandise/list/default',
  6. DynamicCategoryList = '/client/brand/dynamicCategory',
  7. BrandDetail = '/client/brand/detail',
  8. }
  9. /**
  10. * 首页获取品牌列表
  11. * @param params
  12. * @returns
  13. */
  14. export async function getHomeBrandListApi(params?: any) {
  15. return await useMyRequest().get(Api.BrandList, params)
  16. }
  17. /**
  18. * 品牌详情页获取相似品牌列表
  19. * @param params
  20. * @returns
  21. */
  22. export async function getSimilarBrandListApi(params?: any) {
  23. return await useMyRequest().get(Api.BrandList, params)
  24. }
  25. /**
  26. * 品牌页获取品牌列表
  27. * @param params
  28. * @returns
  29. */
  30. export async function getBrandListApi(params?: any) {
  31. return await useMyRequest().get(Api.BrandList, params)
  32. }
  33. /**
  34. * 是否品牌收藏
  35. * @param params
  36. * @returns
  37. */
  38. export async function setBrandFavoriteApi(params: any) {
  39. return await useMyRequest().post(Api.BrandFavorite, params)
  40. }
  41. /**
  42. * 获取品牌详情
  43. * @param params
  44. * @returns
  45. */
  46. export async function getBrandDetailApi(params?: any) {
  47. return await useMyRequest().get(Api.BrandDetail, params)
  48. }
  49. /**
  50. * 获取品牌详情分类列表
  51. * @param params
  52. * @returns
  53. */
  54. export async function getDynamicCategoryListApi(params?: any) {
  55. const data = await useMyRequest().get(Api.DynamicCategoryList, params)
  56. const result = handleData(data)
  57. return result
  58. }
  59. function handleData(data: any) {
  60. if (data && isArray(data)) {
  61. data.forEach((item) => {
  62. item.label = item.title
  63. if (item.children === null)
  64. delete item.children
  65. if (item.children && item.children.length > 0)
  66. handleData(item.children)
  67. })
  68. }
  69. return data
  70. }
  71. /**
  72. * 获取品牌详情分类下的商品列表
  73. * @param params
  74. * @returns
  75. */
  76. export async function getBrandGoodsListApi(params?: any) {
  77. return await useMyRequest().post(Api.BrandGoodsList, params)
  78. }