refactor(reaction): 后台反馈统计独立成 reaction 目录,去掉排序、加最近评价时间

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-06 06:15:34 -06:00
parent b3d0c3fcc7
commit 1fb93e6b16
5 changed files with 18 additions and 39 deletions

View File

@@ -287,14 +287,9 @@ export function createAnnouncement(announcement: AnnouncementEdit) {
return http.post("admin/announcement", announcement) return http.post("admin/announcement", announcement)
} }
export function getReactionStats( export function getReactionStats(offset = 0, limit = 10, problem: string) {
offset = 0,
limit = 10,
problem: string,
ordering: string,
) {
return http.get("admin/reaction", { return http.get("admin/reaction", {
params: { offset, limit, problem, ordering }, params: { offset, limit, problem },
}) })
} }

View File

@@ -9,14 +9,7 @@
/> />
</div> </div>
</n-flex> </n-flex>
<n-data-table <n-data-table striped :columns="columns" :data="rows" />
striped
:columns="columns"
:data="rows"
:scroll-x="1100"
remote
@update:sorter="handleSorter"
/>
<Pagination <Pagination
:total="total" :total="total"
v-model:limit="query.limit" v-model:limit="query.limit"
@@ -29,6 +22,7 @@ import { Icon } from "@iconify/vue"
import { NButton, NFlex } from "naive-ui" import { NButton, NFlex } from "naive-ui"
import Pagination from "shared/components/Pagination.vue" import Pagination from "shared/components/Pagination.vue"
import { REACTIONS } from "utils/constants" import { REACTIONS } from "utils/constants"
import { parseTime } from "utils/functions"
import type { ReactionStatsRow } from "utils/types" import type { ReactionStatsRow } from "utils/types"
import { getReactionStats } from "../api" import { getReactionStats } from "../api"
@@ -38,7 +32,6 @@ const query = reactive({
limit: 10, limit: 10,
page: 1, page: 1,
problem: "", problem: "",
ordering: "-users",
}) })
const columns: DataTableColumn<ReactionStatsRow>[] = [ const columns: DataTableColumn<ReactionStatsRow>[] = [
@@ -58,8 +51,8 @@ const columns: DataTableColumn<ReactionStatsRow>[] = [
() => row.pid, () => row.pid,
), ),
}, },
{ title: "标题", key: "title", minWidth: 180, ellipsis: true }, { title: "标题", key: "title", minWidth: 180 },
{ title: "表态人数", key: "users", width: 110, sorter: true }, { title: "表态人数", key: "users", width: 120 },
...REACTIONS.map((item) => ({ ...REACTIONS.map((item) => ({
title: () => title: () =>
h(NFlex, { align: "center", size: 4, wrap: false }, () => [ h(NFlex, { align: "center", size: 4, wrap: false }, () => [
@@ -67,35 +60,25 @@ const columns: DataTableColumn<ReactionStatsRow>[] = [
item.label, item.label,
]), ]),
key: item.key, key: item.key,
width: 110, width: 120,
sorter: true,
})), })),
{
title: "时间",
key: "last_time",
width: 180,
render: (row) => parseTime(row.last_time, "YYYY-MM-DD HH:mm:ss"),
},
] ]
function handleSorter(sorter: { columnKey: string; order: string | false }) {
if (!sorter || !sorter.order) {
query.ordering = "-users"
} else {
query.ordering =
(sorter.order === "descend" ? "-" : "") + String(sorter.columnKey)
}
query.page = 1
}
async function listStats() { async function listStats() {
const offset = (query.page - 1) * query.limit const offset = (query.page - 1) * query.limit
const res = await getReactionStats( const res = await getReactionStats(offset, query.limit, query.problem)
offset,
query.limit,
query.problem,
query.ordering,
)
rows.value = res.data.results rows.value = res.data.results
total.value = res.data.total total.value = res.data.total
} }
onMounted(listStats) onMounted(listStats)
watch(() => [query.page, query.limit, query.ordering], listStats) watch(() => [query.page, query.limit], listStats)
watchDebounced(() => query.problem, listStats, { watchDebounced(() => query.problem, listStats, {
debounce: 500, debounce: 500,
maxWait: 1000, maxWait: 1000,

View File

@@ -260,7 +260,7 @@ export const admins: RouteRecordRaw = {
{ {
path: "reaction/list", path: "reaction/list",
name: "admin reaction list", name: "admin reaction list",
component: () => import("admin/communication/reactions.vue"), component: () => import("admin/reaction/list.vue"),
meta: { requiresSuperAdmin: true }, meta: { requiresSuperAdmin: true },
}, },
{ {

View File

@@ -119,7 +119,7 @@ const options = computed<MenuOption[]>(() => {
h( h(
RouterLink, RouterLink,
{ to: "/admin/reaction/list" }, { to: "/admin/reaction/list" },
{ default: () => "题目反馈" }, { default: () => "反馈" },
), ),
key: "admin reaction list", key: "admin reaction list",
}, },

View File

@@ -614,6 +614,7 @@ export interface ReactionStatsRow extends ReactionCounts {
pid: string pid: string
title: string title: string
users: number users: number
last_time: string
} }
export interface Tutorial { export interface Tutorial {