exhibition.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { defineStore } from "pinia";
  2. import { request } from "../api";
  3. export const useExhibitionStore = defineStore({
  4. id: "exhibition",
  5. state: () => {
  6. return {
  7. isLoadMoreLock: false,
  8. lists: [],
  9. detail: {},
  10. total: 0,
  11. pagination: {
  12. type: "",
  13. endTime: "",
  14. pageNum: 0,
  15. pageSize: 20,
  16. searchKey: "",
  17. startTime: "",
  18. },
  19. };
  20. },
  21. getters: {
  22. canLoadMore() {
  23. return this.isLoad && !this.isLast && !this.isLoadMoreLock;
  24. },
  25. isLoad() {
  26. return this.total > 0;
  27. },
  28. isLast() {
  29. return (
  30. this.pagination.current &&
  31. this.pagination.pages &&
  32. this.pagination.pages === this.pagination.current
  33. );
  34. },
  35. },
  36. actions: {
  37. async fetch() {
  38. const { data, status } = await request.post("/show/exhibition/pageList", {
  39. ...this.pagination,
  40. });
  41. if (data.code === 0) {
  42. if (this.pagination.pageNum === 1) {
  43. this.lists = [];
  44. }
  45. const { records, total, current, page } = data.data;
  46. const templists = this.lists.concat(records);
  47. this.lists = templists;
  48. this.total = total;
  49. this.pagination.current = current;
  50. this.pagination.page = page;
  51. return Promise.resolve(0);
  52. } else {
  53. this.lists = [];
  54. return Promise.resolve(1);
  55. }
  56. },
  57. async getExhibitionList(page, type) {
  58. this.pagination.pageNum = page || 1;
  59. this.pagination.type = type === "all" ? "" : type;
  60. return await this.fetch();
  61. },
  62. async getDetail(id) {
  63. const { data, status } = await request.get(
  64. `show/exhibition/detail/${id}`
  65. );
  66. if (data.code === 0) {
  67. this.detail = data.data;
  68. } else {
  69. this.detail = {};
  70. }
  71. },
  72. async search(searchKey, type) {
  73. this.pagination.searchKey = searchKey;
  74. this.pagination.pageNum = 1;
  75. this.pagination.type = type === all ? "" : type;
  76. await this.fetch();
  77. },
  78. async clearSearch() {
  79. this.pagination.searchKey = "";
  80. },
  81. resetPage() {
  82. this.total = 0;
  83. this.pagination = {
  84. pageNum: 1,
  85. pageSize: 20,
  86. searchKey: "",
  87. type: "",
  88. current: null,
  89. pages: null,
  90. };
  91. },
  92. async switchTab() {},
  93. async loadMore(type) {
  94. if (!this.isLoadMoreLock && !this.isLast) {
  95. this.isLoadMoreLock = true;
  96. this.pagination.type = type;
  97. const page =
  98. this.pagination.pageNum < this.pagination.pages
  99. ? this.pagination.pageNum + 1
  100. : this.pagination.pages;
  101. this.pagination.pageNum = page;
  102. return await this.fetch();
  103. }
  104. },
  105. },
  106. });