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

79 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-08-23 10:48:20 +00:00
/* 主页的 store */
import { defineStore } from 'pinia'
import { getHomeTopicApi } from '@/api/home/index'
import {
HomeTopicRequestData,
HomeTopicResponseData,
} from '@/api/home/types/home'
2023-08-25 13:01:54 +00:00
interface HomeStore {
keywords: string
category: string
page: number
limit: number
sortField: string
sortOrder: string
// 其它的 store
// 是否激活主页的左侧交互面板
isActiveMainPageAside: boolean
// 搜索历史存储
searchHistory: string[]
}
2023-08-23 10:48:20 +00:00
export const useKUNGalgameHomeStore = defineStore({
id: 'home',
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-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: {
// 获取首页话题
getHomeTopic(): Promise<HomeTopicResponseData> {
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-08-23 10:48:20 +00:00
page: this.page,
limit: this.limit,
2023-08-24 11:51:35 +00:00
sortField: this.sortField,
sortOrder: this.sortOrder,
2023-08-23 10:48:20 +00:00
}
return new Promise((resolve, reject) => {
getHomeTopicApi(requestData)
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
},
},
})