optimize topics ui and logic (65%)

pull/273/head
Michael Li 1 year ago
parent e58e069755
commit 49a624b2c0
No known key found for this signature in database

@ -23,7 +23,7 @@ type topicServant struct {
func newTopicService(db *gorm.DB, ums core.UserManageService) core.TopicService {
return &topicServant{
db: db,
db: db,
ums: ums,
}
}

@ -54,10 +54,11 @@ type GetUserProfileResp struct {
}
type TopicListReq struct {
BaseInfo `form:"-" binding:"-"`
Type TagType `json:"type" form:"type" binding:"required"`
UserId int `json:"uid" form:"uid"`
Num int `json:"num" form:"num" binding:"required"`
BaseInfo `form:"-" binding:"-"`
Type TagType `json:"type" form:"type" binding:"required"`
UserId int `json:"uid" form:"uid"`
Num int `json:"num" form:"num" binding:"required"`
ExtralNum int `json:"extral_num" form:"extral_num"`
}
// TopicListResp 主题返回值

@ -8,7 +8,6 @@ import (
"github.com/alimy/mir/v3"
"github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/model/web"
"github.com/rocboss/paopao-ce/internal/servants/base"
@ -156,9 +155,6 @@ func (s *looseSrv) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Err
err error
)
num := req.Num
if num > conf.AppSetting.MaxPageSize {
num = conf.AppSetting.MaxPageSize
}
switch req.Type {
case web.TagTypeHot:
tags, err = s.Ds.GetHotTags(num, 0)
@ -167,9 +163,13 @@ func (s *looseSrv) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Err
case web.TagTypeFollow:
tags, err = s.Ds.GetFollowTags(num, 0)
case web.TagTypeHotExtral:
extralNum := req.ExtralNum
if extralNum == 0 {
extralNum = num
}
tags, err = s.Ds.GetHotTags(num, 0)
if err == nil {
extralTags, err = s.Ds.GetFollowTags(num, 0)
extralTags, err = s.Ds.GetFollowTags(extralNum, 0)
}
default:
// TODO: return good error

@ -13,7 +13,7 @@
</template>
</n-input>
</div>
<n-card v-if="store.state.userLogined" class="hottopic-wrap" title="关注话题" embedded :bordered="false" size="small">
<n-card v-if="showFollowTopics" class="hottopic-wrap" title="关注话题" embedded :bordered="false" size="small">
<n-spin :show="loading">
<div class="hot-tag-item" v-for="tag in followTags" :key="tag.id">
<router-link
@ -82,7 +82,7 @@
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { ref, onMounted, computed } from 'vue';
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';
import { getTags } from '@/api/post';
@ -105,10 +105,12 @@ const loadHotTags = () => {
getTags({
type: 'hot_extral',
num: 12,
extral_num: 8,
})
.then((res) => {
hotTags.value = res.topics;
followTags.value = res.extral_topics;
followTags.value = res.extral_topics??[];
showFollowTopics.value = true
loading.value = false;
})
.catch((err) => {
@ -130,6 +132,14 @@ const handleSearch = () => {
},
});
};
const showFollowTopics = computed({
get: () => {
return store.state.userLogined && followTags.value.length !==0;
},
set: (newVal) => {
// do nothing
},
});
onMounted(() => {
loadHotTags();
});

@ -167,6 +167,7 @@ declare module NetParams {
interface PostGetTags {
type: "hot" | "new" | "follow" | "hot_extral";
num: number;
extral_num?: number;
}
interface PostGetPostComments {

@ -141,7 +141,7 @@ declare module NetReq {
interface PostGetTags {
topics: Item.TagProps[];
extral_topics: Item.TagProps[];
extral_topics?: Item.TagProps[];
}
interface PostGetPostComments {

Loading…
Cancel
Save