补上家长选班、巡课多画面、找回密码和管理端的节次与安全设置。

This commit is contained in:
itxiaohui committed 2026-11-21 12:44:52 +08:00
1 parent 339641040e
commit 0afc29d431
17 files changed
+381 -113

No files matched your search

+1
View File
@@ -5,6 +5,7 @@ export const router = createRouter({
history: createWebHistory(),
routes: [
{ path: "/login", component: () => import("../views/Login.vue") },
{ path: "/forgot", component: () => import("../views/Forgot.vue") },
{ path: "/register", component: () => import("../views/Register.vue") },
{ path: "/", component: () => import("../views/Home.vue") },
{ path: "/studio", component: () => import("../views/Studio.vue"), meta: { auth: true } },
+68
View File
@@ -254,6 +254,46 @@
<el-table-column prop="ip" label="IP" />
</el-table>
</el-tab-pane>
<el-tab-pane label="节次" name="periods">
<el-form inline @submit.prevent="createPeriod">
<el-input v-model.number="periodForm.schoolId" placeholder="学校 ID" />
<el-input v-model="periodForm.name" placeholder="节次名称" />
<el-input v-model="periodForm.startTime" placeholder="08:00" />
<el-input v-model="periodForm.endTime" placeholder="08:40" />
<el-button native-type="submit" type="primary">新增节次</el-button>
<el-button @click="loadPeriods">查询</el-button>
</el-form>
<el-table :data="periods" empty-text="没有节次">
<el-table-column prop="id" label="ID" width="70" />
<el-table-column prop="name" label="名称" />
<el-table-column prop="startTime" label="开始" />
<el-table-column prop="endTime" label="结束" />
</el-table>
</el-tab-pane>
<el-tab-pane label="通知模板" name="templates">
<el-table :data="templates" empty-text="没有模板">
<el-table-column prop="code" label="编码" />
<el-table-column prop="channel" label="渠道" />
<el-table-column prop="subject" label="标题" />
<el-table-column label="正文">
<template #default="{ row }">
<el-input v-model="row.body" type="textarea" />
<el-button link @click="saveTemplate(row)">保存</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="安全" name="security">
<el-form label-width="140px" style="max-width: 480px">
<el-form-item label="密码最短"><el-input v-model="securityForm['sec.password.min']" /></el-form-item>
<el-form-item label="必须字母加数字"><el-switch v-model="passwordMix" /></el-form-item>
<el-form-item label="失败锁定次数"><el-input v-model="securityForm['sec.login.maxFail']" /></el-form-item>
<el-form-item label="锁定分钟"><el-input v-model="securityForm['sec.login.lockMinutes']" /></el-form-item>
<el-form-item label="最长直播分钟"><el-input v-model="securityForm['live.maxMinutes']" /></el-form-item>
<el-form-item label="断线秒数"><el-input v-model="securityForm['live.disconnectSeconds']" /></el-form-item>
<el-button type="primary" @click="saveSecurity">保存</el-button>
</el-form>
</el-tab-pane>
<el-tab-pane label="状态" name="status">
<p>每 5 秒刷新。直播数来自数据库,服务探测来自实际连接。</p>
<ul>
@@ -294,6 +334,8 @@ const entries = ref<any[]>([]);
const lives = ref<any[]>([]);
const records = ref<any[]>([]);
const inspections = ref<any[]>([]);
const periods = ref<any[]>([]);
const templates = ref<any[]>([]);
const audits = ref<any[]>([]);
const loginLogs = ref<any[]>([]);
const usage = ref({ bytes: 0, failed: 0 });
@@ -312,6 +354,9 @@ const assignForm = reactive({ classId: undefined as number | undefined, teacherI
const courseForm = reactive({ classId: undefined as number | undefined, teacherId: undefined as number | undefined, name: "" });
const entryForm = reactive({ classId: undefined as number | undefined, courseId: undefined as number | undefined, periodId: undefined as number | undefined, weekday: 1 });
const inspectForm = reactive({ classId: undefined as number | undefined, situation: "", disciplineNote: "" });
const periodForm = reactive({ schoolId: undefined as number | undefined, name: "", startTime: "08:00", endTime: "08:40" });
const securityForm = reactive<Record<string, string>>({ "sec.password.min": "8", "sec.login.maxFail": "5", "sec.login.lockMinutes": "15", "live.maxMinutes": "120", "live.disconnectSeconds": "60" });
const passwordMix = ref(true);
const smtp = reactive({ host: "", port: 465, username: "", password: "", fromAddress: "", fromName: "", enabled: false, sslEnabled: true, starttls: true });
const sms = reactive({ provider: "simulated", signName: "", templateId: "", accessKey: "", secret: "", enabled: false, apiUrl: "", region: "", sdkAppId: "" });
const siteForm = reactive<Record<string, string>>({ "site.name.zh": "", "site.name.en": "", "site.title": "", "site.intro": "", "site.announcement": "", "site.footer": "", "site.theme.color": "#1677ff" });
@@ -353,6 +398,13 @@ async function refresh() {
audits.value = (await http.get("/admin/audits")).data.data.items;
loginLogs.value = (await http.get("/admin/login-logs")).data.data.items;
}
if (tab.value === "periods" && periodForm.schoolId) await loadPeriods();
if (tab.value === "templates") templates.value = (await http.get("/admin/templates")).data.data;
if (tab.value === "security") {
const settings = (await http.get("/admin/settings")).data.data;
Object.assign(securityForm, settings);
passwordMix.value = settings["sec.password.mix"] !== "false";
}
if (tab.value === "status") status.value = (await http.get("/admin/status")).data.data;
} catch (err) {
fail(err);
@@ -398,6 +450,22 @@ async function createInspection() {
async function saveSmtp() { await http.put("/admin/smtp", smtp); message.value = "邮件设置已保存"; }
async function testSmtp() { await http.post("/admin/smtp/test", { to: smtpTest.value }); message.value = "测试邮件已提交"; }
async function saveSms() { await http.put("/admin/sms", sms); message.value = "短信设置已保存"; }
async function loadPeriods() {
periods.value = (await http.get("/periods", { params: { schoolId: periodForm.schoolId } })).data.data;
}
async function createPeriod() {
await http.post("/periods", { ...periodForm, sortOrder: periods.value.length + 1 });
message.value = "节次已创建";
await loadPeriods();
}
async function saveTemplate(row: { code: string; channel: string; subject: string; body: string }) {
await http.put("/admin/templates", row);
message.value = "模板已保存";
}
async function saveSecurity() {
await http.put("/admin/settings", { ...securityForm, "sec.password.mix": String(passwordMix.value) });
message.value = "安全设置已保存";
}
async function saveSite() {
await http.put("/admin/settings", { ...siteForm, "reg.enabled": String(registration.value), "reg.emailVerify": String(emailVerify.value), "reg.smsVerify": String(smsVerify.value), "reg.requireApproval": String(requireApproval.value) });
await site.load();
+55
View File
@@ -0,0 +1,55 @@
<template>
<div class="page" style="max-width: 420px">
<div class="card">
<h1>找回密码</h1>
<el-form @submit.prevent="send">
<el-input v-model="target" placeholder="邮箱或手机号" />
<el-button native-type="submit" :loading="sending">发送验证码</el-button>
</el-form>
<p v-if="hint">{{ hint }}</p>
<el-form @submit.prevent="reset">
<el-input v-model="code" placeholder="验证码" />
<el-input v-model="password" type="password" placeholder="新密码" show-password />
<el-button type="primary" native-type="submit">重置密码</el-button>
</el-form>
<p><router-link to="/login">返回登录</router-link></p>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { useRouter } from "vue-router";
import { http } from "../api/http";
const router = useRouter();
const target = ref("");
const code = ref("");
const password = ref("");
const hint = ref("");
const sending = ref(false);
async function send() {
sending.value = true;
hint.value = "";
try {
const { data } = await http.post("/auth/forgot-password", { target: target.value, purpose: "RESET" });
hint.value = data.data.debugCode ? `开发环境验证码 ${data.data.debugCode}` : "如果账号存在,验证码已发出";
} catch (err: unknown) {
hint.value = (err as { response?: { data?: { message?: string } } }).response?.data?.message ?? "发送失败";
} finally {
sending.value = false;
}
}
async function reset() {
hint.value = "";
try {
await http.post("/auth/reset-password", { target: target.value, code: code.value, password: password.value });
hint.value = "密码已重置";
await router.push("/login");
} catch (err: unknown) {
hint.value = (err as { response?: { data?: { message?: string } } }).response?.data?.message ?? "重置失败";
}
}
</script>
+49 -8
View File
@@ -8,10 +8,10 @@
<router-link v-if="!auth.user" to="/login">登录</router-link>
<template v-else>
<span>{{ auth.user.displayName }}</span>
<router-link to="/studio">教室</router-link>
<router-link to="/inspect">巡课</router-link>
<router-link v-if="auth.isTeacher || auth.roles.includes('SUPER_ADMIN')" to="/studio">教室</router-link>
<router-link v-if="auth.isStaff" to="/inspect">巡课</router-link>
<router-link to="/replays">回放</router-link>
<router-link to="/admin">管理</router-link>
<router-link v-if="auth.isStaff" to="/admin">管理</router-link>
<el-button link @click="auth.logout()">退出</el-button>
</template>
</nav>
@@ -23,7 +23,7 @@
<p v-else-if="bindings.length === 0 && lives.length === 0">暂无绑定或直播</p>
<ul>
<li v-for="item in bindings" :key="item.id">
班级 {{ item.classId }} · {{ item.status }} · 直播 {{ item.liveGranted ? "已授权" : "未授权" }} · 回放 {{ item.replayGranted ? "已授权" : "未授权" }}
{{ className(item.classId) }} · {{ item.status }} · 直播 {{ item.liveGranted ? "已授权" : "未授权" }} · 回放 {{ item.replayGranted ? "已授权" : "未授权" }}
</li>
</ul>
<ul>
@@ -32,13 +32,23 @@
</li>
</ul>
<el-form v-if="auth.isParent" @submit.prevent="bind">
<el-input v-model.number="form.classId" placeholder="班级 ID" />
<el-select v-model="form.classId" placeholder="选择班级" filterable style="width: 100%">
<el-option v-for="item in classes" :key="item.id" :label="`${item.schoolName} ${item.name}`" :value="item.id" />
</el-select>
<el-input v-model="form.studentNo" placeholder="学号" />
<el-input v-model="form.studentName" placeholder="学生姓名" />
<el-input v-model="form.relationship" placeholder="关系,例如父亲" />
<el-checkbox v-model="form.requestLive">申请直播</el-checkbox>
<el-checkbox v-model="form.requestReplay">申请回放</el-checkbox>
<el-button native-type="submit" type="primary">提交绑定</el-button>
<p v-if="bindMessage">{{ bindMessage }}</p>
</el-form>
<el-form style="margin-top: 16px" @submit.prevent="changePassword">
<h3>修改密码</h3>
<el-input v-model="password.oldPassword" type="password" placeholder="当前密码" show-password />
<el-input v-model="password.newPassword" type="password" placeholder="新密码" show-password />
<el-button native-type="submit">保存密码</el-button>
<p v-if="passwordMessage">{{ passwordMessage }}</p>
</el-form>
</section>
<p>{{ site.footer }}</p>
@@ -57,7 +67,15 @@ const bindings = ref<Array<{ id: number; classId: number; status: string; liveGr
const lives = ref<Array<{ id: number; roomName: string; status: string }>>([]);
const loading = ref(false);
const error = ref("");
const classes = ref<Array<{ id: number; name: string; schoolName: string }>>([]);
const form = reactive({ classId: undefined as number | undefined, studentNo: "", studentName: "", relationship: "家长", requestLive: true, requestReplay: true });
const bindMessage = ref("");
const password = reactive({ oldPassword: "", newPassword: "" });
const passwordMessage = ref("");
function className(id: number) {
return classes.value.find((item) => item.id === id)?.name ?? `班级 ${id}`;
}
async function load() {
if (!auth.user) return;
@@ -74,9 +92,32 @@ async function load() {
}
async function bind() {
await http.post("/bindings", form);
await load();
bindMessage.value = "";
try {
await http.post("/bindings", form);
bindMessage.value = "已提交,等待管理员分别审核直播和回放";
await load();
} catch (err: unknown) {
bindMessage.value = (err as { response?: { data?: { message?: string } } }).response?.data?.message ?? "提交失败";
}
}
onMounted(load);
async function changePassword() {
passwordMessage.value = "";
try {
await http.put("/auth/password", password);
passwordMessage.value = "密码已更新,其他设备需要重新登录";
password.oldPassword = "";
password.newPassword = "";
} catch (err: unknown) {
passwordMessage.value = (err as { response?: { data?: { message?: string } } }).response?.data?.message ?? "修改失败";
}
}
onMounted(async () => {
if (auth.user) {
classes.value = (await http.get("/directory/classes")).data.data;
}
await load();
});
</script>
+47 -19
View File
@@ -3,15 +3,16 @@
<h2>巡课</h2>
<p>多个教室同时预览时默认静音。点开一间后才播放该教室声音。</p>
<p v-if="loading">加载中</p>
<p v-else-if="error">{{ error }}</p>
<p v-else-if="rooms.length === 0">当前没有直播</p>
<div class="grid-2">
<article class="card" v-for="room in rooms" :key="room.id">
<h3>班级 {{ room.classId }}</h3>
<p>{{ room.status }} · {{ room.roomName }}</p>
<el-button @click="focus(room.id)">只听这一间</el-button>
<article class="card" v-for="item in rooms" :key="item.id">
<h3>班级 {{ item.classId }}</h3>
<p>{{ item.status }} · {{ item.roomName }}</p>
<video :ref="(el) => keep(item.id, el)" autoplay muted playsinline style="width: 100%; background: #111"></video>
<el-button class="touch" @click="focus(item.id)">{{ focused === item.id ? "正在收听" : "只听这一间" }}</el-button>
</article>
</div>
<video v-show="active" ref="videoEl" autoplay playsinline style="width: 100%"></video>
</div>
</template>
@@ -22,28 +23,55 @@ import { http } from "../api/http";
const rooms = ref<Array<{ id: number; classId: number; status: string; roomName: string }>>([]);
const loading = ref(true);
const active = ref(false);
const videoEl = ref<HTMLVideoElement | null>(null);
let room: Room | undefined;
const error = ref("");
const focused = ref<number | null>(null);
const videos = new Map<number, HTMLVideoElement>();
const connections = new Map<number, Room>();
async function load() {
const { data } = await http.get("/live/sessions", { params: { status: "LIVE" } });
rooms.value = data.data.items;
loading.value = false;
function keep(id: number, el: unknown) {
if (el instanceof HTMLVideoElement) videos.set(id, el);
}
async function focus(id: number) {
room?.disconnect();
async function connect(id: number) {
const video = videos.get(id);
if (!video || connections.has(id)) return;
const { data } = await http.post(`/live/sessions/${id}/token`, { publish: false });
room = new Room();
const room = new Room();
room.on(RoomEvent.TrackSubscribed, (track) => {
if (videoEl.value) track.attach(videoEl.value);
track.attach(video);
video.muted = focused.value !== id;
});
await room.connect(data.data.url, data.data.token);
active.value = true;
if (videoEl.value) videoEl.value.muted = false;
video.muted = true;
connections.set(id, room);
}
async function load() {
try {
const { data } = await http.get("/live/sessions", { params: { status: "LIVE" } });
rooms.value = data.data.items;
loading.value = false;
await new Promise((resolve) => requestAnimationFrame(() => resolve(undefined)));
for (const item of rooms.value) {
try {
await connect(item.id);
} catch {
error.value = "有教室暂时无法接入";
}
}
} catch (err: unknown) {
error.value = (err as { response?: { data?: { message?: string } } }).response?.data?.message ?? "巡课列表加载失败";
loading.value = false;
}
}
function focus(id: number) {
focused.value = id;
videos.forEach((video, roomId) => {
video.muted = roomId !== id;
});
}
onMounted(load);
onBeforeUnmount(() => room?.disconnect());
onBeforeUnmount(() => connections.forEach((room) => room.disconnect()));
</script>
+1
View File
@@ -14,6 +14,7 @@
<el-button class="touch" type="primary" native-type="submit" :loading="loading" style="width: 100%">登录</el-button>
</el-form>
<p v-if="error">{{ error }}</p>
<p><router-link to="/forgot">忘记密码</router-link></p>
<p v-if="site.registrationEnabled"><router-link to="/register">注册家长账号</router-link></p>
<p v-else>注册已关闭</p>
<p class="muted">{{ site.footer }}</p>
+26 -9
View File
@@ -1,12 +1,15 @@
<template>
<div class="page">
<h2>课程回放</h2>
<el-input v-model="classId" placeholder="按班级 ID 筛选" style="max-width: 240px" />
<el-button @click="load">查询</el-button>
<p v-if="items.length === 0">没有可看的回放</p>
<el-select v-model="classId" clearable placeholder="全部班级" style="width: 240px" @change="load">
<el-option v-for="item in classes" :key="item.id" :label="`${item.schoolName} ${item.name}`" :value="item.id" />
</el-select>
<p v-if="error">{{ error }}</p>
<p v-else-if="items.length === 0">没有可看的回放</p>
<ul>
<li v-for="item in items" :key="item.id">
班级 {{ item.classId }} · {{ item.status }}
{{ classLabel(item.classId) }} · {{ item.status }}
<span v-if="item.errorMessage"> · {{ item.errorMessage }}</span>
<el-button v-if="item.status === 'COMPLETED'" link @click="play(item.id)">播放</el-button>
</li>
</ul>
@@ -18,13 +21,24 @@
import { onMounted, ref } from "vue";
import { http } from "../api/http";
const items = ref<Array<{ id: number; classId: number; status: string }>>([]);
const classId = ref("");
const items = ref<Array<{ id: number; classId: number; status: string; errorMessage?: string }>>([]);
const classes = ref<Array<{ id: number; name: string; schoolName: string }>>([]);
const classId = ref<number | undefined>();
const url = ref("");
const error = ref("");
function classLabel(id: number) {
return classes.value.find((item) => item.id === id)?.name ?? `班级 ${id}`;
}
async function load() {
const { data } = await http.get("/recordings", { params: { classId: classId.value || undefined } });
items.value = data.data.items;
error.value = "";
try {
const { data } = await http.get("/recordings", { params: { classId: classId.value } });
items.value = data.data.items;
} catch (err: unknown) {
error.value = (err as { response?: { data?: { message?: string } } }).response?.data?.message ?? "回放加载失败";
}
}
async function play(id: number) {
@@ -32,5 +46,8 @@ async function play(id: number) {
url.value = data.data.url;
}
onMounted(load);
onMounted(async () => {
classes.value = (await http.get("/directory/classes")).data.data;
await load();
});
</script>