add messages
This commit is contained in:
@@ -170,10 +170,22 @@ export function updateProfile(data: { real_name: string; mood: string }) {
|
||||
return http.put("profile", data)
|
||||
}
|
||||
|
||||
export function getAnnouncementList(offset = 10, limit = 10) {
|
||||
export function getAnnouncementList(offset = 0, limit = 10) {
|
||||
return http.get("announcement", { params: { limit, offset } })
|
||||
}
|
||||
|
||||
export function getAnnouncement(id: number) {
|
||||
return http.get("announcement", { params: { id } })
|
||||
}
|
||||
|
||||
export function createMessage(data: {
|
||||
recipient: number
|
||||
message: string
|
||||
submission: string
|
||||
}) {
|
||||
return http.post("message", data)
|
||||
}
|
||||
|
||||
export function getMessageList(offset = 0, limit = 10) {
|
||||
return http.get("message", { params: { limit, offset } })
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { getSubmission } from "oj/api"
|
||||
import { createMessage, getSubmission } from "oj/api"
|
||||
import { Submission } from "utils/types"
|
||||
import { JUDGE_STATUS, LANGUAGE_FORMAT_VALUE } from "utils/constants"
|
||||
import {
|
||||
@@ -9,17 +9,34 @@ import {
|
||||
} from "utils/functions"
|
||||
import copy from "copy-text-to-clipboard"
|
||||
import SubmissionResultTag from "~/shared/components/SubmissionResultTag.vue"
|
||||
import { useUserStore } from "~/shared/store/user"
|
||||
|
||||
const TextEditor = defineAsyncComponent(
|
||||
() => import("~/shared/components/TextEditor.vue"),
|
||||
)
|
||||
|
||||
const props = defineProps<{
|
||||
submissionID: string
|
||||
submission?: Submission
|
||||
hideList?: boolean
|
||||
}>()
|
||||
|
||||
const userStore = useUserStore()
|
||||
const systemMessage = useMessage()
|
||||
const submission = ref<Submission>()
|
||||
const message = ref<string>("")
|
||||
const [copied, toggle] = useToggle()
|
||||
const [showBox, toggleBox] = useToggle()
|
||||
const { start } = useTimeoutFn(() => toggle(false), 1000, { immediate: false })
|
||||
|
||||
const canWriteMessage = computed(
|
||||
() =>
|
||||
userStore.isSuperAdmin && userStore.user!.id !== submission.value?.user_id,
|
||||
)
|
||||
|
||||
async function init() {
|
||||
submission.value = props.submission
|
||||
if (submission.value) return
|
||||
const res = await getSubmission(props.submissionID)
|
||||
submission.value = res.data
|
||||
}
|
||||
@@ -30,6 +47,18 @@ function handleCopy(v: string) {
|
||||
start()
|
||||
}
|
||||
|
||||
async function sendMessage() {
|
||||
if (!message.value || message.value === "<p><br></p>") return
|
||||
const data = {
|
||||
message: message.value,
|
||||
recipient: submission.value!.user_id,
|
||||
submission: submission.value!.id,
|
||||
}
|
||||
await createMessage(data)
|
||||
systemMessage.success("消息发送成功")
|
||||
message.value = ""
|
||||
}
|
||||
|
||||
const columns: DataTableColumn<Submission["info"]["data"][number]>[] = [
|
||||
{ title: "测试用例", key: "test_case" },
|
||||
{
|
||||
@@ -72,13 +101,22 @@ onMounted(init)
|
||||
show-line-numbers
|
||||
/>
|
||||
</n-card>
|
||||
<n-button
|
||||
v-if="!hideList"
|
||||
type="primary"
|
||||
@click="handleCopy(submission!.code)"
|
||||
>
|
||||
{{ copied ? "成功复制" : "复制代码" }}
|
||||
</n-button>
|
||||
<n-flex>
|
||||
<n-button v-if="!hideList" @click="handleCopy(submission!.code)">
|
||||
{{ copied ? "成功复制" : "复制代码" }}
|
||||
</n-button>
|
||||
<n-button v-if="canWriteMessage" @click="toggleBox(!showBox)">
|
||||
{{ showBox ? "关闭" : "打开" }}文本框
|
||||
</n-button>
|
||||
<n-button v-if="canWriteMessage" @click="sendMessage">发送消息</n-button>
|
||||
</n-flex>
|
||||
<TextEditor
|
||||
title=""
|
||||
simple
|
||||
v-if="showBox && canWriteMessage"
|
||||
v-model:value="message"
|
||||
:min-height="200"
|
||||
/>
|
||||
<n-data-table
|
||||
v-if="!hideList && submission.info && submission.info.data"
|
||||
:columns="columns"
|
||||
|
||||
74
src/oj/user/message.vue
Normal file
74
src/oj/user/message.vue
Normal file
@@ -0,0 +1,74 @@
|
||||
<template>
|
||||
<n-list v-if="messages.length">
|
||||
<n-list-item
|
||||
:style="{ overflow: 'auto' }"
|
||||
v-for="(item, index) in messages"
|
||||
:key="index"
|
||||
>
|
||||
<n-flex size="large" vertical>
|
||||
<n-flex align="center">
|
||||
<div>发送时间</div>
|
||||
<div>{{ parseTime(item.create_time, "YYYY年M月D日 HH:mm:ss") }}</div>
|
||||
<div>发送者</div>
|
||||
<div>{{ item.sender.username }}</div>
|
||||
</n-flex>
|
||||
<n-flex align="center">
|
||||
<div>题目序号</div>
|
||||
<n-button
|
||||
text
|
||||
type="info"
|
||||
@click="router.push('/problem/' + item.submission.problem)"
|
||||
>
|
||||
{{ item.submission.problem }}
|
||||
</n-button>
|
||||
<n-tag
|
||||
:bordered="false"
|
||||
:type="JUDGE_STATUS[item.submission.result]['type']"
|
||||
>
|
||||
{{ JUDGE_STATUS[item.submission.result]["name"] }}
|
||||
</n-tag>
|
||||
<Copy :value="item.submission.code" />
|
||||
</n-flex>
|
||||
<n-code
|
||||
:language="LANGUAGE_FORMAT_VALUE[item.submission.language]"
|
||||
:code="item.submission.code"
|
||||
show-line-numbers
|
||||
/>
|
||||
<div v-html="item.message"></div>
|
||||
</n-flex>
|
||||
</n-list-item>
|
||||
</n-list>
|
||||
<n-empty v-else description="没有消息"></n-empty>
|
||||
<Pagination
|
||||
v-model:limit="query.limit"
|
||||
v-model:page="query.page"
|
||||
:total="total"
|
||||
/>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { getMessageList } from "oj/api"
|
||||
import { Message } from "~/utils/types"
|
||||
import { parseTime } from "~/utils/functions"
|
||||
import { LANGUAGE_FORMAT_VALUE, JUDGE_STATUS } from "utils/constants"
|
||||
import Pagination from "~/shared/components/Pagination.vue"
|
||||
import Copy from "~/shared/components/Copy.vue"
|
||||
|
||||
const router = useRouter()
|
||||
const messages = ref<Message[]>([])
|
||||
const total = ref(0)
|
||||
|
||||
const query = reactive({
|
||||
limit: 10,
|
||||
page: 1,
|
||||
})
|
||||
|
||||
async function listMessages() {
|
||||
const offset = (query.page - 1) * query.limit
|
||||
const res = await getMessageList(offset, query.limit)
|
||||
total.value = res.data.total
|
||||
messages.value = res.data.results
|
||||
}
|
||||
|
||||
onMounted(listMessages)
|
||||
watch(query, listMessages, { deep: true })
|
||||
</script>
|
||||
Reference in New Issue
Block a user