index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import request from '@/utils/request';
  2. import qs from 'qs'
  3. const hhbangBookApi = {
  4. // 首页获取推荐列表
  5. getRecommendListApi(params = {}) {
  6. return request({
  7. url: '/hyb/artArtworks/index/page',
  8. method: 'get',
  9. params: {
  10. pageNo: Math.floor(Math.random() * 10) + 1, // 随机页码
  11. pageSize: 60,
  12. ...params
  13. }
  14. })
  15. },
  16. // 获取文物列表 - 用于收藏页面和详情页上下页切换
  17. getArtifactListApi(params = {}) {
  18. return request({
  19. url: '/hyb/artArtworks/list',
  20. method: 'get',
  21. params: {
  22. agetype: params.era || '', // 年代
  23. category: params.category || '', // 分类
  24. grade: params.level || '', // 级别
  25. searchText: params.keyword || '', // 关键词
  26. texture: params.material || '', // 材质
  27. ...params
  28. },
  29. //序列化
  30. paramsSerializer: {
  31. serialize: params => qs.stringify(params, {indices: false}),
  32. }
  33. })
  34. },
  35. // 获取字典数据列表
  36. getDictionaryListApi() {
  37. return request({
  38. url: '/hyb/artArtworks/dictionary',
  39. method: 'get'
  40. })
  41. },
  42. // 获取文物详情
  43. getArtifactDetailApi(id) {
  44. return request({
  45. url: `/hyb/artArtworks/${id}`,
  46. method: 'get'
  47. })
  48. },
  49. // 获取公告资讯列表
  50. getNewsListApi(params = {}) {
  51. return request({
  52. url: '/hyb/newsPublish/page',
  53. method: 'get',
  54. params: {
  55. searchText: params.searchText || '', // 关键词
  56. pageNo: params.pageNo || 1, // 页码
  57. pageSize: params.pageSize || 20, // 每页数量
  58. ...params
  59. }
  60. })
  61. },
  62. // 提文物征集
  63. submitCollectionClues(data, options = {}) {
  64. const config = {
  65. url: '/hyb/collCollectionClues/add',
  66. method: 'post',
  67. data
  68. }
  69. // 如果传入了自定义headers,添加到配置中
  70. if (options.headers) {
  71. config.customHeaders = options.headers
  72. }
  73. // 如果是FormData但后台不支持multipart/form-data,转换为application/x-www-form-urlencoded
  74. if (data instanceof FormData && options.useUrlEncoded) {
  75. const urlEncodedData = new URLSearchParams()
  76. for (const [key, value] of data.entries()) {
  77. urlEncodedData.append(key, value)
  78. }
  79. config.data = urlEncodedData
  80. config.customHeaders = {
  81. 'Content-Type': 'application/x-www-form-urlencoded',
  82. ...options.headers
  83. }
  84. }
  85. return request(config)
  86. }
  87. }
  88. export default hhbangBookApi;