diff --git a/src/api/edit/index.ts b/src/api/edit/index.ts index 2aa75963..963de884 100644 --- a/src/api/edit/index.ts +++ b/src/api/edit/index.ts @@ -1,25 +1,35 @@ -import { fetchPost } from '@/utils/request' +import { fetchPost, fetchGet } from '@/utils/request' import type * as Edit from './types/edit' +// 将对象转为请求参数的函数 +import objectToQueryParams from '@/utils/objectToQueryParams' const editURLs = { create: `/edit/topic`, + hotTags: `/tag/popular`, } +// 创建话题 export async function postEditNewTopicApi( newTopicData: Edit.EditCreateTopicRequestData ): Promise { - try { - // 调用 fetchPost 函数 - const response = await fetchPost( - editURLs.create, - newTopicData - ) + // 调用 fetchPost 函数 + const response = await fetchPost( + editURLs.create, + newTopicData + ) - // 返回创建好的话题 tid - return response - } catch (error) { - // 处理错误 - console.error(error) - throw new Error('Failed to create new topic') - } + // 返回创建好的话题 tid + return response +} + +// 获取 10 个热门 tag +export async function getTopTagsApi( + requestData: Edit.EditGetHotTagsRequestData +): Promise { + const queryParams = objectToQueryParams(requestData) + + const response = await fetchGet( + `${editURLs.hotTags}?${queryParams}` + ) + return response } diff --git a/src/api/edit/types/edit.ts b/src/api/edit/types/edit.ts index cf4ef499..3937e76c 100644 --- a/src/api/edit/types/edit.ts +++ b/src/api/edit/types/edit.ts @@ -28,6 +28,14 @@ export interface EditKUNGalgameTopic { // edited: number } +// 获取热门 tag 的请求数据格式 +export interface EditGetHotTagsRequestData { + limit: number +} + // 创建话题响应数据的格式 export type EditCreateTopicResponseData = KUNGalgameResponseData + +// 热门 tag 的返回数据格式 +export type EditGetHotTagsResponseData = KUNGalgameResponseData diff --git a/src/store/modules/edit.ts b/src/store/modules/edit.ts index 43aa650a..0ef42390 100644 --- a/src/store/modules/edit.ts +++ b/src/store/modules/edit.ts @@ -1,9 +1,11 @@ /* 编辑区的 store */ import { defineStore } from 'pinia' -import { postEditNewTopicApi } from '@/api/index' +import { postEditNewTopicApi, getTopTagsApi } from '@/api/index' import { EditCreateTopicRequestData, EditCreateTopicResponseData, + EditGetHotTagsRequestData, + EditGetHotTagsResponseData, } from '@/api/index' interface Topic { @@ -72,6 +74,19 @@ export const useKUNGalgameEditStore = defineStore({ }) }) }, + // 获取热门 tags + getHotTags(limit: number): Promise { + return new Promise((resolve, reject) => { + const requestData: EditGetHotTagsRequestData = { limit } + getTopTagsApi(requestData) + .then((res) => { + resolve(res) + }) + .catch((error) => { + reject(error) + }) + }) + }, resetTopicData() { this.textCount = 0 this.title = '' diff --git a/src/views/Home/content/aside/components/AsideActive.vue b/src/views/Home/content/aside/components/AsideActive.vue index dad27dc9..66243ce6 100644 --- a/src/views/Home/content/aside/components/AsideActive.vue +++ b/src/views/Home/content/aside/components/AsideActive.vue @@ -38,7 +38,7 @@ const props = defineProps(['isActive']) /* 侧边栏功能区 */ .item-box { width: 100%; - height: 300px; + flex-grow: 1; /* 设置六个功能(模式、排行、背景等)分布的弹性盒 */ display: flex; flex-direction: column; @@ -48,7 +48,6 @@ const props = defineProps(['isActive']) width: 100%; /* 发布话题的按钮相对于功能区盒子的占比 */ flex-grow: 1; - flex-shrink: 0; /* 发布按钮样式 */ button { height: 100%; diff --git a/src/views/Home/content/aside/components/Topic.vue b/src/views/Home/content/aside/components/Topic.vue index 50319560..f387a080 100644 --- a/src/views/Home/content/aside/components/Topic.vue +++ b/src/views/Home/content/aside/components/Topic.vue @@ -74,9 +74,6 @@ onMounted(async () => {