fix
Some checks failed
Deploy / deploy (build, debian, 22, /root/OJDeploy/data/clientnext) (push) Has been cancelled
Deploy / deploy (build:staging, school, 8822, /root/OJ/data/dist) (push) Has been cancelled

This commit is contained in:
2026-08-06 08:36:04 -06:00
parent 280e360506
commit d7b57074d3
3 changed files with 14 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
import http, { type ApiResponse } from "utils/http" import http from "utils/http"
import { filterResult } from "oj/transforms" import { filterResult } from "oj/transforms"
import type { import type {
Exercise, Exercise,
@@ -226,43 +226,16 @@ export function getMessageList(offset = 0, limit = 10) {
} }
export function getReaction(problemID: number) { export function getReaction(problemID: number) {
return http return http.get<ReactionState>("reaction", {
.get<ReactionWireState>("reaction", { params: { problem_id: problemID },
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) { export function setReaction(problemID: number, type: ReactionKey) {
return http return http.post<ReactionState>("reaction", {
.post<ReactionWireState>("reaction", { problem_id: problemID,
problem_id: problemID, type,
type, })
// 过渡期同时发送旧字段:新前端先上线时,旧后端也能接受单选提交。
types: [type],
})
.then(normalizeReactionResponse)
} }
// TODO: 这个API有问题 // TODO: 这个API有问题

View File

@@ -6,7 +6,7 @@
v-for="item in REACTIONS" v-for="item in REACTIONS"
:key="item.key" :key="item.key"
trigger="hover" trigger="hover"
:disabled="solved && !locked" :disabled="solved"
> >
<template #trigger> <template #trigger>
<n-button <n-button
@@ -23,7 +23,7 @@
<span v-if="counts" class="count">{{ counts[item.key] }}</span> <span v-if="counts" class="count">{{ counts[item.key] }}</span>
</n-button> </n-button>
</template> </template>
{{ tooltipOf(item.label) }} 完成本题后可以评价
</n-tooltip> </n-tooltip>
</n-flex> </n-flex>
<div v-if="solved" class="hint"> <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 solved = computed(() => problem.value?.my_status === 0)
// 评价一次定终身:后端已存在记录就锁死,只剩查看 // 评价一次定终身:后端已存在记录就锁死,只剩查看
const locked = ref(false) const locked = computed(() => mine.value !== null)
function tooltipOf(label: string) {
if (!solved.value) return "完成本题后可以评价"
return `${label}(已评价,不能修改)`
}
async function pick(key: ReactionKey) { async function pick(key: ReactionKey) {
if (!problem.value) return if (!problem.value) return
@@ -69,7 +64,6 @@ async function pick(key: ReactionKey) {
const res = await setReaction(problem.value.id, key) const res = await setReaction(problem.value.id, key)
mine.value = res.data.mine mine.value = res.data.mine
counts.value = res.data.counts counts.value = res.data.counts
locked.value = true
emit("submitted") emit("submitted")
} catch { } catch {
message.error("提交失败,请重试") message.error("提交失败,请重试")
@@ -83,7 +77,6 @@ async function load() {
const res = await getReaction(problem.value.id) const res = await getReaction(problem.value.id)
mine.value = res.data.mine mine.value = res.data.mine
counts.value = res.data.counts counts.value = res.data.counts
locked.value = res.data.mine !== null
} }
onMounted(() => { onMounted(() => {

View File

@@ -40,9 +40,8 @@ const router = useRouter()
const [commentPanel] = useToggle() const [commentPanel] = useToggle()
const message = useMessage() const message = useMessage()
// 评价提交后停一下让用户看到选中态,再收起弹窗
function closeCommentPanel() { function closeCommentPanel() {
setTimeout(() => (commentPanel.value = false), 800) commentPanel.value = false
} }
const { isDesktop } = useBreakpoints() const { isDesktop } = useBreakpoints()
@@ -266,6 +265,8 @@ watch(
preset="card" preset="card"
title="恭喜你成功提交,说说你对这道题的感受吧" title="恭喜你成功提交,说说你对这道题的感受吧"
:mask-closable="false" :mask-closable="false"
:closable="false"
:close-on-esc="false"
:style="{ maxWidth: isDesktop && '50vw', maxHeight: '80vh' }" :style="{ maxWidth: isDesktop && '50vw', maxHeight: '80vh' }"
v-model:show="commentPanel" v-model:show="commentPanel"
> >