feat: dislike topic

This commit is contained in:
KUN1007 2023-10-04 22:35:25 +08:00
parent b4dddd7c11
commit d3e45850ce
5 changed files with 109 additions and 24 deletions

View file

@ -79,6 +79,18 @@ export async function updateTopicLikeApi(
return response return response
} }
// 点踩话题
export async function updateTopicDislikeApi(
request: Action.TopicDislikeTopicRequestData
): Promise<Action.TopicDislikeTopicResponseData> {
const queryParams = objectToQueryParams(request, 'tid')
const url = `/topics/${request.tid}/dislike?${queryParams}`
const response = fetchPut<Action.TopicDislikeTopicResponseData>(url)
return response
}
// 根据话题 tid 获取话题回复 // 根据话题 tid 获取话题回复
export async function getRepliesByPidApi( export async function getRepliesByPidApi(
request: Topic.TopicReplyRequestData request: Topic.TopicReplyRequestData

View file

@ -15,8 +15,18 @@ export interface TopicLikeTopicRequestData {
isPush: boolean isPush: boolean
} }
// 点踩
export interface TopicDislikeTopicRequestData {
tid: number
to_uid: number
isPush: boolean
}
// 推话题响应数据的格式 // 推话题响应数据的格式
export type TopicUpvoteTopicResponseData = KUNGalgameResponseData<{}> export type TopicUpvoteTopicResponseData = KUNGalgameResponseData<{}>
// 点赞话题响应数据的格式 // 点赞话题响应数据的格式
export type TopicLikeTopicResponseData = KUNGalgameResponseData<{}> export type TopicLikeTopicResponseData = KUNGalgameResponseData<{}>
// 点踩话题响应数据的格式
export type TopicDislikeTopicResponseData = KUNGalgameResponseData<{}>

View file

@ -19,6 +19,9 @@ import {
updateTopicLikeApi, updateTopicLikeApi,
TopicLikeTopicRequestData, TopicLikeTopicRequestData,
TopicLikeTopicResponseData, TopicLikeTopicResponseData,
updateTopicDislikeApi,
TopicDislikeTopicRequestData,
TopicDislikeTopicResponseData,
} from '@/api' } from '@/api'
// 回复 // 回复
@ -136,8 +139,22 @@ export const useKUNGalgameTopicStore = defineStore({
return await updateTopicLikeApi(requestData) return await updateTopicLikeApi(requestData)
}, },
// 点踩话题
async updateTopicDislike(
tid: number,
toUid: number,
isPush: boolean
): Promise<TopicDislikeTopicResponseData> {
const requestData: TopicDislikeTopicRequestData = {
tid: tid,
to_uid: toUid,
isPush: isPush,
}
return await updateTopicDislikeApi(requestData)
},
// 获取回复 // 获取回复
async getReplies(tid: number): Promise<TopicReplyResponseData> { async getReplies(tid: number): Promise<TopicDislikeTopicResponseData> {
// 这里的默认值用于初始化 // 这里的默认值用于初始化
const requestData: TopicReplyRequestData = { const requestData: TopicReplyRequestData = {
tid: tid, tid: tid,

View file

@ -102,7 +102,7 @@ const loliStatus = computed(() => {
<Rewrite v-if="edited" :time="edited" /> <Rewrite v-if="edited" :time="edited" />
</div> </div>
</div> </div>
<!-- 话题的点赞数等信息楼主的 floor 就是 0被作用人就是该话题的发布人 --> <!-- 话题的点赞数等信息被作用人就是该话题的发布人 -->
<MasterFooter <MasterFooter
:info="{ :info="{
tid, tid,
@ -111,7 +111,6 @@ const loliStatus = computed(() => {
dislikes, dislikes,
upvotes, upvotes,
share, share,
to_floor: 0,
}" }"
:topic="{ tid, title, content, tags, category }" :topic="{ tid, title, content, tags, category }"
:master="user" :master="user"

View file

@ -36,8 +36,6 @@ const props = defineProps<{
dislikes: number[] dislikes: number[]
upvotes: number[] upvotes: number[]
share: number[] share: number[]
// floor
to_floor: number
} }
topic: { topic: {
tid: number tid: number
@ -56,8 +54,10 @@ const props = defineProps<{
*/ */
// uid // uid
const currUserUid = useKUNGalgameUserStore().uid const currUserUid = useKUNGalgameUserStore().uid
// uid
const masterUid = props.master.uid
// //
const isShowRewrite = currUserUid === props.master.uid const isShowRewrite = currUserUid === masterUid
// footer // footer
const actions = reactive({ const actions = reactive({
@ -75,11 +75,20 @@ const isActive = reactive({
isShared: false, isShared: false,
}) })
// throttle
const throttleCallback = () => {
message(
'You can only perform one operation within 1007 milliseconds',
'您在 1007 毫秒内只能进行一次操作',
'warn'
)
}
// throttle 1007 // throttle 1007
const handleClickLikeThrottled = throttle( const handleClickLikeThrottled = throttle(
async () => { async () => {
// //
if (currUserUid === props.master.uid) { if (currUserUid === masterUid) {
message( message(
'You cannot like your own topic', 'You cannot like your own topic',
'您不可以给自己的话题点赞', '您不可以给自己的话题点赞',
@ -93,7 +102,7 @@ const handleClickLikeThrottled = throttle(
const res = await useKUNGalgameTopicStore().updateTopicLike( const res = await useKUNGalgameTopicStore().updateTopicLike(
props.info.tid, props.info.tid,
props.master.uid, masterUid,
isActive.isLiked isActive.isLiked
) )
@ -107,19 +116,45 @@ const handleClickLikeThrottled = throttle(
} }
}, },
1007, 1007,
() => { throttleCallback
)
// throttle 1007
const handleClickDislikeThrottled = throttle(
async () => {
if (currUserUid === masterUid) {
message( message(
'You can only perform one operation within 1007 milliseconds', 'You cannot dislike your own topic',
'您在 1007 毫秒内只能进行一次操作', '您不可以给自己的话题点踩',
'warn' 'warn'
) )
return
} }
isActive.isDisliked = !isActive.isDisliked
const res = await useKUNGalgameTopicStore().updateTopicDislike(
props.info.tid,
masterUid,
isActive.isDisliked
)
if (res.code === 200) {
//
actions.dislikes.length = isActive.isDisliked
? actions.dislikes.length + 1
: actions.dislikes.length - 1
} else {
message('Topic dislike failed!', '点踩话题失败', 'error')
}
},
1007,
throttleCallback
) )
// //
const handleClickUpvote = async () => { const handleClickUpvote = async () => {
// //
if (currUserUid === props.master.uid) { if (currUserUid === masterUid) {
message('You cannot upvote your own topic', '您不可以推自己的话题', 'warn') message('You cannot upvote your own topic', '您不可以推自己的话题', 'warn')
return return
} }
@ -145,7 +180,7 @@ const handleClickUpvote = async () => {
// //
const res = await useKUNGalgameTopicStore().updateTopicUpvote( const res = await useKUNGalgameTopicStore().updateTopicUpvote(
props.info.tid, props.info.tid,
props.master.uid masterUid
) )
if (res.code === 200) { if (res.code === 200) {
@ -164,19 +199,25 @@ const handleClickLike = () => {
handleClickLikeThrottled() handleClickLikeThrottled()
} }
//
const handleClickDislike = () => {
handleClickDislikeThrottled()
}
// //
const handelReply = async () => { const handleClickReply = async () => {
// 便 // 便
replyDraft.value.tid = props.info.tid replyDraft.value.tid = props.info.tid
// uid // uid
replyDraft.value.to_uid = props.master.uid replyDraft.value.to_uid = masterUid
replyDraft.value.to_floor = props.info.to_floor // floor 0
replyDraft.value.to_floor = 0
//
isEdit.value = true isEdit.value = true
} }
// //
const handleClickEdit = () => { const handleClickRewrite = () => {
// //
topicRewrite.value.tid = props.topic.tid topicRewrite.value.tid = props.topic.tid
topicRewrite.value.title = props.topic.title topicRewrite.value.title = props.topic.title
@ -250,7 +291,13 @@ onMounted(() => {
</li> </li>
<!-- --> <!-- -->
<li> <li>
<span class="icon"><Icon icon="line-md:thumbs-down-twotone" /></span> <span
class="icon"
:class="isActive.isDisliked ? 'active' : ''"
@click="handleClickDislike"
>
<Icon icon="line-md:thumbs-down-twotone" />
</span>
{{ actions.dislikes.length }} {{ actions.dislikes.length }}
</li> </li>
</ul> </ul>
@ -258,7 +305,7 @@ onMounted(() => {
<!-- 底部右侧部分回复评论只看编辑 --> <!-- 底部右侧部分回复评论只看编辑 -->
<div class="right"> <div class="right">
<div @click="handelReply" class="reply"> <div @click="handleClickReply" class="reply">
{{ $tm('topic.content.reply') }} {{ $tm('topic.content.reply') }}
</div> </div>
@ -269,7 +316,7 @@ onMounted(() => {
<span class="icon"><Icon icon="ph:user-focus-duotone" /></span> <span class="icon"><Icon icon="ph:user-focus-duotone" /></span>
<!-- 编辑 --> <!-- 编辑 -->
<span v-if="isShowRewrite" @click="handleClickEdit" class="icon"> <span v-if="isShowRewrite" @click="handleClickRewrite" class="icon">
<Icon icon="line-md:pencil-twotone-alt" /> <Icon icon="line-md:pencil-twotone-alt" />
</span> </span>
</div> </div>