BUG: topic master router
This commit is contained in:
parent
fb3fda0d28
commit
17af91b60d
|
@ -8,6 +8,7 @@ export * from './home/types/home'
|
||||||
export * from './kungalgamer/types/kungalgamer'
|
export * from './kungalgamer/types/kungalgamer'
|
||||||
export * from './login/types/login'
|
export * from './login/types/login'
|
||||||
export * from './topic/types/topic'
|
export * from './topic/types/topic'
|
||||||
|
export * from './topic/types/aside'
|
||||||
export * from './update-log/types/updateLog'
|
export * from './update-log/types/updateLog'
|
||||||
|
|
||||||
// 暴露出所有 api
|
// 暴露出所有 api
|
||||||
|
|
|
@ -1,11 +1,54 @@
|
||||||
import { fetchGet } from '@/utils/request'
|
import { fetchGet } from '@/utils/request'
|
||||||
|
// 将对象转为请求参数的函数
|
||||||
|
import objectToQueryParams from '@/utils/objectToQueryParams'
|
||||||
|
import * as Aside from './types/aside'
|
||||||
import * as Topic from './types/topic'
|
import * as Topic from './types/topic'
|
||||||
|
|
||||||
const topicURLs = {
|
const topicURLs = {
|
||||||
|
// 左侧相同标签下的其它话题
|
||||||
|
getRelatedTopicsByTags: `/topic/nav/same`,
|
||||||
|
// 楼主的其它话题
|
||||||
|
getPopularTopicsByUserUid: `/topic/nav/master`,
|
||||||
|
// 获取单个话题
|
||||||
getTopicByTid: `/topic/detail`,
|
getTopicByTid: `/topic/detail`,
|
||||||
|
// 根据话题 id 获取话题回复
|
||||||
getRepliesByPid: `/topic/detail`,
|
getRepliesByPid: `/topic/detail`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 左侧相同标签下的其它话题
|
||||||
|
export async function getRelatedTopicsByTagsApi(
|
||||||
|
request: Aside.TopicAsideOtherTagRequestData
|
||||||
|
): Promise<Aside.TopicAsideResponseData> {
|
||||||
|
try {
|
||||||
|
const queryParams = objectToQueryParams(request)
|
||||||
|
const url = `${topicURLs.getRelatedTopicsByTags}?${queryParams}`
|
||||||
|
|
||||||
|
const response = await fetchGet<Aside.TopicAsideResponseData>(url)
|
||||||
|
|
||||||
|
return response
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
throw new Error('Failed to fetch aside other topic')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 楼主的其它话题
|
||||||
|
export async function getPopularTopicsByUserUidApi(
|
||||||
|
request: Aside.TopicAsideMasterRequestData
|
||||||
|
): Promise<Aside.TopicAsideResponseData> {
|
||||||
|
try {
|
||||||
|
const queryParams = objectToQueryParams(request)
|
||||||
|
const url = `${topicURLs.getPopularTopicsByUserUid}?${queryParams}`
|
||||||
|
|
||||||
|
const response = await fetchGet<Aside.TopicAsideResponseData>(url)
|
||||||
|
|
||||||
|
return response
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
throw new Error('Failed to fetch master other topic')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 获取单个话题
|
// 获取单个话题
|
||||||
export async function getTopicByTidApi(
|
export async function getTopicByTidApi(
|
||||||
tid: number
|
tid: number
|
||||||
|
@ -34,7 +77,7 @@ export async function getRepliesByPidApi(
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
throw new Error('Failed to fetch topic')
|
throw new Error('Failed to fetch replies')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +93,6 @@ export async function getCommentsByReplyRidApi(
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
throw new Error('Failed to fetch topic')
|
throw new Error('Failed to fetch comments')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
src/api/topic/types/aside.ts
Normal file
23
src/api/topic/types/aside.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// 话题详情界面的侧边栏
|
||||||
|
|
||||||
|
export interface TopicAside {
|
||||||
|
title: string
|
||||||
|
tid: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TopicAsideOtherTagRequestData {
|
||||||
|
// 本话题的 tags
|
||||||
|
tags: string[]
|
||||||
|
// 当前话题的 tid,因为相同标签下的其它话题不包括本话题
|
||||||
|
tid: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TopicAsideMasterRequestData {
|
||||||
|
// 楼主 id
|
||||||
|
uid: number
|
||||||
|
// 当前话题的 tid,因为相同标签下的其它话题不包括本话题
|
||||||
|
tid: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aside 响应数据的格式
|
||||||
|
export type TopicAsideResponseData = KUNGalgameResponseData<TopicAside[]>
|
|
@ -1,6 +1,6 @@
|
||||||
import { Router } from 'vue-router'
|
import { Router } from 'vue-router'
|
||||||
import { type RouteRecordRaw } from 'vue-router'
|
import { type RouteRecordRaw } from 'vue-router'
|
||||||
import { useKUNGalgamerStore } from '@/store/modules/kungalgamer'
|
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
|
||||||
import { WHITE_LIST } from '../router'
|
import { WHITE_LIST } from '../router'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { unref } from 'vue'
|
import { unref } from 'vue'
|
||||||
|
@ -10,7 +10,7 @@ import { asyncRoutes } from '../router'
|
||||||
|
|
||||||
export const createPermission = (router: Router) => {
|
export const createPermission = (router: Router) => {
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
const useStore = useKUNGalgamerStore()
|
const useStore = useKUNGalgameUserStore()
|
||||||
const { token } = storeToRefs(useStore)
|
const { token } = storeToRefs(useStore)
|
||||||
const getRoute = asyncRoutes
|
const getRoute = asyncRoutes
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||||
import type { App } from 'vue'
|
import type { App } from 'vue'
|
||||||
|
|
||||||
// 导入用户 store
|
// 导入用户 store
|
||||||
import { useKUNGalgamerStore } from '@/store/modules/kungalgamer'
|
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
|
||||||
|
|
||||||
// 导入网站设置面板 store
|
// 导入网站设置面板 store
|
||||||
import { useKUNGalgameSettingsStore } from '@/store/modules/settings'
|
import { useKUNGalgameSettingsStore } from '@/store/modules/settings'
|
||||||
|
@ -16,7 +16,7 @@ export function setupPinia(app: App<Element>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function storeReset() {
|
export function storeReset() {
|
||||||
const userStore = useKUNGalgamerStore()
|
const userStore = useKUNGalgameUserStore()
|
||||||
const settingsStore = useKUNGalgameSettingsStore()
|
const settingsStore = useKUNGalgameSettingsStore()
|
||||||
|
|
||||||
userStore.$reset()
|
userStore.$reset()
|
||||||
|
|
|
@ -2,26 +2,25 @@
|
||||||
* 用户的信息存储
|
* 用户的信息存储
|
||||||
*/
|
*/
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { type Ref, ref } from 'vue'
|
|
||||||
import { LoginRequestData, LoginResponseData } from '@/api/index'
|
import { LoginRequestData, LoginResponseData } from '@/api/index'
|
||||||
import { postLoginDataApi } from '@/api/index'
|
import { postLoginDataApi } from '@/api/index'
|
||||||
|
|
||||||
interface UserState {
|
interface UserState {
|
||||||
uid: Ref<number>
|
uid: number
|
||||||
avatar: Ref<string>
|
avatar: string
|
||||||
token: Ref<string>
|
token: string
|
||||||
refreshToken: Ref<string>
|
refreshToken: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 这里用了 pinia-plugin-persistedstate,直接存储 token 即可
|
// 这里用了 pinia-plugin-persistedstate,直接存储 token 即可
|
||||||
export const useKUNGalgamerStore = defineStore({
|
export const useKUNGalgameUserStore = defineStore({
|
||||||
id: 'kungalgamer',
|
id: 'kungalgamer',
|
||||||
persist: true,
|
persist: true,
|
||||||
state: (): UserState => ({
|
state: (): UserState => ({
|
||||||
uid: ref<number>(0),
|
uid: 0,
|
||||||
avatar: ref<string>(''),
|
avatar: '',
|
||||||
token: ref<string>(''),
|
token: '',
|
||||||
refreshToken: ref<string>(''),
|
refreshToken: '',
|
||||||
}),
|
}),
|
||||||
getters: {},
|
getters: {},
|
||||||
actions: {
|
actions: {
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
/* 话题详情的 store */
|
/* 话题详情的 store */
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
import { getRepliesByPidApi, getTopicByTidApi } from '@/api/index'
|
|
||||||
import {
|
import {
|
||||||
|
getRelatedTopicsByTagsApi,
|
||||||
|
getPopularTopicsByUserUidApi,
|
||||||
|
getRepliesByPidApi,
|
||||||
|
getTopicByTidApi,
|
||||||
|
} from '@/api/index'
|
||||||
|
import {
|
||||||
|
TopicAsideOtherTagRequestData,
|
||||||
|
TopicAsideMasterRequestData,
|
||||||
|
TopicAsideResponseData,
|
||||||
TopicDetailResponseData,
|
TopicDetailResponseData,
|
||||||
TopicReplyRequestData,
|
TopicReplyRequestData,
|
||||||
TopicReplyResponseData,
|
TopicReplyResponseData,
|
||||||
|
@ -68,6 +76,34 @@ export const useKUNGalgameTopicStore = defineStore({
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
|
// 左侧相同标签下的其它话题
|
||||||
|
getRelatedTopicsByTags(
|
||||||
|
request: TopicAsideOtherTagRequestData
|
||||||
|
): Promise<TopicAsideResponseData> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
getRelatedTopicsByTagsApi(request)
|
||||||
|
.then((res) => {
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// 楼主的其它话题
|
||||||
|
getPopularTopicsByUserUid(
|
||||||
|
request: TopicAsideMasterRequestData
|
||||||
|
): Promise<TopicAsideResponseData> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
getPopularTopicsByUserUidApi(request)
|
||||||
|
.then((res) => {
|
||||||
|
resolve(res)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
// 获取单个话题
|
// 获取单个话题
|
||||||
getTopicByTid(tid: number): Promise<TopicDetailResponseData> {
|
getTopicByTid(tid: number): Promise<TopicDetailResponseData> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
|
@ -8,7 +8,7 @@ const props = defineProps(['data'])
|
||||||
<template>
|
<template>
|
||||||
<div class="topic">
|
<div class="topic">
|
||||||
<UserPart :kungalgamer="props.data.uid" />
|
<UserPart :kungalgamer="props.data.uid" />
|
||||||
<!-- TODO: 进入指定话题的路由 -->
|
<!-- 进入指定话题的路由 -->
|
||||||
<router-link :to="`/topic/${props.data.tid}`">
|
<router-link :to="`/topic/${props.data.tid}`">
|
||||||
<TopicPart :data="props.data" />
|
<TopicPart :data="props.data" />
|
||||||
</router-link>
|
</router-link>
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { toRaw } from 'vue'
|
||||||
// 导入编辑话题的 store
|
// 导入编辑话题的 store
|
||||||
import { useKUNGalgameEditStore } from '@/store/modules/edit'
|
import { useKUNGalgameEditStore } from '@/store/modules/edit'
|
||||||
// 导入用户 store
|
// 导入用户 store
|
||||||
import { useKUNGalgamerStore } from '@/store/modules/kungalgamer'
|
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
// 导入路由
|
// 导入路由
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
@ -60,7 +60,7 @@ const handlePublish = async () => {
|
||||||
time: Date.now(),
|
time: Date.now(),
|
||||||
tags: rawData.tags,
|
tags: rawData.tags,
|
||||||
category: rawData.category,
|
category: rawData.category,
|
||||||
uid: useKUNGalgamerStore().uid,
|
uid: useKUNGalgameUserStore().uid,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查提交数据是否合法
|
// 检查提交数据是否合法
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive } from 'vue'
|
import { ref, reactive } from 'vue'
|
||||||
import { useKUNGalgamerStore } from '@/store/modules/kungalgamer'
|
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
// 使用全局通知
|
// 使用全局通知
|
||||||
import { useKUNGalgameMessageStore } from '@/store/modules/message'
|
import { useKUNGalgameMessageStore } from '@/store/modules/message'
|
||||||
|
@ -24,7 +24,7 @@ const router = useRouter()
|
||||||
|
|
||||||
const info = useKUNGalgameMessageStore()
|
const info = useKUNGalgameMessageStore()
|
||||||
|
|
||||||
const useStore = useKUNGalgamerStore()
|
const useStore = useKUNGalgameUserStore()
|
||||||
|
|
||||||
// 用户登录的表单
|
// 用户登录的表单
|
||||||
const loginForm = reactive({
|
const loginForm = reactive({
|
||||||
|
|
|
@ -2,21 +2,48 @@
|
||||||
这里是楼主的其他话题组件
|
这里是楼主的其他话题组件
|
||||||
-->
|
-->
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
// TODO: 后端接口
|
import { ref } from 'vue'
|
||||||
import { asideTopic } from '@/types/topic/topic'
|
|
||||||
|
import { TopicAside } from '@/api/index'
|
||||||
|
|
||||||
|
// 导入 topic store
|
||||||
|
import { useKUNGalgameTopicStore } from '@/store/modules/topic'
|
||||||
|
// 导入用户 store
|
||||||
|
import { useKUNGalgameUserStore } from '@/store/modules/kungalgamer'
|
||||||
|
import { storeToRefs } from 'pinia'
|
||||||
|
|
||||||
|
import { RouterLink, useRoute } from 'vue-router'
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
const tid = route.params.tid as string
|
||||||
|
|
||||||
|
const { uid } = storeToRefs(useKUNGalgameUserStore())
|
||||||
|
|
||||||
|
const topicData = ref<TopicAside[]>()
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
console.log(tid)
|
||||||
|
|
||||||
|
topicData.value = (
|
||||||
|
await useKUNGalgameTopicStore().getPopularTopicsByUserUid({
|
||||||
|
uid: uid.value,
|
||||||
|
tid: tid,
|
||||||
|
})
|
||||||
|
).data
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!-- 楼主的其它话题 -->
|
<!-- 楼主的其它话题 -->
|
||||||
<div class="master">
|
<div class="master">
|
||||||
<ul>
|
<div class="title">
|
||||||
<li>
|
|
||||||
{{ $tm('topic.aside.master') }}
|
{{ $tm('topic.aside.master') }}
|
||||||
</li>
|
</div>
|
||||||
<li v-for="kun in asideTopic" :key="kun.index">
|
<div class="topic" v-for="(kun, index) in topicData" :key="index">
|
||||||
<router-link :to="kun.router">{{ kun.name }}</router-link>
|
<router-link :to="`/topic/${kun.tid}`">{{ kun.title }}</router-link>
|
||||||
</li>
|
</div>
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -24,8 +51,6 @@ import { asideTopic } from '@/types/topic/topic'
|
||||||
/* 楼主的其它话题 */
|
/* 楼主的其它话题 */
|
||||||
.master {
|
.master {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 1px;
|
|
||||||
flex-grow: 4;
|
|
||||||
|
|
||||||
/* 隐藏溢出的颜色 */
|
/* 隐藏溢出的颜色 */
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
@ -36,18 +61,30 @@ import { asideTopic } from '@/types/topic/topic'
|
||||||
border: 1px solid var(--kungalgame-trans-pink-2);
|
border: 1px solid var(--kungalgame-trans-pink-2);
|
||||||
background-color: var(--kungalgame-trans-pink-0);
|
background-color: var(--kungalgame-trans-pink-0);
|
||||||
|
|
||||||
ul {
|
height: 340px;
|
||||||
height: 100%;
|
|
||||||
/* 整体为一个无序列表,列表为弹性盒 */
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
& > li {
|
|
||||||
height: 1px;
|
.title {
|
||||||
width: 100%;
|
/* 左侧没有 border,没有 hover */
|
||||||
/* 每个项目相对于标题的占比 */
|
border-left: 0;
|
||||||
flex-grow: 3;
|
/* 相对于单个话题标题的比例 */
|
||||||
|
height: 40px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: var(--kungalgame-font-color-2);
|
||||||
|
background-color: var(--kungalgame-trans-pink-1);
|
||||||
|
/* 与单个话题标题的分割线 */
|
||||||
|
border-bottom: 1px solid var(--kungalgame-trans-pink-2);
|
||||||
display: flex;
|
display: flex;
|
||||||
/* 垂直居中 */
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topic {
|
||||||
|
height: 60px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
/* 设置左侧的 border 方便制作 hover */
|
/* 设置左侧的 border 方便制作 hover */
|
||||||
border-left: 4px solid transparent;
|
border-left: 4px solid transparent;
|
||||||
|
@ -59,6 +96,8 @@ import { asideTopic } from '@/types/topic/topic'
|
||||||
transition: 0.2s;
|
transition: 0.2s;
|
||||||
}
|
}
|
||||||
a {
|
a {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
/* 左右两侧的距离 */
|
/* 左右两侧的距离 */
|
||||||
margin: 0 17px;
|
margin: 0 17px;
|
||||||
color: var(--kungalgame-font-color-3);
|
color: var(--kungalgame-font-color-3);
|
||||||
|
@ -70,24 +109,8 @@ import { asideTopic } from '@/types/topic/topic'
|
||||||
-webkit-line-clamp: 2; /* 显示两行文本 */
|
-webkit-line-clamp: 2; /* 显示两行文本 */
|
||||||
/* 标题的字体属性 */
|
/* 标题的字体属性 */
|
||||||
font-size: small;
|
font-size: small;
|
||||||
line-height: 1.5em;
|
display: flex;
|
||||||
box-sizing: border-box;
|
align-items: center;
|
||||||
}
|
|
||||||
&:nth-child(1) {
|
|
||||||
/* 左侧没有 border,没有 hover */
|
|
||||||
border-left: 0;
|
|
||||||
/* 相对于单个话题标题的比例 */
|
|
||||||
flex-grow: 2;
|
|
||||||
line-height: 40px;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: var(--kungalgame-font-color-2);
|
|
||||||
background-color: var(--kungalgame-trans-pink-1);
|
|
||||||
/* 与单个话题标题的分割线 */
|
|
||||||
border-bottom: 1px solid var(--kungalgame-trans-pink-2);
|
|
||||||
/* 水平居中 */
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue