mirror of
https://github.com/jiangrui1994/CloudSaver.git
synced 2026-01-13 08:38:47 +08:00
feat:版本迭代
This commit is contained in:
50
frontend/src/stores/douban.ts
Normal file
50
frontend/src/stores/douban.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { doubanApi } from "@/api/douban";
|
||||
import { HotListItem } from "@/types/douban";
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
interface StoreType {
|
||||
hotList: HotListItem[];
|
||||
currentParams: CurrentParams;
|
||||
}
|
||||
|
||||
interface CurrentParams {
|
||||
type: string;
|
||||
tag?: string;
|
||||
}
|
||||
|
||||
export const useDoubanStore = defineStore("douban", {
|
||||
state: (): StoreType => ({
|
||||
hotList: [],
|
||||
currentParams: {
|
||||
type: "movie",
|
||||
tag: "热门",
|
||||
},
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async getHotList() {
|
||||
try {
|
||||
const params = {
|
||||
type: this.currentParams.type,
|
||||
tag: this.currentParams.tag || "热门",
|
||||
page_limit: "20",
|
||||
page_start: "0",
|
||||
};
|
||||
const result = await doubanApi.getHotList(params);
|
||||
if (result && result.length > 0) {
|
||||
this.hotList = result;
|
||||
} else {
|
||||
console.log("获取热门列表失败");
|
||||
ElMessage.warning("获取热门列表失败");
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error(error || "获取热门列表失败");
|
||||
}
|
||||
},
|
||||
setCurrentParams(currentParams: CurrentParams) {
|
||||
this.currentParams = currentParams;
|
||||
this.getHotList();
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user