添加 rating
This commit is contained in:
@@ -133,6 +133,7 @@ export const Submission = {
|
||||
},
|
||||
|
||||
async updateScore(id: string, score: number) {
|
||||
await http.put(`/submission/${id}/score`, { score })
|
||||
const res = await http.put(`/submission/${id}/score`, { score })
|
||||
return res.data
|
||||
},
|
||||
}
|
||||
|
||||
@@ -7,27 +7,20 @@
|
||||
<n-flex>
|
||||
<n-button quaternary @click="download" :disabled="!showDL">下载</n-button>
|
||||
<n-button quaternary @click="open">展示</n-button>
|
||||
<template v-if="!!submission.id">
|
||||
<n-flex v-if="!!submission.id">
|
||||
<n-button quaternary @click="emits('showCode')">查看代码</n-button>
|
||||
<n-popover v-if="!submission.score && (roleAdmin || roleSuper)">
|
||||
<n-popover v-if="submission.my_score === 0">
|
||||
<template #trigger>
|
||||
<n-button secondary type="primary">手动打分</n-button>
|
||||
</template>
|
||||
<n-rate :size="30" @update:value="updateScore" />
|
||||
</n-popover>
|
||||
<n-button
|
||||
v-if="!submission.score && (roleAdmin || roleSuper)"
|
||||
secondary
|
||||
type="info"
|
||||
>
|
||||
智能打分
|
||||
</n-button>
|
||||
</template>
|
||||
<!-- <n-button secondary type="info">智能打分</n-button> -->
|
||||
</n-flex>
|
||||
</n-flex>
|
||||
</n-flex>
|
||||
<iframe class="iframe" ref="iframe"></iframe>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { watchDebounced } from "@vueuse/core"
|
||||
import { computed, onMounted, useTemplateRef } from "vue"
|
||||
@@ -35,7 +28,6 @@ import { Icon } from "@iconify/vue"
|
||||
import { Submission } from "../api"
|
||||
import { submission } from "../store/submission"
|
||||
import { useMessage } from "naive-ui"
|
||||
import { roleAdmin, roleSuper } from "../store/user"
|
||||
|
||||
interface Props {
|
||||
html: string
|
||||
@@ -100,9 +92,9 @@ function open() {
|
||||
|
||||
async function updateScore(score: number) {
|
||||
try {
|
||||
await Submission.updateScore(submission.value.id, score)
|
||||
message.success("评分成功")
|
||||
submission.value.score = score
|
||||
const res = await Submission.updateScore(submission.value.id, score)
|
||||
message.success(res.message)
|
||||
submission.value.my_score = score
|
||||
emits("afterScore")
|
||||
} catch (err: any) {
|
||||
message.error(err.response.data.detail)
|
||||
|
||||
@@ -40,7 +40,7 @@ import { taskId } from "../store/task"
|
||||
|
||||
const displays = ref<number[]>([])
|
||||
const content = useStorage(STORAGE_KEY.CONTENT, "")
|
||||
const $content = useTemplateRef("$content")
|
||||
const $content = useTemplateRef<any>("$content")
|
||||
|
||||
defineEmits(["hide"])
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
:css="css"
|
||||
:js="js"
|
||||
@after-score="afterScore"
|
||||
@show-code="toggleShowCode"
|
||||
@show-code="codeModal = true"
|
||||
/>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
@@ -91,7 +91,15 @@ const columns: DataTableColumn<SubmissionOut>[] = [
|
||||
render: (submission) => h(TaskTitle, { submission }),
|
||||
},
|
||||
{
|
||||
title: "得分",
|
||||
title: "我打的分",
|
||||
key: "my_score",
|
||||
render: (row) => {
|
||||
if (row.my_score > 0) return row.my_score
|
||||
else return "-"
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "平均得分",
|
||||
key: "score",
|
||||
render: (row) => {
|
||||
if (row.score > 0) return row.score
|
||||
@@ -120,14 +128,10 @@ async function getSubmissionByID(id: string) {
|
||||
submission.value = await Submission.get(id)
|
||||
}
|
||||
|
||||
function toggleShowCode() {
|
||||
codeModal.value = true
|
||||
}
|
||||
|
||||
function afterScore() {
|
||||
data.value = data.value.map((d) => {
|
||||
if (d.id === submission.value.id) {
|
||||
d.score = submission.value.score
|
||||
d.my_score = submission.value.my_score
|
||||
}
|
||||
return d
|
||||
})
|
||||
@@ -143,6 +147,7 @@ onUnmounted(() => {
|
||||
task_title: "",
|
||||
task_type: "tutorial",
|
||||
score: 0,
|
||||
my_score: 0,
|
||||
html: "",
|
||||
css: "",
|
||||
js: "",
|
||||
|
||||
@@ -7,7 +7,8 @@ export const submission = ref<SubmissionAll>({
|
||||
username: "",
|
||||
task_title: "",
|
||||
task_type: "tutorial",
|
||||
score: 0,
|
||||
score: 0.0,
|
||||
my_score: 0,
|
||||
html: "",
|
||||
css: "",
|
||||
js: "",
|
||||
|
||||
@@ -44,6 +44,7 @@ export interface SubmissionOut {
|
||||
task_type: string
|
||||
task_title: string
|
||||
score: number
|
||||
my_score: number
|
||||
created: Date
|
||||
modified: Date
|
||||
}
|
||||
@@ -55,6 +56,7 @@ export interface SubmissionAll {
|
||||
task_type: string
|
||||
task_title: string
|
||||
score: number
|
||||
my_score: number
|
||||
html: ""
|
||||
css: ""
|
||||
js: ""
|
||||
|
||||
Reference in New Issue
Block a user