2023-08-23 10:48:20 +00:00
|
|
|
|
/* 主页的 store */
|
|
|
|
|
import { defineStore } from 'pinia'
|
2023-09-28 13:07:12 +00:00
|
|
|
|
// api
|
2023-08-27 09:57:59 +00:00
|
|
|
|
import { getHomeTopicApi } from '@/api/index'
|
2023-09-28 13:07:12 +00:00
|
|
|
|
// 数据接口的类型
|
2023-08-27 09:57:59 +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
|
|
|
|
},
|
|
|
|
|
})
|