补上家长选班、巡课多画面、找回密码和管理端的节次与安全设置。
This commit is contained in:
1 parent
339641040e
commit
0afc29d431
17 files changed
+381
-113
No files matched your search
@@ -4,6 +4,7 @@ deploy/runtime/
|
||||
backend/target/
|
||||
frontend/node_modules/
|
||||
frontend/dist/
|
||||
frontend/tsconfig.tsbuildinfo
|
||||
frontend/coverage/
|
||||
*.log
|
||||
.idea/
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.xh.xunke.recording;
|
||||
|
||||
import com.xh.xunke.config.AppProperties;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class MediaProbe {
|
||||
private static final Logger log = LoggerFactory.getLogger(MediaProbe.class);
|
||||
private final RecordingRepository recordings;
|
||||
private final ObjectStorage storage;
|
||||
private final AppProperties props;
|
||||
|
||||
public MediaProbe(RecordingRepository recordings, ObjectStorage storage, AppProperties props) {
|
||||
this.recordings = recordings;
|
||||
this.storage = storage;
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
@Async("mediaExecutor")
|
||||
public void probe(Long recordingId) {
|
||||
Recording recording = recordings.findById(recordingId).orElse(null);
|
||||
if (recording == null || recording.getObjectKey() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String url = storage.presignInternal(recording.getObjectKey(), 10);
|
||||
Process process = new ProcessBuilder(props.getFfprobePath(), "-v", "error", "-show_streams",
|
||||
"-print_format", "json", url)
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
boolean finished = process.waitFor(20, TimeUnit.SECONDS);
|
||||
String output;
|
||||
try (InputStream in = process.getInputStream()) {
|
||||
output = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
if (!finished) {
|
||||
process.destroyForcibly();
|
||||
markFailed(recording, "探针超时");
|
||||
return;
|
||||
}
|
||||
ProbeParser.Result result = ProbeParser.parse(output);
|
||||
recording.setHasVideo(result.video());
|
||||
recording.setHasAudio(result.audio());
|
||||
if (result.video() && result.audio()) {
|
||||
recording.setStatus("COMPLETED");
|
||||
recording.setErrorMessage(null);
|
||||
} else {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage(result.video() ? "录像缺少音轨" : "录像缺少视频轨");
|
||||
}
|
||||
recordings.save(recording);
|
||||
} catch (Exception ex) {
|
||||
log.warn("录像探针失败");
|
||||
markFailed(recording, "无法检查录像文件");
|
||||
}
|
||||
}
|
||||
|
||||
private void markFailed(Recording recording, String reason) {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage(reason);
|
||||
recordings.save(recording);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import java.util.Optional;
|
||||
public interface RecordingRepository extends JpaRepository<Recording, Long> {
|
||||
Optional<Recording> findFirstBySessionIdOrderByIdDesc(Long sessionId);
|
||||
|
||||
Optional<Recording> findFirstByEgressId(String egressId);
|
||||
|
||||
Page<Recording> findBySchoolId(Long schoolId, Pageable pageable);
|
||||
|
||||
Page<Recording> findByClassId(Long classId, Pageable pageable);
|
||||
|
||||
@@ -12,21 +12,14 @@ import com.xh.xunke.school.BindingService;
|
||||
import com.xh.xunke.school.SchoolRepository;
|
||||
import com.xh.xunke.security.UserPrincipal;
|
||||
import livekit.LivekitWebhook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class RecordingService {
|
||||
private static final Logger log = LoggerFactory.getLogger(RecordingService.class);
|
||||
private final RecordingRepository recordings;
|
||||
private final LiveSessionRepository sessions;
|
||||
private final LiveKitGateway liveKit;
|
||||
@@ -34,9 +27,11 @@ public class RecordingService {
|
||||
private final BindingService bindings;
|
||||
private final SchoolRepository schools;
|
||||
private final AppProperties props;
|
||||
private final MediaProbe mediaProbe;
|
||||
|
||||
public RecordingService(RecordingRepository recordings, LiveSessionRepository sessions, LiveKitGateway liveKit,
|
||||
ObjectStorage storage, BindingService bindings, SchoolRepository schools, AppProperties props) {
|
||||
ObjectStorage storage, BindingService bindings, SchoolRepository schools, AppProperties props,
|
||||
MediaProbe mediaProbe) {
|
||||
this.recordings = recordings;
|
||||
this.sessions = sessions;
|
||||
this.liveKit = liveKit;
|
||||
@@ -44,6 +39,7 @@ public class RecordingService {
|
||||
this.bindings = bindings;
|
||||
this.schools = schools;
|
||||
this.props = props;
|
||||
this.mediaProbe = mediaProbe;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -87,10 +83,7 @@ public class RecordingService {
|
||||
return;
|
||||
}
|
||||
String egressId = event.getEgressInfo().getEgressId();
|
||||
recordings.findAll().stream()
|
||||
.filter(item -> egressId.equals(item.getEgressId()))
|
||||
.findFirst()
|
||||
.ifPresent(recording -> {
|
||||
recordings.findFirstByEgressId(egressId).ifPresent(recording -> {
|
||||
String name = event.getEvent();
|
||||
if ("egress_ended".equals(name) || "egress_complete".equals(name) || name.contains("ended")) {
|
||||
recording.setStatus("PROCESSING");
|
||||
@@ -100,7 +93,7 @@ public class RecordingService {
|
||||
recording.setDurationSeconds((int) event.getEgressInfo().getFileResults(0).getDuration());
|
||||
}
|
||||
recordings.save(recording);
|
||||
probeLater(recording.getId());
|
||||
mediaProbe.probe(recording.getId());
|
||||
} else if (name.contains("failed") || name.contains("aborted")) {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage("录像任务失败");
|
||||
@@ -110,45 +103,6 @@ public class RecordingService {
|
||||
});
|
||||
}
|
||||
|
||||
@Async("mediaExecutor")
|
||||
public void probeLater(Long recordingId) {
|
||||
Recording recording = recordings.findById(recordingId).orElse(null);
|
||||
if (recording == null || recording.getObjectKey() == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String url = storage.presignInternal(recording.getObjectKey(), 10);
|
||||
Process process = new ProcessBuilder(props.getFfprobePath(), "-v", "error", "-show_streams",
|
||||
"-print_format", "json", url)
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
boolean finished = process.waitFor(20, TimeUnit.SECONDS);
|
||||
String output;
|
||||
try (InputStream in = process.getInputStream()) {
|
||||
output = new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
if (!finished) {
|
||||
process.destroyForcibly();
|
||||
markFailed(recording, "探针超时");
|
||||
return;
|
||||
}
|
||||
ProbeParser.Result result = ProbeParser.parse(output);
|
||||
recording.setHasVideo(result.video());
|
||||
recording.setHasAudio(result.audio());
|
||||
if (result.video() && result.audio()) {
|
||||
recording.setStatus("COMPLETED");
|
||||
recording.setErrorMessage(null);
|
||||
} else {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage(result.video() ? "录像缺少音轨" : "录像缺少视频轨");
|
||||
}
|
||||
recordings.save(recording);
|
||||
} catch (Exception ex) {
|
||||
log.warn("录像探针失败");
|
||||
markFailed(recording, "无法检查录像文件");
|
||||
}
|
||||
}
|
||||
|
||||
public PagePayload<Recording> list(UserPrincipal me, Long classId, int page, int size) {
|
||||
var result = classId != null
|
||||
? recordings.findByClassId(classId, Pages.of(page, size))
|
||||
@@ -203,7 +157,7 @@ public class RecordingService {
|
||||
return recordings.save(recording);
|
||||
}
|
||||
if (storage.exists(recording.getObjectKey())) {
|
||||
probeLater(recording.getId());
|
||||
mediaProbe.probe(recording.getId());
|
||||
recording.setStatus("PROCESSING");
|
||||
return recordings.save(recording);
|
||||
}
|
||||
@@ -239,9 +193,4 @@ public class RecordingService {
|
||||
return sessions.findById(recording.getSessionId()).map(session -> session.getTeacherId().equals(me.id())).orElse(false);
|
||||
}
|
||||
|
||||
private void markFailed(Recording recording, String reason) {
|
||||
recording.setStatus("FAILED");
|
||||
recording.setErrorMessage(reason);
|
||||
recordings.save(recording);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,10 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class SchoolService {
|
||||
@@ -159,6 +162,25 @@ public class SchoolService {
|
||||
grades.delete(grade);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> directory() {
|
||||
Map<Long, String> schoolNames = new LinkedHashMap<>();
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
for (ClassRoom room : classes.findAll()) {
|
||||
if (!"ACTIVE".equals(room.getStatus())) {
|
||||
continue;
|
||||
}
|
||||
String schoolName = schoolNames.computeIfAbsent(room.getSchoolId(), id ->
|
||||
schools.findById(id).map(School::getName).orElse(""));
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("id", room.getId());
|
||||
row.put("name", room.getName());
|
||||
row.put("schoolId", room.getSchoolId());
|
||||
row.put("schoolName", schoolName);
|
||||
rows.add(row);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
public PagePayload<ClassRoom> classes(UserPrincipal me, Long schoolId, int page, int size) {
|
||||
Long scoped = me.superAdmin() ? schoolId : me.schoolId();
|
||||
var result = scoped == null
|
||||
|
||||
@@ -427,6 +427,11 @@ public class ResourceController {
|
||||
return ApiResponse.ok(stats);
|
||||
}
|
||||
|
||||
@GetMapping("/directory/classes")
|
||||
public ApiResponse<List<Map<String, Object>>> directory() {
|
||||
return ApiResponse.ok(schools.directory());
|
||||
}
|
||||
|
||||
@GetMapping("/parent/home")
|
||||
public ApiResponse<Map<String, Object>> parentHome() {
|
||||
var mine = bindings.list(me(), null, 0, 50);
|
||||
|
||||
+3
-1
@@ -6,7 +6,9 @@
|
||||
docker compose --env-file .env up --build
|
||||
```
|
||||
|
||||
- 网站:`http://localhost:8088`
|
||||
本机 8088 已被其他项目占用,Compose 把网站映射到 `18088`。官方 `minio/minio` 已不能匿名拉取,这里使用仍可拉取的 `alpine/minio:RELEASE.2025-10-15T17-29-55Z`。LiveKit 使用 `livekit/livekit-server:v1.13.11` 和 `livekit/egress:v1.13.0`。后端运行镜像是本机已有的 `eclipse-temurin:21-jdk-jammy`。
|
||||
|
||||
- 网站:`http://localhost:18088`
|
||||
- 后端:`http://localhost:8080`
|
||||
- MinIO 控制台:`http://localhost:9001`
|
||||
- LiveKit:`ws://localhost:7880`,UDP `50000-50100`
|
||||
|
||||
@@ -7,20 +7,18 @@ Java 不安装在宿主机。编译和测试使用 `scripts/mvn.ps1`,镜像是
|
||||
## 已完成并通过测试
|
||||
|
||||
- Spring Boot 3.5.16 / Java 21 后端可在 Docker 中编译。
|
||||
- 单元测试 `PolicyTest` 6 项通过:密码策略、公开注册只能成为待审核家长、直播房间隔离、家长不能推流、直播/回放授权分开、录像探针必须同时有音视频、密钥可加密往返。
|
||||
- 前端设备拆分测试 1 项通过:摄像头与麦克风分属两个列表。
|
||||
- 数据库 Flyway 脚本、RBAC、注册开关、家长绑定审核、课程与课表、直播状态机、LiveKit 令牌、Egress/MinIO 录像、SMTP/短信适配、Docker Compose 草稿已写入代码。
|
||||
- 单元测试 `PolicyTest` 7 项通过:密码策略、公开注册只能成为待审核家长、直播房间隔离、家长不能推流、直播/回放授权分开、家长不能管理学校、录像探针必须同时有音视频、密钥可加密往返。
|
||||
- 前端设备拆分测试 1 项通过,`vue-tsc` 与生产构建通过。
|
||||
- Docker Compose 已在本机启动。验收脚本走通建校、教师、待审核家长、只批直播、开播前拒绝播放、确认后订阅、停播和关闭注册。
|
||||
- 管理后台概览读到真实计数:用户 5、家长 1、教师 2、班级 2、今日直播 1。状态页显示 LiveKit 和对象存储可连接。
|
||||
- 浏览器登录后站点名来自接口。教室页点击允许摄像头后,视频列表出现 `5MP USB webcam` 和 `OBS Virtual Camera`,音频列表单独出现 USB 麦克风,没有混成一个设备框。
|
||||
- 家长首页按学校和班级名称申请绑定,并可修改密码。登录页可以找回密码。
|
||||
- 巡课页对每间正在直播的教室单独拉流,默认静音,点开一间才出声。
|
||||
- 管理端补了节次、通知模板和登录锁定设置。回放按班级名称筛选。
|
||||
|
||||
## 已写代码但尚未在本机完整跑通
|
||||
## 已写代码但尚未用真实推流跑通
|
||||
|
||||
- Docker Compose 全栈尚未启动,因此还没有真实的开播、观看、录像文件和 HTTPS 验收。
|
||||
- 浏览器摄像头和麦克风尚未用真实设备验证。希沃硬件不在当前环境。
|
||||
- 这次验收没有从浏览器把画面推进 LiveKit。确认开播后录像任务失败 1 次,没有生成可播放文件。
|
||||
- 教室页预览已经显示出本机 USB 摄像头画面。还没有把这路画面推进 LiveKit,也没有生成可播放录像。
|
||||
- 阿里云、腾讯云短信和 SMTP 只完成了协议实现,没有使用真实密钥发送。
|
||||
- 300 人观看压力测试没有执行,不能宣称支持该并发。
|
||||
|
||||
## 下一步
|
||||
|
||||
1. 启动 Compose 中的 PostgreSQL、Redis、MinIO、LiveKit 和后端。
|
||||
2. 用管理员账号走通建校、建班、审核、开播、观看、停播。
|
||||
3. 有摄像头时在浏览器里验证独立设备切换。
|
||||
4. 记录资源占用后再做小规模并发,不把未测结果写成能力。
|
||||
- 只测量了 50 个并发的公开站点接口,不能宣称支持 300 路观看。
|
||||
+11
-4
@@ -12,14 +12,21 @@
|
||||
|
||||
| 套件 | 命令 | 结果 |
|
||||
|---|---|---|
|
||||
| 后端策略测试 | `scripts/mvn.ps1 test` | 6 通过,0 失败 |
|
||||
| 后端策略测试 | `scripts/mvn.ps1 test` | 7 通过,0 失败 |
|
||||
| 前端设备列表 | `npm test` | 1 通过,0 失败 |
|
||||
| 前端类型与构建 | `vue-tsc --noEmit`、`vite build` | 通过 |
|
||||
| 学校流程验收 | `scripts/acceptance.ps1` | 通过。输出 `ACCEPTANCE_OK school=2 class=2 course=2 users=5 liveToday=1` |
|
||||
| 公开接口并发 | 50 个并发请求 `/api/public/site` | 50 成功,0 失败,p95 166 毫秒,最大 214 毫秒 |
|
||||
| 浏览器 | `http://localhost:18088` | 登录、后台概览和状态页已打开。教室页允许摄像头后,视频与麦克风分别列出真实设备 |
|
||||
|
||||
状态页实测:LiveKit 可连接,对象存储可连接,失败录像 1,完成录像 0。失败来自没有浏览器推流时启动的录像任务。
|
||||
|
||||
## 未执行
|
||||
|
||||
- 对 PostgreSQL 的接口集成测试。
|
||||
- 真实摄像头、麦克风、LiveKit 房间和 Egress 文件。
|
||||
- 1 / 5 / 10 个班级,以及 50 / 100 / 300 个观看者的压力测试。
|
||||
- 把预览中的摄像头推进 LiveKit,以及麦克风电平和非静音观看。预览画面已经出现。
|
||||
- Egress 生成并回放带音视频的 MP4。
|
||||
- 真实阿里云、腾讯云短信和 SMTP。
|
||||
- 50 / 100 / 300 个 WebRTC 观看者。
|
||||
- 服务器重启后的直播恢复。
|
||||
|
||||
没有上述证据时,不把并发观看能力写成已支持。
|
||||
@@ -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 } },
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
@@ -55,5 +55,6 @@ Api PUT "/admin/settings" @{ "reg.enabled" = "false" } $adminToken | Out-Null
|
||||
$closed = $false
|
||||
try { Api POST "/auth/register" @{ username = "closed$stamp"; displayName = "乙"; email = "closed$stamp@example.com"; password = "Parent123" } $null | Out-Null } catch { $closed = $true }
|
||||
if (-not $closed) { throw "关闭注册后仍能注册" }
|
||||
Api PUT "/admin/settings" @{ "reg.enabled" = "true" } $adminToken | Out-Null
|
||||
$dash = Api GET "/dashboard" $null $adminToken
|
||||
Write-Output "ACCEPTANCE_OK school=$schoolId class=$($class.data.id) course=$($course.data.id) users=$($dash.data.users) liveToday=$($dash.data.liveToday)"
|
||||
Reference in new issue
Block a user