refactor(reaction): 后台反馈统计独立成 reaction 目录,去掉排序、加最近评价时间
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -287,14 +287,9 @@ export function createAnnouncement(announcement: AnnouncementEdit) {
|
||||
return http.post("admin/announcement", announcement)
|
||||
}
|
||||
|
||||
export function getReactionStats(
|
||||
offset = 0,
|
||||
limit = 10,
|
||||
problem: string,
|
||||
ordering: string,
|
||||
) {
|
||||
export function getReactionStats(offset = 0, limit = 10, problem: string) {
|
||||
return http.get("admin/reaction", {
|
||||
params: { offset, limit, problem, ordering },
|
||||
params: { offset, limit, problem },
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,7 @@
|
||||
/>
|
||||
</div>
|
||||
</n-flex>
|
||||
<n-data-table
|
||||
striped
|
||||
:columns="columns"
|
||||
:data="rows"
|
||||
:scroll-x="1100"
|
||||
remote
|
||||
@update:sorter="handleSorter"
|
||||
/>
|
||||
<n-data-table striped :columns="columns" :data="rows" />
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:limit="query.limit"
|
||||
@@ -29,6 +22,7 @@ import { Icon } from "@iconify/vue"
|
||||
import { NButton, NFlex } from "naive-ui"
|
||||
import Pagination from "shared/components/Pagination.vue"
|
||||
import { REACTIONS } from "utils/constants"
|
||||
import { parseTime } from "utils/functions"
|
||||
import type { ReactionStatsRow } from "utils/types"
|
||||
import { getReactionStats } from "../api"
|
||||
|
||||
@@ -38,7 +32,6 @@ const query = reactive({
|
||||
limit: 10,
|
||||
page: 1,
|
||||
problem: "",
|
||||
ordering: "-users",
|
||||
})
|
||||
|
||||
const columns: DataTableColumn<ReactionStatsRow>[] = [
|
||||
@@ -58,8 +51,8 @@ const columns: DataTableColumn<ReactionStatsRow>[] = [
|
||||
() => row.pid,
|
||||
),
|
||||
},
|
||||
{ title: "标题", key: "title", minWidth: 180, ellipsis: true },
|
||||
{ title: "表态人数", key: "users", width: 110, sorter: true },
|
||||
{ title: "标题", key: "title", minWidth: 180 },
|
||||
{ title: "表态人数", key: "users", width: 120 },
|
||||
...REACTIONS.map((item) => ({
|
||||
title: () =>
|
||||
h(NFlex, { align: "center", size: 4, wrap: false }, () => [
|
||||
@@ -67,35 +60,25 @@ const columns: DataTableColumn<ReactionStatsRow>[] = [
|
||||
item.label,
|
||||
]),
|
||||
key: item.key,
|
||||
width: 110,
|
||||
sorter: true,
|
||||
width: 120,
|
||||
})),
|
||||
{
|
||||
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() {
|
||||
const offset = (query.page - 1) * query.limit
|
||||
const res = await getReactionStats(
|
||||
offset,
|
||||
query.limit,
|
||||
query.problem,
|
||||
query.ordering,
|
||||
)
|
||||
const res = await getReactionStats(offset, query.limit, query.problem)
|
||||
rows.value = res.data.results
|
||||
total.value = res.data.total
|
||||
}
|
||||
|
||||
onMounted(listStats)
|
||||
watch(() => [query.page, query.limit, query.ordering], listStats)
|
||||
watch(() => [query.page, query.limit], listStats)
|
||||
watchDebounced(() => query.problem, listStats, {
|
||||
debounce: 500,
|
||||
maxWait: 1000,
|
||||
@@ -260,7 +260,7 @@ export const admins: RouteRecordRaw = {
|
||||
{
|
||||
path: "reaction/list",
|
||||
name: "admin reaction list",
|
||||
component: () => import("admin/communication/reactions.vue"),
|
||||
component: () => import("admin/reaction/list.vue"),
|
||||
meta: { requiresSuperAdmin: true },
|
||||
},
|
||||
{
|
||||
|
||||
@@ -119,7 +119,7 @@ const options = computed<MenuOption[]>(() => {
|
||||
h(
|
||||
RouterLink,
|
||||
{ to: "/admin/reaction/list" },
|
||||
{ default: () => "题目反馈" },
|
||||
{ default: () => "反馈" },
|
||||
),
|
||||
key: "admin reaction list",
|
||||
},
|
||||
|
||||
@@ -614,6 +614,7 @@ export interface ReactionStatsRow extends ReactionCounts {
|
||||
pid: string
|
||||
title: string
|
||||
users: number
|
||||
last_time: string
|
||||
}
|
||||
|
||||
export interface Tutorial {
|
||||
|
||||
Reference in New Issue
Block a user