|
@@ -6,14 +6,17 @@ export const useCollectStore = defineStore({
|
|
|
id: "collect",
|
|
|
state: () => {
|
|
|
return {
|
|
|
+ isLoadMoreLock: false,
|
|
|
lists: [],
|
|
|
entity: {},
|
|
|
files: [],
|
|
|
currentLevel: null,
|
|
|
+ total: 0,
|
|
|
pagination: {
|
|
|
dictLevel: "",
|
|
|
endTime: "",
|
|
|
pageNum: 0,
|
|
|
+ pages: null,
|
|
|
pageSize: 20,
|
|
|
searchKey: "",
|
|
|
startTime: "",
|
|
@@ -21,12 +24,22 @@ export const useCollectStore = defineStore({
|
|
|
};
|
|
|
},
|
|
|
getters: {
|
|
|
+ canLoadMore() {
|
|
|
+ return this.isLoad && !this.isLast && !this.isLoadMoreLock;
|
|
|
+ },
|
|
|
+ isLoad() {
|
|
|
+ return this.total > 0;
|
|
|
+ },
|
|
|
+ isLast() {
|
|
|
+ return (
|
|
|
+ this.pagination.current &&
|
|
|
+ this.pagination.pages &&
|
|
|
+ this.pagination.pages === this.pagination.current
|
|
|
+ );
|
|
|
+ },
|
|
|
model() {
|
|
|
const model = this.files.find((item) => item.type === "model");
|
|
|
-
|
|
|
- console.log("model", model);
|
|
|
if (model) {
|
|
|
- // const url = model.id;
|
|
|
return model.id;
|
|
|
} else {
|
|
|
return "";
|
|
@@ -34,7 +47,6 @@ export const useCollectStore = defineStore({
|
|
|
},
|
|
|
video() {
|
|
|
const video = this.files.find((item) => item.type === "video");
|
|
|
- console.log("video", video);
|
|
|
if (video) {
|
|
|
const url = domain + video.filePath;
|
|
|
return url;
|
|
@@ -67,23 +79,49 @@ export const useCollectStore = defineStore({
|
|
|
},
|
|
|
},
|
|
|
actions: {
|
|
|
+ convertLevel(dictLevel) {
|
|
|
+ switch (dictLevel) {
|
|
|
+ case 1:
|
|
|
+ return "一级";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ return "二级";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ return "三级";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return "";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ },
|
|
|
async fetch() {
|
|
|
+ if (this.pagination.pageNum === 1) {
|
|
|
+ this.lists = [];
|
|
|
+ }
|
|
|
const { data, status } = await request.post("/show/goods/pageList", {
|
|
|
...this.pagination,
|
|
|
+ dictLevel: this.convertLevel(this.pagination.dictLevel),
|
|
|
});
|
|
|
if (data.code === 0) {
|
|
|
- const { records, total, current, page } = data.data;
|
|
|
- this.lists = records;
|
|
|
+ const { records, total, current, pages } = data.data;
|
|
|
+ const templists = this.lists.concat(records);
|
|
|
+ this.lists = templists;
|
|
|
this.total = total;
|
|
|
this.pagination.current = current;
|
|
|
- this.pagination.page = page;
|
|
|
+ this.pagination.pages = pages;
|
|
|
+ this.isLoadMoreLock = false;
|
|
|
+ return Promise.resolve(0);
|
|
|
+ } else {
|
|
|
+ this.reset();
|
|
|
+ return Promise.resolve(1);
|
|
|
}
|
|
|
},
|
|
|
async getCollectList(page, level) {
|
|
|
this.pagination.pageNum = page || 1;
|
|
|
this.pagination.dictLevel = level === 0 ? "" : level;
|
|
|
this.currentLevel = level;
|
|
|
- await this.fetch();
|
|
|
+ return await this.fetch();
|
|
|
},
|
|
|
|
|
|
async getDetail(id) {
|
|
@@ -101,11 +139,38 @@ export const useCollectStore = defineStore({
|
|
|
this.pagination.searchKey = searchKey;
|
|
|
this.pagination.pageNum = 1;
|
|
|
this.pagination.dictLevel = level === 0 ? "" : level;
|
|
|
- await this.fetch();
|
|
|
+ return await this.fetch();
|
|
|
},
|
|
|
async clearSearch() {
|
|
|
this.pagination.searchKey = "";
|
|
|
- // await this.fetch();
|
|
|
+ },
|
|
|
+ async reset() {
|
|
|
+ this.lists = [];
|
|
|
+ this.pagination = {
|
|
|
+ dictLevel: "",
|
|
|
+ endTime: "",
|
|
|
+ pageNum: 0,
|
|
|
+ pages: null,
|
|
|
+ pageSize: 20,
|
|
|
+ searchKey: "",
|
|
|
+ startTime: "",
|
|
|
+ current: null,
|
|
|
+ };
|
|
|
+ return Promise.resolve();
|
|
|
+ },
|
|
|
+ async loadMore(level) {
|
|
|
+ if (!this.isLoadMoreLock && !this.isLast) {
|
|
|
+ console.log("loadMore -c-2", this.isLoad);
|
|
|
+ this.isLoadMoreLock = true;
|
|
|
+ this.pagination.dictLevel = level;
|
|
|
+ const page =
|
|
|
+ this.pagination.pageNum < this.pagination.pages
|
|
|
+ ? this.pagination.pageNum + 1
|
|
|
+ : this.pagination.pages;
|
|
|
+ this.pagination.pageNum = page;
|
|
|
+
|
|
|
+ return await this.fetch();
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
});
|