123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <template>
- <div class="my-container" @dblclick="saveTaskToServer">
- <mark-header />
- <div class="flex gap-1">
- <mark-history />
- <mark-body />
- </div>
- </div>
- </template>
- <script lang="ts">
- import { defineComponent, onMounted, onUnmounted, watch } from "vue";
- import {
- clearMarkTask,
- getGroup,
- getSetting,
- getStatus,
- getTask,
- saveTask,
- updateUISetting,
- } from "@/api/markPage";
- import { store } from "./store";
- import MarkHeader from "./MarkHeader.vue";
- import MarkBody from "./MarkBody.vue";
- import { useTimers } from "@/setups/useTimers";
- import MarkHistory from "./MarkHistory.vue";
- export default defineComponent({
- name: "Mark",
- components: {
- MarkHeader,
- MarkBody,
- MarkHistory,
- },
- setup: () => {
- const { addInterval } = useTimers();
- async function updateMarkTask() {
- const settingRes = await clearMarkTask();
- }
- async function updateSetting() {
- const settingRes = await getSetting();
- settingRes.data.uiSetting["answer.paper.scale"] ||= 1;
- store.setting = settingRes.data;
- }
- async function updateStatus() {
- const res = await getStatus();
- store.status = res.data;
- }
- async function updateGroups() {
- const res = await getGroup();
- store.groups = res.data;
- }
- async function updateTask() {
- const res = await getTask();
- if (res.data.libraryId) {
- store.tasks.push(res.data);
- store.currentTask = store.tasks[0];
- }
- }
- // 5秒更新一次tasks
- addInterval(() => {
- // console.log("get task", store.tasks);
- if (store.tasks.length < 3) {
- updateTask();
- }
- }, 5 * 1000);
- addInterval(() => {
- updateStatus();
- }, 30 * 1000);
- onMounted(async () => {
- await updateMarkTask();
- updateSetting();
- updateStatus();
- updateGroups();
- updateTask();
- });
- watch(
- () => store.setting.uiSetting,
- () => {
- updateUISetting(undefined, store.setting.uiSetting);
- },
- { deep: true }
- );
- const saveTaskToServer = async () => {
- console.log("save task to server");
- const res = (await saveTask()) as any;
- updateStatus();
- if (res.data.success && store.currentTask) {
- let { libraryId, studentId } = store.currentTask;
- const i = store.markResults.findIndex(
- (s) => s.libraryId === libraryId && s.studentId === studentId
- );
- store.markResults.splice(i, 1);
- store.currentTask = undefined;
- store.tasks.shift();
- } else {
- console.log(res.data.message);
- }
- };
- function scoreKeyInput(event: KeyboardEvent) {
- console.log(event);
- }
- onMounted(() => {
- document.addEventListener("keypress", scoreKeyInput);
- });
- onUnmounted(() => {
- document.removeEventListener("keypress", scoreKeyInput);
- });
- return { store, saveTaskToServer, scoreKeyInput };
- },
- });
- </script>
- <style scoped>
- .my-container {
- width: 100%;
- }
- a {
- color: #42b983;
- }
- label {
- margin: 0 0.5em;
- font-weight: bold;
- }
- code {
- background-color: #eee;
- padding: 2px 4px;
- border-radius: 4px;
- color: #304455;
- }
- </style>
|