kun-galgame-vue/src/store/modules/home.ts

62 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-08-23 10:48:20 +00:00
/* 主页的 store */
import { defineStore } from 'pinia'
2023-09-28 13:07:12 +00:00
// api
import { getHomeTopicApi } from '@/api/index'
2023-09-28 13:07:12 +00:00
// 数据接口的类型
import { HomeTopicRequestData, HomeTopicResponseData } from '@/api/index'
2023-08-23 10:48:20 +00:00
2023-09-28 13:07:12 +00:00
// home store 的类型
import { HomeStore } from '../types/home'
2023-08-25 13:01:54 +00:00
2023-08-23 10:48:20 +00:00
export const useKUNGalgameHomeStore = defineStore({
2023-10-07 08:51:14 +00:00
id: 'KUNGalgameHome',
2023-08-23 10:48:20 +00:00
persist: true,
2023-08-25 13:01:54 +00:00
state: (): HomeStore => ({
2023-08-25 09:49:49 +00:00
// 搜索框的 store
2023-08-24 11:51:35 +00:00
/**
* @param {String} keywords -
* @param {Array} category - Galgame, Technique, Others
* @param {Number} page -
* @param {Number} limit -
* @param {String} sortField -
* @param {String} sortOrder - `asc`, `desc`
* @returns {HomeTopicResponseData} topicData
*/
keywords: '',
category: '',
2023-08-23 10:48:20 +00:00
page: 1,
limit: 17,
2023-08-24 11:51:35 +00:00
sortField: 'updated',
sortOrder: 'desc',
2023-09-16 07:24:11 +00:00
isLoading: true,
2023-08-25 09:49:49 +00:00
// 其它的 store
2023-08-25 13:01:54 +00:00
// 是否激活主页的左侧交互面板
2023-08-25 09:49:49 +00:00
isActiveMainPageAside: true,
2023-08-25 13:01:54 +00:00
// 搜索历史存储
searchHistory: [],
2023-08-23 10:48:20 +00:00
}),
getters: {},
actions: {
// 获取首页话题
2023-09-28 13:07:12 +00:00
async getHomeTopic(): Promise<HomeTopicResponseData> {
2023-09-14 08:26:27 +00:00
// 这里的值用于初始化
2023-08-25 09:49:49 +00:00
const requestData: HomeTopicRequestData = {
2023-08-24 11:51:35 +00:00
keywords: this.keywords,
category: this.category,
2023-09-16 07:24:11 +00:00
page: this.page,
limit: this.limit,
2023-09-16 11:00:10 +00:00
sortField: this.sortField,
sortOrder: this.sortOrder,
2023-08-23 10:48:20 +00:00
}
2023-09-28 13:07:12 +00:00
return await getHomeTopicApi(requestData)
2023-08-23 10:48:20 +00:00
},
2023-09-16 07:24:11 +00:00
// 重置页数,是否加载,这样排序才能生效
resetPageStatus() {
this.page = 1
this.isLoading = true
},
2023-08-23 10:48:20 +00:00
},
})