后台添加随机抽签
This commit is contained in:
@@ -16,6 +16,10 @@ export function getBaseInfo() {
|
|||||||
return http.get("admin/dashboard_info")
|
return http.get("admin/dashboard_info")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function randomUser10(classroom: string) {
|
||||||
|
return http.get("admin/random_user", { params: { classroom } })
|
||||||
|
}
|
||||||
|
|
||||||
export async function getProblemList(
|
export async function getProblemList(
|
||||||
offset = 0,
|
offset = 0,
|
||||||
limit = 10,
|
limit = 10,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Pagination from "~/shared/components/Pagination.vue"
|
|||||||
import { useUserStore } from "~/shared/store/user"
|
import { useUserStore } from "~/shared/store/user"
|
||||||
import { getACRate } from "~/utils/functions"
|
import { getACRate } from "~/utils/functions"
|
||||||
import { Rank } from "~/utils/types"
|
import { Rank } from "~/utils/types"
|
||||||
import { getBaseInfo } from "../api"
|
import { getBaseInfo, randomUser10 } from "../api"
|
||||||
|
|
||||||
const userCount = ref(0)
|
const userCount = ref(0)
|
||||||
const submissionCount = ref(0)
|
const submissionCount = ref(0)
|
||||||
@@ -13,12 +13,14 @@ const contestCount = ref(0)
|
|||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
const showModal = ref(false)
|
||||||
|
const luckyGuy = ref("")
|
||||||
const data = ref<Rank[]>([])
|
const data = ref<Rank[]>([])
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
limit: 10,
|
limit: 10,
|
||||||
page: 1,
|
page: 1,
|
||||||
username: "",
|
classroom: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
const columns: DataTableColumn<Rank>[] = [
|
const columns: DataTableColumn<Rank>[] = [
|
||||||
@@ -44,6 +46,7 @@ const columns: DataTableColumn<Rank>[] = [
|
|||||||
() => row.user.username,
|
() => row.user.username,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{ title: "个性签名", key: "mood" },
|
||||||
{ title: "已解决", key: "accepted_number", width: 100 },
|
{ title: "已解决", key: "accepted_number", width: 100 },
|
||||||
{ title: "提交数", key: "submission_number", width: 100 },
|
{ title: "提交数", key: "submission_number", width: 100 },
|
||||||
{
|
{
|
||||||
@@ -63,11 +66,22 @@ onMounted(async () => {
|
|||||||
|
|
||||||
async function listRanks() {
|
async function listRanks() {
|
||||||
const offset = (query.page - 1) * query.limit
|
const offset = (query.page - 1) * query.limit
|
||||||
const res = await getRank(offset, query.limit, 0, query.username)
|
const res = await getRank(offset, query.limit, 0, query.classroom)
|
||||||
data.value = res.data.results
|
data.value = res.data.results
|
||||||
total.value = res.data.total
|
total.value = res.data.total
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getRandom() {
|
||||||
|
const res = await randomUser10(query.classroom)
|
||||||
|
const name = res.data[res.data.length - 1]
|
||||||
|
luckyGuy.value = name.split(query.classroom)[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getRandomModal() {
|
||||||
|
showModal.value = true
|
||||||
|
getRandom()
|
||||||
|
}
|
||||||
|
|
||||||
watch(() => query.page, listRanks)
|
watch(() => query.page, listRanks)
|
||||||
watch(
|
watch(
|
||||||
() => query.limit,
|
() => query.limit,
|
||||||
@@ -76,6 +90,21 @@ watch(
|
|||||||
listRanks()
|
listRanks()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
watchDebounced(
|
||||||
|
() => query.classroom,
|
||||||
|
() => {
|
||||||
|
query.page = 1
|
||||||
|
listRanks()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
debounce: 500,
|
||||||
|
maxWait: 1000,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(showModal, (v) => {
|
||||||
|
if (!v) luckyGuy.value = ""
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -107,11 +136,12 @@ watch(
|
|||||||
style="width: 200px"
|
style="width: 200px"
|
||||||
clearable
|
clearable
|
||||||
@change="listRanks"
|
@change="listRanks"
|
||||||
v-model:value="query.username"
|
v-model:value="query.classroom"
|
||||||
placeholder="班级前缀"
|
placeholder="班级前缀"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<n-button @click="listRanks">用户排名</n-button>
|
<n-button @click="listRanks">用户排名</n-button>
|
||||||
|
<n-button @click="getRandomModal" v-if="query.classroom">随机抽签</n-button>
|
||||||
<Pagination
|
<Pagination
|
||||||
class="pagination"
|
class="pagination"
|
||||||
:total="total"
|
:total="total"
|
||||||
@@ -120,6 +150,17 @@ watch(
|
|||||||
/>
|
/>
|
||||||
</n-flex>
|
</n-flex>
|
||||||
<n-data-table v-if="data.length" striped :data="data" :columns="columns" />
|
<n-data-table v-if="data.length" striped :data="data" :columns="columns" />
|
||||||
|
<n-modal
|
||||||
|
preset="card"
|
||||||
|
title="猜猜看幸运儿是谁?"
|
||||||
|
v-model:show="showModal"
|
||||||
|
style="width: 400px"
|
||||||
|
>
|
||||||
|
<n-flex vertical justify="center" align="center">
|
||||||
|
<n-h1 class="lucky">{{ luckyGuy }}</n-h1>
|
||||||
|
<n-button block @click="getRandom">再来一次</n-button>
|
||||||
|
</n-flex>
|
||||||
|
</n-modal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -135,4 +176,8 @@ watch(
|
|||||||
.pagination {
|
.pagination {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lucky {
|
||||||
|
height: 48px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ const columns = computed(() => {
|
|||||||
<n-form-item>
|
<n-form-item>
|
||||||
<n-button @click="clear" quaternary>重置</n-button>
|
<n-button @click="clear" quaternary>重置</n-button>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item v-if="todayCount>0">
|
<n-form-item v-if="todayCount > 0">
|
||||||
<component :is="isDesktop ? NH2 : NText" class="todayCount">
|
<component :is="isDesktop ? NH2 : NText" class="todayCount">
|
||||||
<n-gradient-text>今日提交数:{{ todayCount }}</n-gradient-text>
|
<n-gradient-text>今日提交数:{{ todayCount }}</n-gradient-text>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
Reference in New Issue
Block a user