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)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|