From e58e06975598f25ff78f3a4f74fff6f8d07c965f Mon Sep 17 00:00:00 2001 From: Michael Li Date: Wed, 19 Apr 2023 22:45:16 +0800 Subject: [PATCH 1/6] optimize topic ui and logic (60%) --- auto/api/v1/loose.go | 33 ++++ auto/api/v1/pub.go | 33 ---- internal/core/topics.go | 3 + internal/dao/jinzhu/dbr/tag.go | 22 +-- internal/dao/jinzhu/jinzhu.go | 3 +- internal/dao/jinzhu/topics.go | 60 ++++++- internal/model/web/loose.go | 23 +++ internal/model/web/pub.go | 18 -- internal/servants/web/loose.go | 35 ++++ internal/servants/web/pub.go | 45 ----- mirc/web/v1/loose.go | 3 + mirc/web/v1/pub.go | 3 - web/src/components/rightbar.vue | 42 ++++- web/src/components/sidebar.vue | 2 +- web/src/components/tag-item.vue | 133 +++++++++++++++ web/src/store/index.ts | 5 + web/src/types/Item.d.ts | 2 + web/src/types/NetParams.d.ts | 2 +- web/src/types/NetReq.d.ts | 281 +++++++++++++++----------------- web/src/views/Topic.vue | 46 ++---- 20 files changed, 487 insertions(+), 307 deletions(-) create mode 100644 web/src/components/tag-item.vue diff --git a/auto/api/v1/loose.go b/auto/api/v1/loose.go index 832f6fc3..8e45824a 100644 --- a/auto/api/v1/loose.go +++ b/auto/api/v1/loose.go @@ -16,6 +16,7 @@ type Loose interface { // Chain provide handlers chain for gin Chain() gin.HandlersChain + TopicList(*web.TopicListReq) (*web.TopicListResp, mir.Error) GetUserProfile(*web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) GetUserTweets(*web.GetUserTweetsReq) (*web.GetUserTweetsResp, mir.Error) Timeline(*web.TimelineReq) (*web.TimelineResp, mir.Error) @@ -24,6 +25,7 @@ type Loose interface { } type LooseBinding interface { + BindTopicList(*gin.Context) (*web.TopicListReq, mir.Error) BindGetUserProfile(*gin.Context) (*web.GetUserProfileReq, mir.Error) BindGetUserTweets(*gin.Context) (*web.GetUserTweetsReq, mir.Error) BindTimeline(*gin.Context) (*web.TimelineReq, mir.Error) @@ -32,6 +34,7 @@ type LooseBinding interface { } type LooseRender interface { + RenderTopicList(*gin.Context, *web.TopicListResp, mir.Error) RenderGetUserProfile(*gin.Context, *web.GetUserProfileResp, mir.Error) RenderGetUserTweets(*gin.Context, *web.GetUserTweetsResp, mir.Error) RenderTimeline(*gin.Context, *web.TimelineResp, mir.Error) @@ -47,6 +50,22 @@ func RegisterLooseServant(e *gin.Engine, s Loose, b LooseBinding, r LooseRender) router.Use(middlewares...) // register routes info to router + router.Handle("GET", "/tags", func(c *gin.Context) { + select { + case <-c.Request.Context().Done(): + return + default: + } + + req, err := b.BindTopicList(c) + if err != nil { + r.RenderTopicList(c, nil, err) + return + } + resp, err := s.TopicList(req) + r.RenderTopicList(c, resp, err) + }) + router.Handle("GET", "/user/profile", func(c *gin.Context) { select { case <-c.Request.Context().Done(): @@ -105,6 +124,10 @@ func (UnimplementedLooseServant) Chain() gin.HandlersChain { return nil } +func (UnimplementedLooseServant) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error) { + return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) +} + func (UnimplementedLooseServant) GetUserProfile(req *web.GetUserProfileReq) (*web.GetUserProfileResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } @@ -124,6 +147,10 @@ type UnimplementedLooseRender struct { RenderAny func(*gin.Context, any, mir.Error) } +func (r *UnimplementedLooseRender) RenderTopicList(c *gin.Context, data *web.TopicListResp, err mir.Error) { + r.RenderAny(c, data, err) +} + func (r *UnimplementedLooseRender) RenderGetUserProfile(c *gin.Context, data *web.GetUserProfileResp, err mir.Error) { r.RenderAny(c, data, err) } @@ -143,6 +170,12 @@ type UnimplementedLooseBinding struct { BindAny func(*gin.Context, any) mir.Error } +func (b *UnimplementedLooseBinding) BindTopicList(c *gin.Context) (*web.TopicListReq, mir.Error) { + obj := new(web.TopicListReq) + err := b.BindAny(c, obj) + return obj, err +} + func (b *UnimplementedLooseBinding) BindGetUserProfile(c *gin.Context) (*web.GetUserProfileReq, mir.Error) { obj := new(web.GetUserProfileReq) err := b.BindAny(c, obj) diff --git a/auto/api/v1/pub.go b/auto/api/v1/pub.go index 3417cacd..ab8a4832 100644 --- a/auto/api/v1/pub.go +++ b/auto/api/v1/pub.go @@ -13,7 +13,6 @@ import ( ) type Pub interface { - TopicList(*web.TopicListReq) (*web.TopicListResp, mir.Error) TweetComments(*web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error) TweetDetail(*web.TweetDetailReq) (*web.TweetDetailResp, mir.Error) SendCaptcha(*web.SendCaptchaReq) mir.Error @@ -26,7 +25,6 @@ type Pub interface { } type PubBinding interface { - BindTopicList(*gin.Context) (*web.TopicListReq, mir.Error) BindTweetComments(*gin.Context) (*web.TweetCommentsReq, mir.Error) BindTweetDetail(*gin.Context) (*web.TweetDetailReq, mir.Error) BindSendCaptcha(*gin.Context) (*web.SendCaptchaReq, mir.Error) @@ -37,7 +35,6 @@ type PubBinding interface { } type PubRender interface { - RenderTopicList(*gin.Context, *web.TopicListResp, mir.Error) RenderTweetComments(*gin.Context, *web.TweetCommentsResp, mir.Error) RenderTweetDetail(*gin.Context, *web.TweetDetailResp, mir.Error) RenderSendCaptcha(*gin.Context, mir.Error) @@ -54,22 +51,6 @@ func RegisterPubServant(e *gin.Engine, s Pub, b PubBinding, r PubRender) { router := e.Group("v1") // register routes info to router - router.Handle("GET", "/tags", func(c *gin.Context) { - select { - case <-c.Request.Context().Done(): - return - default: - } - - req, err := b.BindTopicList(c) - if err != nil { - r.RenderTopicList(c, nil, err) - return - } - resp, err := s.TopicList(req) - r.RenderTopicList(c, resp, err) - }) - router.Handle("GET", "/post/comments", func(c *gin.Context) { select { case <-c.Request.Context().Done(): @@ -177,10 +158,6 @@ func RegisterPubServant(e *gin.Engine, s Pub, b PubBinding, r PubRender) { type UnimplementedPubServant struct { } -func (UnimplementedPubServant) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error) { - return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) -} - func (UnimplementedPubServant) TweetComments(req *web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error) { return nil, mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented)) } @@ -216,10 +193,6 @@ type UnimplementedPubRender struct { RenderAny func(*gin.Context, any, mir.Error) } -func (r *UnimplementedPubRender) RenderTopicList(c *gin.Context, data *web.TopicListResp, err mir.Error) { - r.RenderAny(c, data, err) -} - func (r *UnimplementedPubRender) RenderTweetComments(c *gin.Context, data *web.TweetCommentsResp, err mir.Error) { r.RenderAny(c, data, err) } @@ -255,12 +228,6 @@ type UnimplementedPubBinding struct { BindAny func(*gin.Context, any) mir.Error } -func (b *UnimplementedPubBinding) BindTopicList(c *gin.Context) (*web.TopicListReq, mir.Error) { - obj := new(web.TopicListReq) - err := b.BindAny(c, obj) - return obj, err -} - func (b *UnimplementedPubBinding) BindTweetComments(c *gin.Context) (*web.TweetCommentsReq, mir.Error) { obj := new(web.TweetCommentsReq) err := b.BindAny(c, obj) diff --git a/internal/core/topics.go b/internal/core/topics.go index 138cc151..f0f0e8fb 100644 --- a/internal/core/topics.go +++ b/internal/core/topics.go @@ -18,5 +18,8 @@ type TopicService interface { CreateTag(tag *Tag) (*Tag, error) DeleteTag(tag *Tag) error GetTags(conditions *ConditionsT, offset, limit int) ([]*Tag, error) + GetHotTags(limit int, offset int) ([]*TagFormated, error) + GetNewestTags(limit int, offset int) ([]*TagFormated, error) + GetFollowTags(limit int, offset int) ([]*TagFormated, error) GetTagsByKeyword(keyword string) ([]*Tag, error) } diff --git a/internal/dao/jinzhu/dbr/tag.go b/internal/dao/jinzhu/dbr/tag.go index 8570f574..8566d812 100644 --- a/internal/dao/jinzhu/dbr/tag.go +++ b/internal/dao/jinzhu/dbr/tag.go @@ -17,11 +17,12 @@ type Tag struct { QuoteNum int64 `json:"quote_num"` } type TagFormated struct { - ID int64 `json:"id"` - UserID int64 `json:"user_id"` - User *UserFormated `json:"user"` - Tag string `json:"tag"` - QuoteNum int64 `json:"quote_num"` + ID int64 `json:"id"` + UserID int64 `json:"user_id"` + User *UserFormated `json:"user"` + Tag string `json:"tag"` + QuoteNum int64 `json:"quote_num"` + IsFollowing int8 `json:"is_following"` } func (t *Tag) Format() *TagFormated { @@ -30,11 +31,12 @@ func (t *Tag) Format() *TagFormated { } return &TagFormated{ - ID: t.ID, - UserID: t.UserID, - User: &UserFormated{}, - Tag: t.Tag, - QuoteNum: t.QuoteNum, + ID: t.ID, + UserID: t.UserID, + User: &UserFormated{}, + Tag: t.Tag, + QuoteNum: t.QuoteNum, + IsFollowing: 0, } } diff --git a/internal/dao/jinzhu/jinzhu.go b/internal/dao/jinzhu/jinzhu.go index 790ee6ad..3ccebdb9 100644 --- a/internal/dao/jinzhu/jinzhu.go +++ b/internal/dao/jinzhu/jinzhu.go @@ -49,6 +49,7 @@ func NewDataService() (core.DataService, core.VersionInfo) { pvs := security.NewPhoneVerifyService() ams := NewAuthorizationManageService() ths := newTweetHelpService(db) + ums := newUserManageService(db) // initialize core.IndexPostsService if cfg.If("Friendship") { @@ -86,7 +87,7 @@ func NewDataService() (core.DataService, core.VersionInfo) { IndexPostsService: cis, WalletService: newWalletService(db), MessageService: newMessageService(db), - TopicService: newTopicService(db), + TopicService: newTopicService(db, ums), TweetService: newTweetService(db), TweetManageService: newTweetManageService(db, cis), TweetHelpService: newTweetHelpService(db), diff --git a/internal/dao/jinzhu/topics.go b/internal/dao/jinzhu/topics.go index d5ce70a9..405afd96 100644 --- a/internal/dao/jinzhu/topics.go +++ b/internal/dao/jinzhu/topics.go @@ -17,12 +17,14 @@ var ( ) type topicServant struct { - db *gorm.DB + db *gorm.DB + ums core.UserManageService } -func newTopicService(db *gorm.DB) core.TopicService { +func newTopicService(db *gorm.DB, ums core.UserManageService) core.TopicService { return &topicServant{ db: db, + ums: ums, } } @@ -38,6 +40,60 @@ func (s *topicServant) GetTags(conditions *core.ConditionsT, offset, limit int) return (&dbr.Tag{}).List(s.db, conditions, offset, limit) } +func (s *topicServant) GetHotTags(limit int, offset int) ([]*core.TagFormated, error) { + tags, err := (&dbr.Tag{}).List(s.db, &core.ConditionsT{ + "ORDER": "quote_num DESC", + }, offset, limit) + if err != nil { + return nil, err + } + return s.tagsFormat(tags) +} + +func (s *topicServant) GetNewestTags(limit int, offset int) ([]*core.TagFormated, error) { + tags, err := (&dbr.Tag{}).List(s.db, &core.ConditionsT{ + "ORDER": "id DESC", + }, offset, limit) + if err != nil { + return nil, err + } + return s.tagsFormat(tags) +} + +func (s *topicServant) GetFollowTags(limit int, offset int) ([]*core.TagFormated, error) { + // TODO:具体逻辑稍后实现,先用热门标签替换 + tags, err := (&dbr.Tag{}).List(s.db, &core.ConditionsT{ + "ORDER": "quote_num DESC", + }, offset, limit) + if err != nil { + return nil, err + } + return s.tagsFormat(tags) +} + +func (s *topicServant) tagsFormat(tags []*core.Tag) ([]*core.TagFormated, error) { + // 获取创建者User IDs + userIds := []int64{} + for _, tag := range tags { + userIds = append(userIds, tag.UserID) + } + users, err := s.ums.GetUsersByIDs(userIds) + if err != nil { + return nil, err + } + tagsFormated := []*core.TagFormated{} + for _, tag := range tags { + tagFormated := tag.Format() + for _, user := range users { + if user.ID == tagFormated.UserID { + tagFormated.User = user.Format() + } + } + tagsFormated = append(tagsFormated, tagFormated) + } + return tagsFormated, nil +} + func (s *topicServant) GetTagsByKeyword(keyword string) ([]*core.Tag, error) { tag := &dbr.Tag{} diff --git a/internal/model/web/loose.go b/internal/model/web/loose.go index e505e35b..aa6c08a3 100644 --- a/internal/model/web/loose.go +++ b/internal/model/web/loose.go @@ -9,6 +9,15 @@ import ( "github.com/rocboss/paopao-ce/internal/servants/base" ) +const ( + TagTypeHot TagType = "hot" + TagTypeNew TagType = "new" + TagTypeFollow TagType = "follow" + TagTypeHotExtral TagType = "hot_extral" +) + +type TagType string + type TimelineReq struct { BaseInfo `form:"-" binding:"-"` Query string `form:"query"` @@ -44,6 +53,20 @@ type GetUserProfileResp struct { IsFriend bool `json:"is_friend"` } +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"` +} + +// TopicListResp 主题返回值 +// TODO: 优化内容定义 +type TopicListResp struct { + Topics []*core.TagFormated `json:"topics"` + ExtralTopics []*core.TagFormated `json:"extral_topics,omitempty"` +} + func (r *GetUserTweetsReq) SetPageInfo(page int, pageSize int) { r.Page, r.PageSize = page, pageSize } diff --git a/internal/model/web/pub.go b/internal/model/web/pub.go index a5634549..e8550984 100644 --- a/internal/model/web/pub.go +++ b/internal/model/web/pub.go @@ -10,13 +10,6 @@ import ( "github.com/rocboss/paopao-ce/pkg/version" ) -const ( - TagTypeHot TagType = "hot" - TagTypeNew TagType = "new" -) - -type TagType string - type TweetDetailReq struct { TweetId int64 `form:"id"` } @@ -32,17 +25,6 @@ type TweetCommentsReq struct { type TweetCommentsResp base.PageResp -type TopicListReq struct { - Type TagType `json:"type" form:"type" binding:"required"` - Num int `json:"num" form:"num" binding:"required"` -} - -// TopicListResp 主题返回值 -// TODO: 优化内容定义 -type TopicListResp struct { - Topics []*core.TagFormated `json:"topics"` -} - type GetCaptchaResp struct { Id string `json:"id"` Content string `json:"b64s"` diff --git a/internal/servants/web/loose.go b/internal/servants/web/loose.go index a619fd26..5efa0444 100644 --- a/internal/servants/web/loose.go +++ b/internal/servants/web/loose.go @@ -8,6 +8,7 @@ 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" @@ -149,6 +150,40 @@ func (s *looseSrv) GetUserProfile(req *web.GetUserProfileReq) (*web.GetUserProfi }, nil } +func (s *looseSrv) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error) { + var ( + tags, extralTags []*core.TagFormated + 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) + case web.TagTypeNew: + tags, err = s.Ds.GetNewestTags(num, 0) + case web.TagTypeFollow: + tags, err = s.Ds.GetFollowTags(num, 0) + case web.TagTypeHotExtral: + tags, err = s.Ds.GetHotTags(num, 0) + if err == nil { + extralTags, err = s.Ds.GetFollowTags(num, 0) + } + default: + // TODO: return good error + err = _errGetPostTagsFailed + } + if err != nil { + return nil, _errGetPostTagsFailed + } + return &web.TopicListResp{ + Topics: tags, + ExtralTopics: extralTags, + }, nil +} + func newLooseSrv(s *base.DaoServant) api.Loose { return &looseSrv{ DaoServant: s, diff --git a/internal/servants/web/pub.go b/internal/servants/web/pub.go index 3fa68f10..113a9ffb 100644 --- a/internal/servants/web/pub.go +++ b/internal/servants/web/pub.go @@ -18,7 +18,6 @@ import ( "github.com/gin-gonic/gin" "github.com/gofrs/uuid" 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" @@ -66,50 +65,6 @@ func (b *pubBinding) BindTweetComments(c *gin.Context) (*web.TweetCommentsReq, m }, nil } -func (s *pubSrv) TopicList(req *web.TopicListReq) (*web.TopicListResp, mir.Error) { - // tags, err := broker.GetPostTags(¶m) - num := req.Num - if num > conf.AppSetting.MaxPageSize { - num = conf.AppSetting.MaxPageSize - } - - conditions := &core.ConditionsT{} - if req.Type == web.TagTypeHot { - // 热门标签 - conditions = &core.ConditionsT{ - "ORDER": "quote_num DESC", - } - } else if req.Type == web.TagTypeNew { - // 热门标签 - conditions = &core.ConditionsT{ - "ORDER": "id DESC", - } - } - tags, err := s.Ds.GetTags(conditions, 0, num) - if err != nil { - return nil, _errGetPostTagsFailed - } - // 获取创建者User IDs - userIds := []int64{} - for _, tag := range tags { - userIds = append(userIds, tag.UserID) - } - users, _ := s.Ds.GetUsersByIDs(userIds) - tagsFormated := []*core.TagFormated{} - for _, tag := range tags { - tagFormated := tag.Format() - for _, user := range users { - if user.ID == tagFormated.UserID { - tagFormated.User = user.Format() - } - } - tagsFormated = append(tagsFormated, tagFormated) - } - return &web.TopicListResp{ - Topics: tagsFormated, - }, nil -} - func (s *pubSrv) TweetComments(req *web.TweetCommentsReq) (*web.TweetCommentsResp, mir.Error) { sort := "id ASC" if req.SortStrategy == "newest" { diff --git a/mirc/web/v1/loose.go b/mirc/web/v1/loose.go index 977ca649..4fb9ecdf 100644 --- a/mirc/web/v1/loose.go +++ b/mirc/web/v1/loose.go @@ -23,4 +23,7 @@ type Loose struct { // GetUserProfile 获取用户基本信息 GetUserProfile func(Get, web.GetUserProfileReq) web.GetUserProfileResp `mir:"/user/profile"` + + // TopicList 获取话题列表 + TopicList func(Get, web.TopicListReq) web.TopicListResp `mir:"/tags"` } diff --git a/mirc/web/v1/pub.go b/mirc/web/v1/pub.go index aadc5e48..33c1544a 100644 --- a/mirc/web/v1/pub.go +++ b/mirc/web/v1/pub.go @@ -34,7 +34,4 @@ type Pub struct { // TweetComments 获取动态评论 TweetComments func(Get, web.TweetCommentsReq) web.TweetCommentsResp `mir:"/post/comments"` - - // TopicList 获取话题列表 - TopicList func(Get, web.TopicListReq) web.TopicListResp `mir:"/tags"` } diff --git a/web/src/components/rightbar.vue b/web/src/components/rightbar.vue index 2e66b119..4fbd2537 100644 --- a/web/src/components/rightbar.vue +++ b/web/src/components/rightbar.vue @@ -13,9 +13,31 @@ + + +
+ + #{{ tag.tag }} + + +
+ {{ formatQuoteNum(tag.quote_num) }} +
+
+
+
-
+
+ + + + +
+ + + + + \ No newline at end of file diff --git a/web/src/store/index.ts b/web/src/store/index.ts index f0268f9c..60195adc 100644 --- a/web/src/store/index.ts +++ b/web/src/store/index.ts @@ -11,6 +11,7 @@ export default createStore({ desktopModelShow: document.body.clientWidth > 821, authModalShow: false, authModelTab: "signin", + userLogined: false, userInfo: { id: 0, username: "", @@ -40,10 +41,14 @@ export default createStore({ }, updateUserinfo(state, data) { state.userInfo = data; + if (state.userInfo.id > 0) { + state.userLogined = true; + } }, userLogout(state) { localStorage.removeItem("PAOPAO_TOKEN"); state.userInfo = { id: 0, nickname: "", username: "" }; + state.userLogined = false; }, }, actions: {}, diff --git a/web/src/types/Item.d.ts b/web/src/types/Item.d.ts index 2228e1a1..dde29899 100644 --- a/web/src/types/Item.d.ts +++ b/web/src/types/Item.d.ts @@ -290,6 +290,8 @@ declare module Item { modified_on?: number; /** 删除时间 */ deleted_on?: number; + /** 是否关注:0为未关注,1为已关注 */ + is_following?: 0 | 1; /** 是否删除:0为未删除,1为已删除 */ is_del?: 0 | 1; } diff --git a/web/src/types/NetParams.d.ts b/web/src/types/NetParams.d.ts index 95e23e54..017f95ec 100644 --- a/web/src/types/NetParams.d.ts +++ b/web/src/types/NetParams.d.ts @@ -165,7 +165,7 @@ declare module NetParams { } interface PostGetTags { - type: "hot" | "new"; + type: "hot" | "new" | "follow" | "hot_extral"; num: number; } diff --git a/web/src/types/NetReq.d.ts b/web/src/types/NetReq.d.ts index b317c587..1e7def92 100644 --- a/web/src/types/NetReq.d.ts +++ b/web/src/types/NetReq.d.ts @@ -1,197 +1,172 @@ declare module NetReq { + interface AuthUserLogin { + token: string; + } - interface AuthUserLogin { - token: string - } + interface AuthUserRegister { + /** 用户UID */ + id: number; + /** 用户名 */ + username: string; + } - interface AuthUserRegister { - /** 用户UID */ - id: number, - /** 用户名 */ - username: string - } + type AuthUserInfo = Item.UserInfo; - type AuthUserInfo = Item.UserInfo + interface AuthUpdateUserPassword {} - interface AuthUpdateUserPassword { + interface UserGetCollections { + /** 帖子列表 */ + list: Item.PostProps[]; + /** 页码信息 */ + pager: Item.PagerProps; + } - } + interface UserGetSuggestUsers { + suggest: string[]; + } - interface UserGetCollections { - /** 帖子列表 */ - list: Item.PostProps[], - /** 页码信息 */ - pager: Item.PagerProps - } + interface UserGetSuggestTags { + suggest: string[]; + } - interface UserGetSuggestUsers { - suggest: string[] - } + interface UserPrecheckAttachment { + paid: number; + } - interface UserGetSuggestTags { - suggest: string[] - } + interface UserGetAttachment { + signed_url: string; + } - interface UserPrecheckAttachment { - paid: number - } + interface UserGetUnreadMsgCount { + count: number; + } - interface UserGetAttachment { - signed_url: string - } + interface UserGetMessages { + /** 消息列表 */ + list: Item.MessageProps[]; + /** 页码信息 */ + pager: Item.PagerProps; + } + + interface UserGetUserPosts { + /** 帖子列表 */ + list: Item.PostProps[]; + /** 页码信息 */ + pager: Item.PagerProps; + } - interface UserGetUnreadMsgCount { - count: number - } + type UserGetUserProfile = Item.UserInfo; - interface UserGetMessages { - /** 消息列表 */ - list: Item.MessageProps[], - /** 页码信息 */ - pager: Item.PagerProps - } + interface UserGetBills { + list: Item.BillProps[]; + /** 页码信息 */ + pager: Item.PagerProps; + } - interface UserGetUserPosts { - /** 帖子列表 */ - list: Item.PostProps[], - /** 页码信息 */ - pager: Item.PagerProps - } + interface UserReqRecharge { + id: number; + pay: string; + } - type UserGetUserProfile = Item.UserInfo + interface UserGetRecharge { + status: string; + } - interface UserGetBills { - list: Item.BillProps[], - /** 页码信息 */ - pager: Item.PagerProps - } + interface UserBindUserPhone {} - interface UserReqRecharge { - id: number, - pay: string - } + interface UserGetCaptcha { + id: string; + /** 头像图片 base64 */ + b64s: string; + } - interface UserGetRecharge { - status: string - } + interface UserChangeNickname {} - interface UserBindUserPhone { + interface UserChangePassword {} - } + interface UserChangeStatus {} - interface UserGetCaptcha { - id: string, - /** 头像图片 base64 */ - b64s: string - } + interface AddFriend {} - interface UserChangeNickname { + interface DeleteFriend {} - } + interface GetContacts { + contacts: Item.ContactsItemProps; + total: number; + } - interface UserChangePassword { + interface RejectFriend {} - } + interface RequestingFriend {} - interface UserChangeStatus { + type PostGetPost = Item.PostProps; - } + interface PostGetPosts { + /** 帖子列表 */ + list: Item.PostProps[]; + /** 页码信息 */ + pager: Item.PagerProps; + } - interface AddFriend { + interface PostLockPost { + /** 锁定状态:0为未锁定,1为锁定 */ + lock_status: 0 | 1; + } - } + interface PostStickPost { + /** 置顶状态:0为未置顶,1为置顶 */ + top_status: 0 | 1; + } - interface DeleteFriend { + interface PostVisibilityPost { + /** 可见性:0为公开,1为私密,2为好友可见 */ + visibility_status: import("@/utils/IEnum").VisibilityEnum; + } - } + interface PostGetPostStar { + status: boolean; + } - interface GetContacts { - contacts: Item.ContactsItemProps, - total: number - } + interface PostPostStar { + status: boolean; + } - interface RejectFriend { + interface PostGetPostCollection { + status: boolean; + } - } + interface PostPostCollection { + status: boolean; + } - interface RequestingFriend { + interface PostGetTags { + topics: Item.TagProps[]; + extral_topics: Item.TagProps[]; + } - } + interface PostGetPostComments { + /** 评论列表 */ + list: Item.CommentProps[]; + /** 页码信息 */ + pager: Item.PagerProps; + } - type PostGetPost = Item.PostProps + type PostCreatePost = Item.PostProps; - interface PostGetPosts { - /** 帖子列表 */ - list: Item.PostProps[], - /** 页码信息 */ - pager: Item.PagerProps - } + interface PostDeletePost {} - interface PostLockPost { - /** 锁定状态:0为未锁定,1为锁定 */ - lock_status: 0 | 1 - } + type PostCreateComment = Item.CommentProps; - interface PostStickPost { - /** 置顶状态:0为未置顶,1为置顶 */ - top_status: 0 | 1 - } + interface PostDeleteComment {} - interface PostVisibilityPost { - /** 可见性:0为公开,1为私密,2为好友可见 */ - visibility_status: import('@/utils/IEnum').VisibilityEnum - } + type PostCreateCommentReply = Item.ReplyProps; - interface PostGetPostStar { - status: boolean - } - - interface PostPostStar { - status: boolean - } - - interface PostGetPostCollection { - status: boolean - } - - interface PostPostCollection { - status: boolean - } - - interface PostGetTags { - topics: Item.TagProps[] - } - - interface PostGetPostComments { - /** 评论列表 */ - list: Item.CommentProps[], - /** 页码信息 */ - pager: Item.PagerProps - } - - type PostCreatePost = Item.PostProps - - interface PostDeletePost { - - } - - type PostCreateComment = Item.CommentProps - - interface PostDeleteComment { - - } - - type PostCreateCommentReply = Item.ReplyProps - - interface PostDeleteCommentReply { - - } - - interface GetContacts { - /** 评论列表 */ - list: Item.ContactItemProps[], - /** 页码信息 */ - pager: Item.PagerProps - } + interface PostDeleteCommentReply {} + interface GetContacts { + /** 评论列表 */ + list: Item.ContactItemProps[]; + /** 页码信息 */ + pager: Item.PagerProps; + } } diff --git a/web/src/views/Topic.vue b/web/src/views/Topic.vue index 9da25620..35d60b75 100644 --- a/web/src/views/Topic.vue +++ b/web/src/views/Topic.vue @@ -6,33 +6,17 @@ + - - - #{{ tag.tag }} - - ({{ tag.quote_num }}) - - + @@ -40,11 +24,13 @@ + @@ -27,8 +27,8 @@ - - + + diff --git a/web/src/api/post.ts b/web/src/api/post.ts index 8d37858c..a16fb77c 100644 --- a/web/src/api/post.ts +++ b/web/src/api/post.ts @@ -1,163 +1,232 @@ -import { request } from '@/utils/request'; +import { request } from "@/utils/request"; /** 获取动态列表 */ -export const getPosts = (params: NetParams.PostGetPosts): Promise => { - return request({ - method: 'get', - url: '/v1/posts', - params - }); +export const getPosts = ( + params: NetParams.PostGetPosts +): Promise => { + return request({ + method: "get", + url: "/v1/posts", + params, + }); }; /** 获取标签列表 */ -export const getTags = (params: NetParams.PostGetTags): Promise => { - return request({ - method: 'get', - url: '/v1/tags', - params - }); +export const getTags = ( + params: NetParams.PostGetTags +): Promise => { + return request({ + method: "get", + url: "/v1/tags", + params, + }); }; /** 获取动态详情 */ -export const getPost = (params: NetParams.PostGetPost): Promise => { - return request({ - method: 'get', - url: '/v1/post', - params - }); +export const getPost = ( + params: NetParams.PostGetPost +): Promise => { + return request({ + method: "get", + url: "/v1/post", + params, + }); }; /** 获取动态点赞状态 */ -export const getPostStar = (params: NetParams.PostPostStar): Promise => { - return request({ - method: 'get', - url: '/v1/post/star', - params - }); +export const getPostStar = ( + params: NetParams.PostPostStar +): Promise => { + return request({ + method: "get", + url: "/v1/post/star", + params, + }); }; /** 动态点赞 */ -export const postStar = (data: NetParams.PostPostStar): Promise => { - return request({ - method: 'post', - url: '/v1/post/star', - data - }); +export const postStar = ( + data: NetParams.PostPostStar +): Promise => { + return request({ + method: "post", + url: "/v1/post/star", + data, + }); }; /** 获取动态收藏状态 */ -export const getPostCollection = (params: NetParams.PostGetPostCollection): Promise => { - return request({ - method: 'get', - url: '/v1/post/collection', - params - }); +export const getPostCollection = ( + params: NetParams.PostGetPostCollection +): Promise => { + return request({ + method: "get", + url: "/v1/post/collection", + params, + }); }; /** 动态收藏 */ -export const postCollection = (data: NetParams.PostPostCollection): Promise => { - return request({ - method: 'post', - url: '/v1/post/collection', - data - }); +export const postCollection = ( + data: NetParams.PostPostCollection +): Promise => { + return request({ + method: "post", + url: "/v1/post/collection", + data, + }); }; /** 获取动态评论列表 */ -export const getPostComments = (params: NetParams.PostGetPostComments): Promise => { - return request({ - method: 'get', - url: '/v1/post/comments', - params - }); +export const getPostComments = ( + params: NetParams.PostGetPostComments +): Promise => { + return request({ + method: "get", + url: "/v1/post/comments", + params, + }); }; /** 获取联系人列表 */ -export const getContacts = (params: NetParams.GetContacts): Promise => { - return request({ - method: 'get', - url: '/v1/user/contacts', - params - }); +export const getContacts = ( + params: NetParams.GetContacts +): Promise => { + return request({ + method: "get", + url: "/v1/user/contacts", + params, + }); }; /** 发布动态 */ -export const createPost = (data: NetParams.PostCreatePost): Promise => { - return request({ - method: 'post', - url: '/v1/post', - data - }); +export const createPost = ( + data: NetParams.PostCreatePost +): Promise => { + return request({ + method: "post", + url: "/v1/post", + data, + }); }; /** 删除动态 */ -export const deletePost = (data: NetParams.PostDeletePost): Promise => { - return request({ - method: 'delete', - url: '/v1/post', - data - }); +export const deletePost = ( + data: NetParams.PostDeletePost +): Promise => { + return request({ + method: "delete", + url: "/v1/post", + data, + }); }; /** 锁定/解锁动态 */ -export const lockPost = (data: NetParams.PostLockPost): Promise => { - return request({ - method: 'post', - url: '/v1/post/lock', - data - }); +export const lockPost = ( + data: NetParams.PostLockPost +): Promise => { + return request({ + method: "post", + url: "/v1/post/lock", + data, + }); }; /** 置顶/取消置顶动态 */ -export const stickPost = (data: NetParams.PostStickPost): Promise => { - return request({ - method: 'post', - url: '/v1/post/stick', - data - }); +export const stickPost = ( + data: NetParams.PostStickPost +): Promise => { + return request({ + method: "post", + url: "/v1/post/stick", + data, + }); }; /** 置顶/取消置顶动态 */ -export const visibilityPost = (data: NetParams.PostVisibilityPost): Promise => { - return request({ - method: 'post', - url: '/v1/post/visibility', - data - }); +export const visibilityPost = ( + data: NetParams.PostVisibilityPost +): Promise => { + return request({ + method: "post", + url: "/v1/post/visibility", + data, + }); }; /** 发布动态评论 */ -export const createComment = (data: NetParams.PostCreateComment): Promise => { - return request({ - method: 'post', - url: '/v1/post/comment', - data - }); +export const createComment = ( + data: NetParams.PostCreateComment +): Promise => { + return request({ + method: "post", + url: "/v1/post/comment", + data, + }); }; /** 删除评论 */ -export const deleteComment = (data: NetParams.PostDeleteComment): Promise => { - return request({ - method: 'delete', - url: '/v1/post/comment', - data - }); +export const deleteComment = ( + data: NetParams.PostDeleteComment +): Promise => { + return request({ + method: "delete", + url: "/v1/post/comment", + data, + }); }; /** 发布评论回复 */ -export const createCommentReply = (data: NetParams.PostCreateCommentReply): Promise => { - return request({ - method: 'post', - url: '/v1/post/comment/reply', - data - }); +export const createCommentReply = ( + data: NetParams.PostCreateCommentReply +): Promise => { + return request({ + method: "post", + url: "/v1/post/comment/reply", + data, + }); }; /** 删除评论回复 */ -export const deleteCommentReply = (data: NetParams.PostDeleteCommentReply): Promise => { - return request({ - method: 'delete', - url: '/v1/post/comment/reply', - data - }); +export const deleteCommentReply = ( + data: NetParams.PostDeleteCommentReply +): Promise => { + return request({ + method: "delete", + url: "/v1/post/comment/reply", + data, + }); +}; + +/** 置顶/取消置顶话题 */ +export const stickTopic = ( + data: NetParams.PostStickTopic +): Promise => { + return request({ + method: "post", + url: "/v1/topic/stick", + data, + }); +}; + +/** 关注话题 */ +export const followTopic = ( + data: NetParams.PostFollowTopic +): Promise => { + return request({ + method: "post", + url: "/v1/topic/follow", + data, + }); +}; + +/** 取消关注话题 */ +export const unfollowTopic = ( + data: NetParams.PostUnfollowTopic +): Promise => { + return request({ + method: "post", + url: "/v1/topic/unfollow", + data, + }); }; diff --git a/web/src/components/rightbar.vue b/web/src/components/rightbar.vue index 705edc4c..3a4d6a43 100644 --- a/web/src/components/rightbar.vue +++ b/web/src/components/rightbar.vue @@ -82,7 +82,7 @@