fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import http, { type ApiResponse } from "utils/http"
|
||||
import http from "utils/http"
|
||||
import { filterResult } from "oj/transforms"
|
||||
import type {
|
||||
Exercise,
|
||||
@@ -226,43 +226,16 @@ export function getMessageList(offset = 0, limit = 10) {
|
||||
}
|
||||
|
||||
export function getReaction(problemID: number) {
|
||||
return http
|
||||
.get<ReactionWireState>("reaction", {
|
||||
return http.get<ReactionState>("reaction", {
|
||||
params: { problem_id: problemID },
|
||||
})
|
||||
.then(normalizeReactionResponse)
|
||||
}
|
||||
|
||||
interface ReactionWireState {
|
||||
mine: ReactionKey[] | ReactionKey | null
|
||||
mine_type?: ReactionKey | null
|
||||
counts: ReactionState["counts"]
|
||||
}
|
||||
|
||||
function normalizeReactionResponse(
|
||||
res: ApiResponse<ReactionWireState>,
|
||||
): ApiResponse<ReactionState> {
|
||||
const legacyMine = Array.isArray(res.data.mine)
|
||||
? (res.data.mine[0] ?? null)
|
||||
: res.data.mine
|
||||
return {
|
||||
...res,
|
||||
data: {
|
||||
mine: res.data.mine_type ?? legacyMine,
|
||||
counts: res.data.counts,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function setReaction(problemID: number, type: ReactionKey) {
|
||||
return http
|
||||
.post<ReactionWireState>("reaction", {
|
||||
return http.post<ReactionState>("reaction", {
|
||||
problem_id: problemID,
|
||||
type,
|
||||
// 过渡期同时发送旧字段:新前端先上线时,旧后端也能接受单选提交。
|
||||
types: [type],
|
||||
})
|
||||
.then(normalizeReactionResponse)
|
||||
}
|
||||
|
||||
// TODO: 这个API有问题
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
v-for="item in REACTIONS"
|
||||
:key="item.key"
|
||||
trigger="hover"
|
||||
:disabled="solved && !locked"
|
||||
:disabled="solved"
|
||||
>
|
||||
<template #trigger>
|
||||
<n-button
|
||||
@@ -23,7 +23,7 @@
|
||||
<span v-if="counts" class="count">{{ counts[item.key] }}</span>
|
||||
</n-button>
|
||||
</template>
|
||||
{{ tooltipOf(item.label) }}
|
||||
完成本题后可以评价
|
||||
</n-tooltip>
|
||||
</n-flex>
|
||||
<div v-if="solved" class="hint">
|
||||
@@ -55,12 +55,7 @@ const submitting = ref<ReactionKey | null>(null)
|
||||
|
||||
const solved = computed(() => problem.value?.my_status === 0)
|
||||
// 评价一次定终身:后端已存在记录就锁死,只剩查看
|
||||
const locked = ref(false)
|
||||
|
||||
function tooltipOf(label: string) {
|
||||
if (!solved.value) return "完成本题后可以评价"
|
||||
return `${label}(已评价,不能修改)`
|
||||
}
|
||||
const locked = computed(() => mine.value !== null)
|
||||
|
||||
async function pick(key: ReactionKey) {
|
||||
if (!problem.value) return
|
||||
@@ -69,7 +64,6 @@ async function pick(key: ReactionKey) {
|
||||
const res = await setReaction(problem.value.id, key)
|
||||
mine.value = res.data.mine
|
||||
counts.value = res.data.counts
|
||||
locked.value = true
|
||||
emit("submitted")
|
||||
} catch {
|
||||
message.error("提交失败,请重试")
|
||||
@@ -83,7 +77,6 @@ async function load() {
|
||||
const res = await getReaction(problem.value.id)
|
||||
mine.value = res.data.mine
|
||||
counts.value = res.data.counts
|
||||
locked.value = res.data.mine !== null
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -40,9 +40,8 @@ const router = useRouter()
|
||||
const [commentPanel] = useToggle()
|
||||
const message = useMessage()
|
||||
|
||||
// 评价提交后停一下让用户看到选中态,再收起弹窗
|
||||
function closeCommentPanel() {
|
||||
setTimeout(() => (commentPanel.value = false), 800)
|
||||
commentPanel.value = false
|
||||
}
|
||||
|
||||
const { isDesktop } = useBreakpoints()
|
||||
@@ -266,6 +265,8 @@ watch(
|
||||
preset="card"
|
||||
title="恭喜你成功提交,说说你对这道题的感受吧"
|
||||
:mask-closable="false"
|
||||
:closable="false"
|
||||
:close-on-esc="false"
|
||||
:style="{ maxWidth: isDesktop && '50vw', maxHeight: '80vh' }"
|
||||
v-model:show="commentPanel"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user