feat: dislike topic
This commit is contained in:
parent
b4dddd7c11
commit
d3e45850ce
|
@ -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
|
||||||
|
|
|
@ -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<{}>
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue