123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import { defineStore } from "pinia";
- import { request } from "../api";
- export const useInfoStore = defineStore({
- id: "info",
- state: () => {
- return {
- isLoadMoreLock: false,
- tabs: ["exhibitions", "activates", "news", "notices"],
- exhibitions: [],
- activates: [],
- news: [],
- notices: [],
- detail: {
- createTime: "",
- creatorId: "",
- creatorName: "",
- display: null,
- id: "",
- name: "",
- publishDate: "",
- richText: "",
- thumb: "",
- type: "",
- video: "",
- },
- total: 0,
- pagination: {
- pageNum: 1,
- pageSize: 20,
- searchKey: "",
- type: "",
- pages: 0,
- current: 0,
- },
- };
- },
- getters: {
- isLoad() {
- return this.total > 0;
- },
- isLast() {
- return (
- this.pagination.current &&
- this.pagination.pages &&
- this.pagination.pages === this.pagination.current
- );
- },
- },
- actions: {
- async getExhibitions(page) {
- this.pagination.type = "exhibition";
- this.pagination.pageNum = page || 1;
- const { data, status } = await request.post("/show/news/pageList", {
- ...this.pagination,
- });
- if (data.code === 0) {
- const { records, total, current, pages } = data.data;
- const lists = this.exhibitions.concat(records);
- this.exhibitions = lists;
- this.total = total;
- this.pagination.current = current;
- this.pagination.pages = pages;
- this.isLoadMoreLock = false;
- } else {
- this.resetPage();
- this.exhibitions = [];
- }
- },
- async getActivates(page) {
- this.pagination.pageNum = page || 1;
- this.pagination.type = "activity";
- const { data, status } = await request.post("/show/news/pageList", {
- ...this.pagination,
- });
- if (data.code === 0) {
- const { records, total, current, pages } = data.data;
- const lists = this.activates.concat(records);
- this.activates = lists;
- this.total = total;
- this.pagination.current = current;
- this.pagination.pages = pages;
- } else {
- this.resetPage();
- this.activates = [];
- }
- },
- async getNews(page) {
- this.pagination.type = "news";
- this.pagination.pageNum = page || 1;
- const { data, status } = await request.post("/show/news/pageList", {
- ...this.pagination,
- });
- if (data.code === 0) {
- const { records, total, current, pages } = data.data;
- const lists = this.news.concat(records);
- this.news = lists;
- this.total = total;
- this.pagination.current = current;
- this.pagination.pages = pages;
- } else {
- this.resetPage();
- this.news = [];
- }
- },
- async getNotices(page) {
- this.pagination.type = "notice";
- this.pagination.pageNum = page || 1;
- const { data, status } = await request.post("/show/news/pageList", {
- ...this.pagination,
- });
- if (data.code === 0) {
- const { records, total, current, pages } = data.data;
- const lists = this.notices.concat(records);
- this.notices = lists;
- this.total = total;
- this.pagination.current = current;
- this.pagination.pages = pages;
- } else {
- this.resetPage();
- this.notices = [];
- }
- },
- async getDetail(id) {
- const { data, status } = await request.get(`/show/news/detail/${id}`);
- if (data.code === 0) {
- this.detail = data.data;
- } else {
- this.detail = null;
- }
- },
- resetPage() {
- this.total = 0;
- this.pagination = {
- pageNum: 1,
- pageSize: 20,
- searchKey: "",
- type: "",
- current: null,
- pages: null,
- };
- },
- loadMore(currentTab) {
- if (!this.isLoadMoreLock && !this.isLast) {
- console.log("loadMore", currentTab);
- this.isLoadMoreLock = true;
- const page =
- this.pagination.pageNum < this.pagination.pages
- ? this.pagination.pageNum + 1
- : this.pagination.pages;
- switch (currentTab) {
- case "exhibitions":
- this.getExhibitions(page);
- break;
- case "activates":
- this.getActivates(page);
- break;
- case "news":
- this.getNews(page);
- break;
- case "notices":
- this.getNotices(page);
- break;
- }
- }
- },
- switchTab(tab) {
- this.resetPage();
- switch (tab) {
- case "exhibitions":
- this.exhibitions = [];
- this.getExhibitions();
- break;
- case "activates":
- this.activates = [];
- this.getActivates();
- break;
- case "news":
- this.news = [];
- this.getNews();
- break;
- case "notices":
- this.notices = [];
- this.getNotices();
- break;
- }
- },
- },
- });
|