update
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
2025-10-23 23:20:00 +08:00
parent 791828b9e1
commit df24bf7f54
18 changed files with 591 additions and 359 deletions

View File

@@ -1,16 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import {
NModal,
NForm,
NFormItem,
NInput,
NInputNumber,
NSelect,
NButton,
NFlex,
NImage,
} from "naive-ui"
interface Props { interface Props {
show: boolean show: boolean
} }

View File

@@ -1,15 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import {
NModal,
NForm,
NFormItem,
NInput,
NInputNumber,
NSwitch,
NButton,
NFlex,
} from "naive-ui"
interface Props { interface Props {
show: boolean show: boolean
} }

View File

@@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { h } from "vue" import { h } from "vue"
import { NDataTable, NButton, NFlex, NImage } from "naive-ui"
import { ProblemSetBadge } from "utils/types" import { ProblemSetBadge } from "utils/types"
import { NButton, NImage } from "naive-ui"
interface Props { interface Props {
badges: ProblemSetBadge[] badges: ProblemSetBadge[]

View File

@@ -1,15 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import {
NModal,
NForm,
NFormItem,
NInput,
NInputNumber,
NSelect,
NButton,
NFlex,
NImage,
} from "naive-ui"
import { ProblemSetBadge } from "utils/types" import { ProblemSetBadge } from "utils/types"
interface Props { interface Props {

View File

@@ -1,14 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import {
NModal,
NForm,
NFormItem,
NInput,
NInputNumber,
NSwitch,
NButton,
NFlex,
} from "naive-ui"
import { ProblemSetProblem } from "utils/types" import { ProblemSetProblem } from "utils/types"
interface Props { interface Props {

View File

@@ -1,5 +1,4 @@
<script setup lang="ts"> <script setup lang="ts">
import { NCard, NTag, NButton, NFlex } from "naive-ui"
import { parseTime } from "utils/functions" import { parseTime } from "utils/functions"
import { ProblemSet } from "utils/types" import { ProblemSet } from "utils/types"

View File

@@ -31,7 +31,7 @@ const progressColumns = [
title: "进度", title: "进度",
key: "progress_percentage", key: "progress_percentage",
width: 100, width: 100,
render: (row: ProblemSetProgress) => `${row.progress_percentage}%`, render: (row: ProblemSetProgress) => `${row.progress_percentage.toFixed(0)}%`,
}, },
{ {
title: "是否完成", title: "是否完成",

View File

@@ -1,16 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { NSwitch, NSelect, NTag } from "naive-ui"
import Pagination from "shared/components/Pagination.vue" import Pagination from "shared/components/Pagination.vue"
import { usePagination } from "shared/composables/pagination" import { usePagination } from "shared/composables/pagination"
import { parseTime } from "utils/functions" import { parseTime } from "utils/functions"
import { ProblemSetList } from "utils/types" import { ProblemSetList } from "utils/types"
import { import { getProblemSetList, toggleProblemSetVisible } from "../api"
getProblemSetList,
toggleProblemSetVisible,
updateProblemSetStatus,
deleteProblemSet,
} from "../api"
import Actions from "./components/Actions.vue" import Actions from "./components/Actions.vue"
import { NTag, NSwitch } from "naive-ui"
const total = ref(0) const total = ref(0)
const problemSets = ref<ProblemSetList[]>([]) const problemSets = ref<ProblemSetList[]>([])

View File

@@ -359,3 +359,8 @@ export function getUserBadges() {
export function getProblemSetBadges(problemSetId: number) { export function getProblemSetBadges(problemSetId: number) {
return http.get(`problemset/${problemSetId}/badges`) return http.get(`problemset/${problemSetId}/badges`)
} }
// 获取题单用户进度列表
export function getProblemSetUserProgress(problemSetId: number) {
return http.get(`problemset/${problemSetId}/users_progress`)
}

View File

@@ -18,10 +18,13 @@ type Sample = Problem["samples"][number] & {
const theme = useThemeVars() const theme = useThemeVars()
const style = computed(() => "color: " + theme.value.primaryColor) const style = computed(() => "color: " + theme.value.primaryColor)
const route = useRoute()
const codeStore = useCodeStore() const codeStore = useCodeStore()
const problemStore = useProblemStore() const problemStore = useProblemStore()
const { problem } = storeToRefs(problemStore) const { problem } = storeToRefs(problemStore)
const problemSetId = computed(() => route.params.problemSetId)
// 判断用户是否尝试过但未通过 // 判断用户是否尝试过但未通过
// my_status === 0: 已通过 // my_status === 0: 已通过
// my_status !== 0 && my_status !== null: 尝试过但未通过 // my_status !== 0 && my_status !== null: 尝试过但未通过
@@ -106,24 +109,27 @@ function type(status: ProblemStatus) {
<template> <template>
<div v-if="problem" class="problemContent"> <div v-if="problem" class="problemContent">
<!-- 已通过 --> <template v-if="!problemSetId">
<n-alert <!-- 已通过 -->
class="status-alert" <n-alert
v-if="problem.my_status === 0" class="status-alert"
type="success" v-if="problem.my_status === 0"
title="🎉 本 题 已 经 被 你 解 决 啦" type="success"
> title="🎉 本 题 已 经 被 你 解 决 啦"
</n-alert> >
</n-alert>
<!-- 尝试过但未通过 -->
<n-alert
class="status-alert"
v-else-if="hasTriedButNotPassed"
type="warning"
title="💪 你已经尝试过这道题,但还没有通过"
>
不要放弃仔细检查代码逻辑或者寻求 AI 的帮助获取灵感
</n-alert>
</template>
<!-- 尝试过但未通过 -->
<n-alert
class="status-alert"
v-else-if="hasTriedButNotPassed"
type="warning"
title="💪 你已经尝试过这道题,但还没有通过"
>
不要放弃仔细检查代码逻辑或者寻求 AI 的帮助获取灵感
</n-alert>
<n-flex align="center"> <n-flex align="center">
<n-tag>{{ problem._id }}</n-tag> <n-tag>{{ problem._id }}</n-tag>
<h2 class="problemTitle">{{ problem.title }}</h2> <h2 class="problemTitle">{{ problem.title }}</h2>

View File

@@ -130,13 +130,26 @@ watch(isMobile, (value) => {
> >
<ProblemFlowchart /> <ProblemFlowchart />
</n-tab-pane> </n-tab-pane>
<n-tab-pane name="info" tab="题目统计"> <n-tab-pane
name="info"
tab="题目统计"
:disabled="!!props.problemSetId"
>
<ProblemInfo /> <ProblemInfo />
</n-tab-pane> </n-tab-pane>
<n-tab-pane v-if="!props.contestID" name="comment" tab="题目点评"> <n-tab-pane
v-if="!props.contestID"
name="comment"
tab="题目点评"
:disabled="!!props.problemSetId"
>
<ProblemComment /> <ProblemComment />
</n-tab-pane> </n-tab-pane>
<n-tab-pane name="submission" tab="我的提交"> <n-tab-pane
name="submission"
tab="我的提交"
:disabled="!!props.problemSetId"
>
<ProblemSubmission /> <ProblemSubmission />
</n-tab-pane> </n-tab-pane>
</n-tabs> </n-tabs>
@@ -151,13 +164,22 @@ watch(isMobile, (value) => {
<n-tab-pane name="editor" tab="代码"> <n-tab-pane name="editor" tab="代码">
<component :is="inProblem ? ProblemEditor : ContestEditor" /> <component :is="inProblem ? ProblemEditor : ContestEditor" />
</n-tab-pane> </n-tab-pane>
<n-tab-pane name="info" tab="统计"> <n-tab-pane name="info" tab="统计" :disabled="!!props.problemSetId">
<ProblemInfo /> <ProblemInfo />
</n-tab-pane> </n-tab-pane>
<n-tab-pane v-if="!props.contestID" name="comment" tab="点评"> <n-tab-pane
v-if="!props.contestID"
name="comment"
tab="点评"
:disabled="!!props.problemSetId"
>
<ProblemComment /> <ProblemComment />
</n-tab-pane> </n-tab-pane>
<n-tab-pane name="submission" tab="提交"> <n-tab-pane
name="submission"
tab="提交"
:disabled="!!props.problemSetId"
>
<ProblemSubmission /> <ProblemSubmission />
</n-tab-pane> </n-tab-pane>
</n-tabs> </n-tabs>

View File

@@ -0,0 +1,106 @@
<script setup lang="ts">
import { Icon } from "@iconify/vue"
import { ProblemSet, UserBadge as UserBadgeType } from "utils/types"
import UserBadge from "shared/components/UserBadge.vue"
interface Props {
problemSet: ProblemSet
isJoined: boolean
isJoining: boolean
userBadges: UserBadgeType[]
}
interface Emits {
(e: 'join'): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
function getDifficultyTag(difficulty: string) {
const difficultyMap: Record<
string,
{ type: "success" | "warning" | "error" | "default"; text: string }
> = {
Easy: { type: "success", text: "简单" },
Medium: { type: "warning", text: "中等" },
Hard: { type: "error", text: "困难" },
}
return difficultyMap[difficulty] || { type: "default", text: "未知" }
}
function getProgressPercentage() {
if (!props.problemSet) return 0
return Math.round(
(props.problemSet.completed_count / props.problemSet.problems_count) * 100,
)
}
function handleJoin() {
emit('join')
}
</script>
<template>
<n-card style="margin-bottom: 24px;">
<n-flex justify="space-between" align="center">
<n-flex align="center">
<n-tag type="warning" v-if="problemSet.status === 'archived'">
已归档
</n-tag>
<n-tag :type="getDifficultyTag(problemSet.difficulty).type">
{{ getDifficultyTag(problemSet.difficulty).text }}
</n-tag>
<n-h2 style="margin: 0">{{ problemSet.title }}</n-h2>
<n-tooltip trigger="hover" v-if="problemSet.description">
<template #trigger>
<Icon width="20" icon="emojione:information" />
</template>
{{ problemSet.description }}
</n-tooltip>
</n-flex>
<n-flex align="center">
<!-- 用户徽章显示区域 - 只在已加入且有徽章时显示 -->
<n-flex v-if="isJoined && userBadges.length > 0" align="center">
<n-text>已获徽章</n-text>
<UserBadge
v-for="badge in userBadges"
:key="badge.id"
:badge="badge"
/>
</n-flex>
<!-- 完成进度 - 只在已加入时显示 -->
<n-flex align="center" v-if="isJoined">
<n-text strong>完成进度</n-text>
<n-text>
{{ problemSet.completed_count }} / {{ problemSet.problems_count }}
</n-text>
</n-flex>
<n-progress
v-if="isJoined"
:percentage="getProgressPercentage()"
:height="8"
:border-radius="4"
style="width: 200px"
/>
<n-button
v-if="!isJoined"
type="primary"
size="large"
:loading="isJoining"
@click="handleJoin"
>
加入题单
</n-button>
<n-tag v-else type="success" size="large">
<template #icon>
<Icon icon="material-symbols:check-circle" />
</template>
已加入
</n-tag>
</n-flex>
</n-flex>
</n-card>
</template>

View File

@@ -0,0 +1,81 @@
<script setup lang="ts">
import { Icon } from "@iconify/vue"
import { ProblemSetProblem } from "utils/types"
import { DIFFICULTY } from "utils/constants"
import { getTagColor } from "utils/functions"
import { useBreakpoints } from "shared/composables/breakpoints"
interface Props {
problems: ProblemSetProblem[]
isJoined: boolean
}
interface Emits {
(e: 'problem-click', problemId: string): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const { isDesktop } = useBreakpoints()
function handleProblemClick(problemId: string) {
emit('problem-click', problemId)
}
</script>
<template>
<div>
<n-grid :cols="isDesktop ? 4 : 1" :x-gap="16" :y-gap="16">
<n-grid-item
v-for="(problemSetProblem, index) in problems"
:key="problemSetProblem.id"
>
<n-card
hoverable
@click="handleProblemClick(problemSetProblem.problem._id)"
style="cursor: pointer"
>
<n-flex align="center">
<Icon
style="margin-right: 10px"
width="48"
icon="noto:check-mark-button"
v-if="problemSetProblem.is_completed"
/>
<n-flex vertical style="flex: 1">
<n-flex align="center">
<n-h4 style="margin: 0">#{{ index + 1 }}</n-h4>
<n-h4 style="margin: 0">
{{ problemSetProblem.problem.title }}
</n-h4>
</n-flex>
<n-flex align="center" size="small">
<n-tag
:type="getTagColor(problemSetProblem.problem.difficulty)"
size="small"
>
{{ DIFFICULTY[problemSetProblem.problem.difficulty] }}
</n-tag>
<n-text type="info">分数{{ problemSetProblem.score }}</n-text>
<n-text v-if="!problemSetProblem.is_required">选做</n-text>
</n-flex>
</n-flex>
</n-flex>
</n-card>
</n-grid-item>
</n-grid>
<div class="tip">
<n-text depth="3">题目完成后会自动返回题单页面</n-text>
</div>
</div>
</template>
<style scoped>
.tip {
padding-top: 24px;
text-align: center;
}
</style>

View File

@@ -0,0 +1,157 @@
<script setup lang="ts">
import { h, computed, ref, onMounted } from "vue"
import { Icon } from "@iconify/vue"
import { parseTime } from "utils/functions"
import { ProblemSetProgress } from "utils/types"
import { getProblemSetUserProgress } from "../../api"
import { NP, NProgress, NTag, useMessage } from "naive-ui"
const message = useMessage()
const route = useRoute()
const problemSetId = computed(() => Number(route.params.problemSetId))
const progress = ref<ProblemSetProgress[]>([])
const loading = ref(false)
// 加载用户进度数据
async function loadUserProgress() {
loading.value = true
try {
const res = await getProblemSetUserProgress(problemSetId.value)
progress.value = res.data
} catch (err: any) {
message.error("加载用户进度失败:" + (err.data || "未知错误"))
} finally {
loading.value = false
}
}
// 计算统计数据
const stats = computed(() => {
const total = progress.value.length
const completed = progress.value.filter((p) => p.is_completed).length
const avgProgress =
total > 0
? progress.value.reduce((sum, p) => sum + p.progress_percentage, 0) /
total
: 0
return {
total,
completed,
avgProgress: Math.round(avgProgress),
}
})
onMounted(loadUserProgress)
// 定义表格列
const progressColumns = [
{
title: "排名",
key: "rank",
width: 80,
render: (row: ProblemSetProgress, index: number) => index + 1,
},
{
title: "用户",
key: "user.username",
width: 120,
render: (row: ProblemSetProgress) => row.user.username,
},
{
title: "加入时间",
key: "join_time",
width: 180,
render: (row: ProblemSetProgress) =>
parseTime(row.join_time, "YYYY-MM-DD HH:mm:ss"),
},
{
title: "已完成数量",
key: "completed_problems_count",
width: 100,
},
{
title: "已完成题目",
key: "completed_problems",
width: 300,
render: (row: ProblemSetProgress) => {
return h("div", { style: "max-height: 120px; overflow-y: auto" }, [
h(
"div",
{ style: "display: flex; flex-wrap: wrap; gap: 4px" },
row.completed_problems.map((problem: any) =>
h(
NTag,
{
type: "success",
size: "small",
style: "margin: 2px",
},
`${problem._id}: ${problem.title}`,
),
),
),
])
},
},
{
title: "进度",
key: "progress_percentage",
width: 120,
render: (row: ProblemSetProgress) => {
return `${row.progress_percentage.toFixed(0)}%`
},
},
{
title: "状态",
key: "is_completed",
width: 100,
render: (row: ProblemSetProgress) => {
if (row.is_completed) {
return h(NTag, { type: "success" }, "已完成")
} else {
return h(NTag, { type: "warning" }, "进行中")
}
},
},
]
</script>
<template>
<div>
<n-flex justify="space-between" align="center" style="margin-bottom: 16px">
<n-h3 style="margin: 0">用户进度</n-h3>
<n-text depth="3"> {{ stats.total }} 人参与</n-text>
</n-flex>
<!-- 统计信息卡片 -->
<n-grid :cols="3" :x-gap="16" style="margin-bottom: 16px">
<n-grid-item>
<n-card size="small">
<n-statistic label="总参与人数" :value="stats.total" />
</n-card>
</n-grid-item>
<n-grid-item>
<n-card size="small">
<n-statistic label="已完成人数" :value="stats.completed" />
</n-card>
</n-grid-item>
<n-grid-item>
<n-card size="small">
<n-statistic label="平均进度" :value="stats.avgProgress.toFixed(0) + '%'" />
</n-card>
</n-grid-item>
</n-grid>
<n-data-table
:columns="progressColumns"
:data="progress"
:loading="loading"
:pagination="false"
:bordered="false"
:single-line="false"
/>
</div>
</template>

View File

@@ -1,28 +1,27 @@
<script setup lang="ts"> <script setup lang="ts">
import { Icon } from "@iconify/vue"
import { import {
getProblemSetDetail, getProblemSetDetail,
getProblemSetProblems, getProblemSetProblems,
joinProblemSet, joinProblemSet,
getUserBadges, getUserBadges,
} from "../api" } from "../api"
import { getTagColor } from "utils/functions"
import { import {
ProblemSet, ProblemSet,
ProblemSetProblem, ProblemSetProblem,
UserBadge as UserBadgeType, UserBadge as UserBadgeType,
} from "utils/types" } from "utils/types"
import { DIFFICULTY } from "utils/constants"
import { useBreakpoints } from "shared/composables/breakpoints"
import UserBadge from "shared/components/UserBadge.vue"
import { useFireworks } from "../problem/composables/useFireworks" import { useFireworks } from "../problem/composables/useFireworks"
import ProblemSetHeader from "./components/ProblemSetHeader.vue"
import ProblemSetProblemsList from "./components/ProblemSetProblemsList.vue"
import UserProgressView from "./components/UserProgressView.vue"
import { useUserStore } from "shared/store/user"
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
const message = useMessage() const message = useMessage()
const { isDesktop } = useBreakpoints()
const { celebrate } = useFireworks() const { celebrate } = useFireworks()
const userStore = useUserStore()
const problemSetId = computed(() => Number(route.params.problemSetId)) const problemSetId = computed(() => Number(route.params.problemSetId))
@@ -31,25 +30,7 @@ const problems = ref<ProblemSetProblem[]>([])
const isJoined = ref(false) const isJoined = ref(false)
const isJoining = ref(false) const isJoining = ref(false)
const userBadges = ref<UserBadgeType[]>([]) const userBadges = ref<UserBadgeType[]>([])
const activeTab = ref("problems")
function getDifficultyTag(difficulty: string) {
const difficultyMap: Record<
string,
{ type: "success" | "warning" | "error" | "default"; text: string }
> = {
Easy: { type: "success", text: "简单" },
Medium: { type: "warning", text: "中等" },
Hard: { type: "error", text: "困难" },
}
return difficultyMap[difficulty] || { type: "default", text: "未知" }
}
function getProgressPercentage() {
if (!problemSet.value) return 0
return Math.round(
(problemSet.value.completed_count / problemSet.value.problems_count) * 100,
)
}
async function loadProblemSetDetail() { async function loadProblemSetDetail() {
const res = await getProblemSetDetail(problemSetId.value) const res = await getProblemSetDetail(problemSetId.value)
@@ -112,123 +93,43 @@ async function handleJoinProblemSet() {
} }
} }
const showTabs = computed(
() =>
userStore.isSuperAdmin ||
(isJoined.value && problemSet.value?.user_progress?.is_completed),
)
onMounted(init) onMounted(init)
</script> </script>
<template> <template>
<div v-if="problemSet"> <div v-if="problemSet">
<n-card style="margin-bottom: 24px"> <ProblemSetHeader
<n-flex justify="space-between" align="center"> :problem-set="problemSet"
<n-flex align="center"> :is-joined="isJoined"
<n-tag type="warning" v-if="problemSet.status === 'archived'"> :is-joining="isJoining"
已归档 :user-badges="userBadges"
</n-tag> @join="handleJoinProblemSet"
<n-tag :type="getDifficultyTag(problemSet.difficulty).type"> />
{{ getDifficultyTag(problemSet.difficulty).text }} <n-tabs v-if="showTabs" v-model:value="activeTab" animated>
</n-tag> <n-tab-pane name="problems" tab="题目列表">
<n-h2 style="margin: 0">{{ problemSet.title }}</n-h2> <ProblemSetProblemsList
<n-tooltip trigger="hover" v-if="problemSet.description"> :problems="problems"
<template #trigger> :is-joined="isJoined"
<Icon width="20" icon="emojione:information" /> @problem-click="handleProblemClick"
</template> />
{{ problemSet.description }} </n-tab-pane>
</n-tooltip> <n-tab-pane name="progress" tab="用户进度">
</n-flex> <UserProgressView />
</n-tab-pane>
<n-flex align="center"> </n-tabs>
<!-- 用户徽章显示区域 - 只在已加入且有徽章时显示 --> <ProblemSetProblemsList
<n-flex v-if="isJoined && userBadges.length > 0" align="center"> v-else
<n-text>已获徽章</n-text> :problems="problems"
<UserBadge :is-joined="isJoined"
v-for="badge in userBadges" @problem-click="handleProblemClick"
:key="badge.id" />
:badge="badge"
/>
</n-flex>
<!-- 完成进度 - 只在已加入时显示 -->
<n-flex align="center" v-if="isJoined">
<n-text strong>完成进度</n-text>
<n-text>
{{ problemSet.completed_count }} / {{ problemSet.problems_count }}
</n-text>
</n-flex>
<n-progress
v-if="isJoined"
:percentage="getProgressPercentage()"
:height="8"
:border-radius="4"
style="width: 200px"
/>
<n-button
v-if="!isJoined"
type="primary"
size="large"
:loading="isJoining"
@click="handleJoinProblemSet"
>
加入题单
</n-button>
<n-tag v-else type="success" size="large">
<template #icon>
<Icon icon="material-symbols:check-circle" />
</template>
已加入
</n-tag>
</n-flex>
</n-flex>
</n-card>
<n-grid :cols="isDesktop ? 4 : 1" :x-gap="16" :y-gap="16">
<n-grid-item
v-for="(problemSetProblem, index) in problems"
:key="problemSetProblem.id"
>
<n-card
hoverable
@click="handleProblemClick(problemSetProblem.problem._id)"
style="cursor: pointer"
>
<n-flex align="center">
<Icon
style="margin-right: 10px"
width="48"
icon="noto:check-mark-button"
v-if="problemSetProblem.is_completed"
/>
<n-flex vertical style="flex: 1">
<n-flex align="center">
<n-h4 style="margin: 0">#{{ index + 1 }}</n-h4>
<n-h4 style="margin: 0">
{{ problemSetProblem.problem.title }}
</n-h4>
</n-flex>
<n-flex align="center" size="small">
<n-tag
:type="getTagColor(problemSetProblem.problem.difficulty)"
size="small"
>
{{ DIFFICULTY[problemSetProblem.problem.difficulty] }}
</n-tag>
<n-text type="info">分数{{ problemSetProblem.score }}</n-text>
<n-text v-if="!problemSetProblem.is_required">选做</n-text>
</n-flex>
</n-flex>
</n-flex>
</n-card>
</n-grid-item>
</n-grid>
<div class="tip">
<n-text>题目完成后会自动返回题单页面</n-text>
</div>
</div> </div>
</template> </template>
<style scoped> <style scoped></style>
.tip {
padding-top: 24px;
text-align: center;
}
</style>

View File

@@ -104,157 +104,154 @@ watch(
</script> </script>
<template> <template>
<div> <n-flex v-if="problemSets.length > 0" vertical size="large">
<n-flex vertical size="large"> <n-space>
<n-space> <n-space align="center">
<n-space align="center"> <n-text>难度</n-text>
<n-text>难度</n-text> <n-select
<n-select v-model:value="query.difficulty"
v-model:value="query.difficulty" :options="difficultyOptions"
:options="difficultyOptions" placeholder="选择难度"
placeholder="选择难度" style="width: 120px"
style="width: 120px"
clearable
/>
</n-space>
<n-space align="center">
<n-text>状态</n-text>
<n-select
v-model:value="query.status"
:options="statusOptions"
placeholder="选择状态"
style="width: 120px"
clearable
/>
</n-space>
<n-input
v-model:value="query.keyword"
placeholder="搜索题单..."
clearable clearable
@clear="clearQuery"
style="width: 200px"
/> />
</n-space> </n-space>
<n-space align="center">
<n-text>状态</n-text>
<n-select
v-model:value="query.status"
:options="statusOptions"
placeholder="选择状态"
style="width: 120px"
clearable
/>
</n-space>
<n-input
v-model:value="query.keyword"
placeholder="搜索题单..."
clearable
@clear="clearQuery"
style="width: 200px"
/>
</n-space>
<n-grid :cols="isDesktop ? 4 : 1" :x-gap="16" :y-gap="16"> <n-grid :cols="isDesktop ? 3 : 1" :x-gap="16" :y-gap="16">
<n-grid-item v-for="problemSet in problemSets" :key="problemSet.id"> <n-grid-item v-for="problemSet in problemSets" :key="problemSet.id">
<n-card <n-card
hoverable hoverable
@click="goToProblemSet(problemSet.id)" @click="goToProblemSet(problemSet.id)"
style="cursor: pointer" style="cursor: pointer"
> >
<template #header> <template #header>
<n-flex justify="space-between" align="center"> <n-flex justify="space-between" align="center">
<n-text strong>{{ problemSet.title }}</n-text> <n-text strong>{{ problemSet.title }}</n-text>
<n-tag :type="getDifficultyTag(problemSet.difficulty).type"> <n-tag :type="getDifficultyTag(problemSet.difficulty).type">
{{ getDifficultyTag(problemSet.difficulty).text }} {{ getDifficultyTag(problemSet.difficulty).text }}
</n-tag>
</n-flex>
</template>
<n-flex vertical size="large">
<n-flex justify="space-between" align="center">
<n-flex>
<Icon width="20" icon="streamline-emojis:blossom" />
<n-text>{{ problemSet.problems_count }} 道题目</n-text>
</n-flex>
<n-flex align="center" style="height: 28px">
<!-- 用户进度显示 -->
<n-progress
v-if="
problemSet.user_progress?.is_joined &&
!problemSet.user_progress?.is_completed
"
type="line"
:percentage="
Math.round(problemSet.user_progress.progress_percentage)
"
:height="4"
:border-radius="2"
style="width: 100px"
:color="
getProgressColor(
problemSet.user_progress.progress_percentage,
)
"
/>
<n-tag type="warning" v-if="problemSet.status === 'archived'">
已归档
</n-tag>
<n-tag
v-if="
problemSet.user_progress?.is_joined &&
!problemSet.user_progress?.is_completed
"
type="warning"
>
已加入
</n-tag>
<n-tag
v-if="problemSet.user_progress?.is_completed"
type="error"
>
已完成
</n-tag> </n-tag>
</n-flex> </n-flex>
</template>
<n-flex vertical size="large">
<n-flex justify="space-between" align="center">
<n-flex>
<Icon width="20" icon="streamline-emojis:blossom" />
<n-text>{{ problemSet.problems_count }} 道题目</n-text>
</n-flex>
<n-flex align="center" size="small">
<n-tag type="warning" v-if="problemSet.status === 'archived'">
已归档
</n-tag>
<n-tag
v-if="problemSet.user_progress?.is_joined"
type="success"
size="small"
>
<template #icon>
<Icon icon="material-symbols:check-circle" width="12" />
</template>
已加入
</n-tag>
</n-flex>
</n-flex>
<!-- 用户进度显示 -->
<div v-if="problemSet.user_progress?.is_joined">
<n-flex
align="center"
justify="space-between"
style="margin-bottom: 8px"
>
<n-text depth="3" style="font-size: 12px">
我的进度: {{ problemSet.user_progress.completed_count }} /
{{ problemSet.user_progress.total_count }}
</n-text>
<n-progress
type="line"
:percentage="
Math.round(problemSet.user_progress.progress_percentage)
"
:height="4"
:border-radius="2"
style="width: 100px"
:color="
getProgressColor(
problemSet.user_progress.progress_percentage,
)
"
/>
</n-flex>
</div>
<!-- 奖章显示 -->
<div v-if="problemSet.badges && problemSet.badges.length > 0">
<n-flex align="center" justify="space-between">
<n-text depth="3">
创建于
{{ parseTime(problemSet.create_time, "YYYY-MM-DD") }}
</n-text>
<n-flex>
<n-tooltip
v-for="badge in problemSet.badges"
:key="badge.id"
trigger="hover"
>
<template #trigger>
<n-image
:src="badge.icon"
:alt="badge.name"
width="24"
height="24"
object-fit="cover"
/>
</template>
<n-flex vertical size="small">
<span style="font-weight: bold"
>徽章: {{ badge.name }}</span
>
<span>
获取条件:
{{
getConditionText(
badge.condition_type,
badge.condition_value,
)
}}
</span>
</n-flex>
</n-tooltip>
</n-flex>
</n-flex>
</div>
</n-flex> </n-flex>
</n-card>
</n-grid-item>
</n-grid>
<Pagination <!-- 奖章显示 -->
:total="total" <n-flex
v-model:limit="query.limit" v-if="problemSet.badges && problemSet.badges.length > 0"
v-model:page="query.page" align="center"
/> justify="space-between"
</n-flex> >
</div> <n-text depth="3">
创建于
{{ parseTime(problemSet.create_time, "YYYY-MM-DD") }}
</n-text>
<n-flex>
<n-tooltip
v-for="badge in problemSet.badges"
:key="badge.id"
trigger="hover"
>
<template #trigger>
<n-image
:src="badge.icon"
:alt="badge.name"
width="24"
height="24"
object-fit="cover"
/>
</template>
<n-flex vertical size="small">
<span style="font-weight: bold">
徽章: {{ badge.name }}
</span>
<span>
获取条件:
{{
getConditionText(
badge.condition_type,
badge.condition_value,
)
}}
</span>
</n-flex>
</n-tooltip>
</n-flex>
</n-flex>
</n-flex>
</n-card>
</n-grid-item>
</n-grid>
<Pagination
:total="total"
v-model:limit="query.limit"
v-model:page="query.page"
/>
</n-flex>
<n-empty v-else></n-empty>
</template> </template>
<style scoped></style> <style scoped></style>

View File

@@ -58,8 +58,8 @@ function getConditionText() {
position: relative; position: relative;
display: inline-block; display: inline-block;
cursor: pointer; cursor: pointer;
width: 50px; width: 44px;
height: 50px; height: 44px;
} }
.badge-icon { .badge-icon {

View File

@@ -251,6 +251,12 @@ export interface UserBadge {
earned_time: Date earned_time: Date
} }
export interface CompletedProblem {
id: number
_id: string
title: string
}
export interface ProblemSetProgress { export interface ProblemSetProgress {
id: number id: number
problemset: ProblemSetList problemset: ProblemSetList
@@ -260,6 +266,7 @@ export interface ProblemSetProgress {
total_problems_count: number total_problems_count: number
progress_percentage: number progress_percentage: number
is_completed: boolean is_completed: boolean
completed_problems: CompletedProblem[]
} }
export interface CreateProblemSetData { export interface CreateProblemSetData {