info.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { defineStore } from "pinia";
  2. import { request } from "../api";
  3. export const useInfoStore = defineStore({
  4. id: "info",
  5. state: () => {
  6. return {
  7. isLoadMoreLock: false,
  8. tabs: ["exhibitions", "activates", "news", "notices"],
  9. exhibitions: [],
  10. activates: [],
  11. news: [],
  12. notices: [],
  13. detail: {
  14. createTime: "",
  15. creatorId: "",
  16. creatorName: "",
  17. display: null,
  18. id: "",
  19. name: "",
  20. publishDate: "",
  21. richText: "",
  22. thumb: "",
  23. type: "",
  24. video: "",
  25. },
  26. total: 0,
  27. pagination: {
  28. pageNum: 1,
  29. pageSize: 20,
  30. searchKey: "",
  31. type: "",
  32. pages: 0,
  33. current: 0,
  34. },
  35. };
  36. },
  37. getters: {
  38. isLoad() {
  39. return this.total > 0;
  40. },
  41. isLast() {
  42. return (
  43. this.pagination.current &&
  44. this.pagination.pages &&
  45. this.pagination.pages === this.pagination.current
  46. );
  47. },
  48. },
  49. actions: {
  50. async getExhibitions(page) {
  51. this.pagination.type = "exhibition";
  52. this.pagination.pageNum = page || 1;
  53. const { data, status } = await request.post("/show/news/pageList", {
  54. ...this.pagination,
  55. });
  56. if (data.code === 0) {
  57. const { records, total, current, pages } = data.data;
  58. const lists = this.exhibitions.concat(records);
  59. this.exhibitions = lists;
  60. this.total = total;
  61. this.pagination.current = current;
  62. this.pagination.pages = pages;
  63. this.isLoadMoreLock = false;
  64. } else {
  65. this.resetPage();
  66. this.exhibitions = [];
  67. }
  68. },
  69. async getActivates(page) {
  70. this.pagination.pageNum = page || 1;
  71. this.pagination.type = "activity";
  72. const { data, status } = await request.post("/show/news/pageList", {
  73. ...this.pagination,
  74. });
  75. if (data.code === 0) {
  76. const { records, total, current, pages } = data.data;
  77. const lists = this.activates.concat(records);
  78. this.activates = lists;
  79. this.total = total;
  80. this.pagination.current = current;
  81. this.pagination.pages = pages;
  82. } else {
  83. this.resetPage();
  84. this.activates = [];
  85. }
  86. },
  87. async getNews(page) {
  88. this.pagination.type = "news";
  89. this.pagination.pageNum = page || 1;
  90. const { data, status } = await request.post("/show/news/pageList", {
  91. ...this.pagination,
  92. });
  93. if (data.code === 0) {
  94. const { records, total, current, pages } = data.data;
  95. const lists = this.news.concat(records);
  96. this.news = lists;
  97. this.total = total;
  98. this.pagination.current = current;
  99. this.pagination.pages = pages;
  100. } else {
  101. this.resetPage();
  102. this.news = [];
  103. }
  104. },
  105. async getNotices(page) {
  106. this.pagination.type = "notice";
  107. this.pagination.pageNum = page || 1;
  108. const { data, status } = await request.post("/show/news/pageList", {
  109. ...this.pagination,
  110. });
  111. if (data.code === 0) {
  112. const { records, total, current, pages } = data.data;
  113. const lists = this.notices.concat(records);
  114. this.notices = lists;
  115. this.total = total;
  116. this.pagination.current = current;
  117. this.pagination.pages = pages;
  118. } else {
  119. this.resetPage();
  120. this.notices = [];
  121. }
  122. },
  123. async getDetail(id) {
  124. const { data, status } = await request.get(`/show/news/detail/${id}`);
  125. if (data.code === 0) {
  126. this.detail = data.data;
  127. } else {
  128. this.detail = null;
  129. }
  130. },
  131. resetPage() {
  132. this.total = 0;
  133. this.pagination = {
  134. pageNum: 1,
  135. pageSize: 20,
  136. searchKey: "",
  137. type: "",
  138. current: null,
  139. pages: null,
  140. };
  141. },
  142. loadMore(currentTab) {
  143. if (!this.isLoadMoreLock && !this.isLast) {
  144. console.log("loadMore", currentTab);
  145. this.isLoadMoreLock = true;
  146. const page =
  147. this.pagination.pageNum < this.pagination.pages
  148. ? this.pagination.pageNum + 1
  149. : this.pagination.pages;
  150. switch (currentTab) {
  151. case "exhibitions":
  152. this.getExhibitions(page);
  153. break;
  154. case "activates":
  155. this.getActivates(page);
  156. break;
  157. case "news":
  158. this.getNews(page);
  159. break;
  160. case "notices":
  161. this.getNotices(page);
  162. break;
  163. }
  164. }
  165. },
  166. switchTab(tab) {
  167. this.resetPage();
  168. switch (tab) {
  169. case "exhibitions":
  170. this.exhibitions = [];
  171. this.getExhibitions();
  172. break;
  173. case "activates":
  174. this.activates = [];
  175. this.getActivates();
  176. break;
  177. case "news":
  178. this.news = [];
  179. this.getNews();
  180. break;
  181. case "notices":
  182. this.notices = [];
  183. this.getNotices();
  184. break;
  185. }
  186. },
  187. },
  188. });