feat: 自动学习功能,后台定时发送心跳积累学时
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NInput, NInputNumber, NSwitch } from "naive-ui";
|
||||
import { NAlert, NButton, NInput, NInputNumber, NRadioButton, NRadioGroup, NSwitch } from "naive-ui";
|
||||
|
||||
const emit = defineEmits<{ saved: [] }>();
|
||||
|
||||
@@ -16,6 +16,10 @@ const attempts = ref<number | null>(null);
|
||||
const username = ref("");
|
||||
const password = ref("");
|
||||
const confirmPassword = ref("");
|
||||
const hbMode = ref("manual");
|
||||
const hbVideo = ref<number | null>(30);
|
||||
const hbDocument = ref<number | null>(120);
|
||||
const hbScorm = ref<number | null>(120);
|
||||
|
||||
const preferenceLabel = computed(() =>
|
||||
showManualJigsaw.value ? "默认勾选手动滑动验证码" : "先尝试自动滑动验证码",
|
||||
@@ -58,6 +62,10 @@ onMounted(async () => {
|
||||
showManualJigsaw.value = body.show_manual_jigsaw === true;
|
||||
manualPreference.value = body.manual_preference === true;
|
||||
username.value = body.admin_username;
|
||||
hbMode.value = typeof body.heartbeat_interval_mode === "string" ? body.heartbeat_interval_mode : "manual";
|
||||
hbVideo.value = readNumber(body.heartbeat_video_seconds) ?? 30;
|
||||
hbDocument.value = readNumber(body.heartbeat_document_seconds) ?? 120;
|
||||
hbScorm.value = readNumber(body.heartbeat_scorm_seconds) ?? 120;
|
||||
loaded.value = true;
|
||||
} catch {
|
||||
errorText.value = "系统配置没有获取到。";
|
||||
@@ -82,24 +90,35 @@ async function save() {
|
||||
errorText.value = "自动滑动次数须为 1 到 10 的整数";
|
||||
return;
|
||||
}
|
||||
if (hbMode.value === "manual") {
|
||||
if (invalidInteger(hbVideo.value, 10, 300)) {
|
||||
errorText.value = "视频心跳间隔须为 10 到 300 的整数";
|
||||
return;
|
||||
}
|
||||
if (invalidInteger(hbDocument.value, 30, 600)) {
|
||||
errorText.value = "文档心跳间隔须为 30 到 600 的整数";
|
||||
return;
|
||||
}
|
||||
if (invalidInteger(hbScorm.value, 30, 600)) {
|
||||
errorText.value = "Scorm 心跳间隔须为 30 到 600 的整数";
|
||||
return;
|
||||
}
|
||||
}
|
||||
const adminUsername = username.value.trim();
|
||||
if (!adminUsername) {
|
||||
errorText.value = "请填写管理员用户名";
|
||||
return;
|
||||
}
|
||||
const body: {
|
||||
refresh_interval_minutes: number;
|
||||
show_manual_jigsaw: boolean;
|
||||
manual_preference: boolean;
|
||||
auto_jigsaw_attempts: number;
|
||||
admin_username: string;
|
||||
admin_password?: string;
|
||||
} = {
|
||||
const body: Record<string, unknown> = {
|
||||
refresh_interval_minutes: refreshInterval.value as number,
|
||||
show_manual_jigsaw: showManualJigsaw.value,
|
||||
manual_preference: manualPreference.value,
|
||||
auto_jigsaw_attempts: attempts.value as number,
|
||||
admin_username: adminUsername,
|
||||
heartbeat_interval_mode: hbMode.value,
|
||||
heartbeat_video_seconds: hbVideo.value as number,
|
||||
heartbeat_document_seconds: hbDocument.value as number,
|
||||
heartbeat_scorm_seconds: hbScorm.value as number,
|
||||
};
|
||||
if (password.value !== "" || confirmPassword.value !== "") {
|
||||
if (password.value !== confirmPassword.value) {
|
||||
@@ -166,6 +185,39 @@ async function save() {
|
||||
<span class="setting-unit">次</span>
|
||||
</div>
|
||||
</div>
|
||||
<h3 class="form-section">自动学习心跳间隔</h3>
|
||||
<div class="form-row">
|
||||
<label>间隔来源</label>
|
||||
<n-radio-group v-model:value="hbMode" size="small">
|
||||
<n-radio-button value="auto">自动获取</n-radio-button>
|
||||
<n-radio-button value="manual">手动设定</n-radio-button>
|
||||
</n-radio-group>
|
||||
</div>
|
||||
<template v-if="hbMode === 'manual'">
|
||||
<div class="form-row">
|
||||
<label for="hb-video">视频</label>
|
||||
<div class="setting-control">
|
||||
<n-input-number id="hb-video" v-model:value="hbVideo" button-placement="both" :min="10" :max="300" :precision="0" />
|
||||
<span class="setting-unit">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="hb-document">文档</label>
|
||||
<div class="setting-control">
|
||||
<n-input-number id="hb-document" v-model:value="hbDocument" button-placement="both" :min="30" :max="600" :precision="0" />
|
||||
<span class="setting-unit">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="hb-scorm">Scorm</label>
|
||||
<div class="setting-control">
|
||||
<n-input-number id="hb-scorm" v-model:value="hbScorm" button-placement="both" :min="30" :max="600" :precision="0" />
|
||||
<span class="setting-unit">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<p v-else class="form-hint">自动获取:每次自动学习时从课程播放页在线读取间隔</p>
|
||||
<h3 class="form-section">管理员</h3>
|
||||
<div class="form-row">
|
||||
<label for="admin-username">管理员用户名</label>
|
||||
<n-input id="admin-username" v-model:value="username" autocomplete="username" />
|
||||
|
||||
Reference in New Issue
Block a user