optimize topics ui and logic (65%)

pull/273/head
Michael Li 2 years 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 { func newTopicService(db *gorm.DB, ums core.UserManageService) core.TopicService {
return &topicServant{ return &topicServant{
db: db, db: db,
ums: ums, ums: ums,
} }
} }

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

@ -8,7 +8,6 @@ import (
"github.com/alimy/mir/v3" "github.com/alimy/mir/v3"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
api "github.com/rocboss/paopao-ce/auto/api/v1" 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/core"
"github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/model/web"
"github.com/rocboss/paopao-ce/internal/servants/base" "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 err error
) )
num := req.Num num := req.Num
if num > conf.AppSetting.MaxPageSize {
num = conf.AppSetting.MaxPageSize
}
switch req.Type { switch req.Type {
case web.TagTypeHot: case web.TagTypeHot:
tags, err = s.Ds.GetHotTags(num, 0) 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: case web.TagTypeFollow:
tags, err = s.Ds.GetFollowTags(num, 0) tags, err = s.Ds.GetFollowTags(num, 0)
case web.TagTypeHotExtral: case web.TagTypeHotExtral:
extralNum := req.ExtralNum
if extralNum == 0 {
extralNum = num
}
tags, err = s.Ds.GetHotTags(num, 0) tags, err = s.Ds.GetHotTags(num, 0)
if err == nil { if err == nil {
extralTags, err = s.Ds.GetFollowTags(num, 0) extralTags, err = s.Ds.GetFollowTags(extralNum, 0)
} }
default: default:
// TODO: return good error // TODO: return good error

@ -13,7 +13,7 @@
</template> </template>
</n-input> </n-input>
</div> </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"> <n-spin :show="loading">
<div class="hot-tag-item" v-for="tag in followTags" :key="tag.id"> <div class="hot-tag-item" v-for="tag in followTags" :key="tag.id">
<router-link <router-link
@ -82,7 +82,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue'; import { ref, onMounted, computed } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import { getTags } from '@/api/post'; import { getTags } from '@/api/post';
@ -105,10 +105,12 @@ const loadHotTags = () => {
getTags({ getTags({
type: 'hot_extral', type: 'hot_extral',
num: 12, num: 12,
extral_num: 8,
}) })
.then((res) => { .then((res) => {
hotTags.value = res.topics; hotTags.value = res.topics;
followTags.value = res.extral_topics; followTags.value = res.extral_topics??[];
showFollowTopics.value = true
loading.value = false; loading.value = false;
}) })
.catch((err) => { .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(() => { onMounted(() => {
loadHotTags(); loadHotTags();
}); });

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

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

Loading…
Cancel
Save