学生、任课关系、周次口径三处长期靠约定维持的事情,改为由数据模型保证。 学生不是账号 - 拆出独立 Student 表,没有 passwordHash / role / 任何登录字段 - 「学生不能登录」由表结构保证,不再靠「登录前判 role 再 403」的代码分支 - 三张个人数据表外键 userId → studentId;删掉 Enrollment 与 ClassTeacher - 学生一律称「学号」、教师一律称「工号」,「学生账号」这个概念消失 任课关系唯一来源 = Course(班级 + 科目 + 教师) - 班主任 = Class.teacherId,科任 = Course.teacherId,同一人两处指向同一账号、不重复建号 - 作业与成绩按科目再收一道:挂科目只由该科任课老师改,没挂科目归班主任 / 管理员 - 新增「任课教师分配」与「班级教师批量导入」(带「使用工号匹配」开关) 成绩与名单 - 成绩等级:百分制 / 等级制 A·B·C·D / 自定义,支持单个与批量改等级 - 按学号查成绩明细(教师端 + 班级端 + 设备令牌),受按班开关控制 - 调班 / 转出(单个与批量)+ 可查历史;学号不变、历史作业成绩留原归属 - 毕业归档页(按年度记录毕业班级 / 毕业生 / 转出学生 / 该届通知与作业) - 学年升级(未毕业不归档、数据沿用);班级称呼改为「2026级1班」 ClassHelper 班级端在线状态 - Web 端显示 班级 / 设备名 / 设备号 / 在线离线 / 最后在线 / 最后心跳 - lastHeartbeatAt 驱动 60 秒在线窗口,与只表示「带状态上报」的 lastSeenAt 分开 学期周次 - 新增 TermWeek(classId 空串 = 全校默认),管理员可用日期范围选择器逐周配置 - 一键按开学日期生成整学期;联网拉取调休建议(只给建议、不改数据,无外网失败属正常) - 改周次后随课表下发给教室的 ClassHelper 班级端 课表方向反转 - 主方向改为「服务端 → 教室」自动下发;教室不再自动回传 - 取教室课表改为手动动作(点击前弹警告),插件按待办标记在下一次心跳补报 改名 - 班级小助手 → ClassHelper:界面、窗口标题、托盘、灵动岛、EXE、安装包、 安装目录、systemd 描述、插件清单与设置页、官网、文档站、README BREAKING CHANGE: 产品名与 EXE 名变更(班级小助手.exe → ClassHelper.exe), 安装目录随之改变,不支持覆盖安装,需先卸载旧版。 服务端首次启动会自动应用 6 个数据库迁移(学生行按 id 原样搬迁,历史数据不丢), 升级前请先备份。
198 lines
7.6 KiB
C#
198 lines
7.6 KiB
C#
using System.ComponentModel;
|
||
using System.Runtime.CompilerServices;
|
||
using Avalonia.Threading;
|
||
using ClassHelper.ClassIslandPlugin.Models;
|
||
using ClassHelper.ClassIslandPlugin.Services;
|
||
using ClassIsland.Core.Abstractions.Controls;
|
||
using ClassIsland.Core.Attributes;
|
||
using ClassIsland.Core.Enums.SettingsWindow;
|
||
using CommunityToolkit.Mvvm.Input;
|
||
|
||
namespace ClassHelper.ClassIslandPlugin.Views;
|
||
|
||
/// <summary>
|
||
/// 「ClassHelper 联动」设置页。
|
||
///
|
||
/// 页面上的绑定源就是本页自己(<c>DataContext = this</c>):<see cref="Settings"/> 暴露全部配置项,
|
||
/// <see cref="Bridge"/> 暴露运行状态。这样 XAML 里能直接写 <c>{Binding Settings.Xxx}</c>,
|
||
/// 不需要再套一层 ViewModel,改配置项时也少一处"两边同步"的机会。
|
||
/// </summary>
|
||
// 图标用 Fluent 字体的码位(与 ClassIsland 内置设置页写法一致):未选中/选中同一枚插头图标
|
||
[SettingsPageInfo(
|
||
"classhelper.classisland.bridge.settings",
|
||
"ClassHelper 联动",
|
||
"\uE71B",
|
||
"\uE71B",
|
||
SettingsPageCategory.External)]
|
||
public partial class BridgeSettingsPage : SettingsPageBase, INotifyPropertyChanged
|
||
{
|
||
public BridgeSettingsPage(PluginSettings settings, BridgeService bridge)
|
||
{
|
||
Settings = settings;
|
||
Bridge = bridge;
|
||
|
||
ReportCommand = new AsyncRelayCommand(ReportAsync);
|
||
TestCommand = new AsyncRelayCommand(TestAsync);
|
||
PullCommand = new AsyncRelayCommand(PullAsync);
|
||
MirrorCommand = new AsyncRelayCommand(MirrorAsync);
|
||
|
||
InitializeComponent();
|
||
DataContext = this;
|
||
Raise(nameof(StatusText));
|
||
}
|
||
|
||
public PluginSettings Settings { get; }
|
||
|
||
public BridgeService Bridge { get; }
|
||
|
||
public IAsyncRelayCommand ReportCommand { get; }
|
||
public IAsyncRelayCommand TestCommand { get; }
|
||
public IAsyncRelayCommand PullCommand { get; }
|
||
public IAsyncRelayCommand MirrorCommand { get; }
|
||
|
||
private PropertyChangedEventHandler? _propertyChanged;
|
||
|
||
/// <summary>
|
||
/// 显式实现 <see cref="INotifyPropertyChanged"/>:<c>AvaloniaObject</c> 自带一个同名但类型不同的事件,
|
||
/// 直接声明会遮蔽基类成员。显式实现既不影响 Avalonia 的绑定查找(它按接口取),也不会有歧义。
|
||
/// </summary>
|
||
event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged
|
||
{
|
||
add => _propertyChanged += value;
|
||
remove => _propertyChanged -= value;
|
||
}
|
||
|
||
/* ---------------------------------------------------------------- 绑定用的展示文本 */
|
||
|
||
/// <summary>一句话结论:还没配 / 已配置 / 已连接 / 连接异常。</summary>
|
||
public string StatusText
|
||
{
|
||
get
|
||
{
|
||
if (!Settings.IsConfigured) return "尚未配置:请填写服务器地址与设备令牌";
|
||
if (!Bridge.IsAttached) return "已填写配置,等待 ClassIsland 课程服务就绪";
|
||
return Bridge.LastReportOk ? "已连接" : "连接异常";
|
||
}
|
||
}
|
||
|
||
public string DetailText
|
||
{
|
||
get
|
||
{
|
||
var week = Bridge.LastServerWeek?.ToString() ?? "—";
|
||
return $"最后上报:{Bridge.LastReportAtText} 教学周:{week} " +
|
||
$"课表 {Bridge.LastScheduleEntryCount} 节 / 节次 {Bridge.LastTimeLayoutItemCount} 条 " +
|
||
$"已弹出提醒:{Bridge.NotificationCount} 条";
|
||
}
|
||
}
|
||
|
||
/// <summary>调试信息(设置页里打开"显示调试信息"才可见)。</summary>
|
||
public string DebugText
|
||
{
|
||
get
|
||
{
|
||
var lines = new List<string>
|
||
{
|
||
$"服务器地址:{(string.IsNullOrWhiteSpace(Settings.ServerUrl) ? "(未填)" : Settings.ServerUrl)}",
|
||
$"设备令牌:{(string.IsNullOrWhiteSpace(Settings.DeviceToken) ? "(未填)" : Mask(Settings.DeviceToken))}",
|
||
$"设备标识:{(string.IsNullOrWhiteSpace(Settings.DeviceKey) ? "(未生成)" : Settings.DeviceKey)}",
|
||
$"课程服务:{(Bridge.IsAttached ? "已接入" : "未接入")}",
|
||
$"与服务端时钟差:{Bridge.ClientTimeOffsetText}",
|
||
$"ClassIsland 版本:{SafeVersion()}",
|
||
$"配置目录:{PluginConfigFolder}",
|
||
};
|
||
return string.Join(Environment.NewLine, lines);
|
||
}
|
||
}
|
||
|
||
/// <summary>设置页所在的插件配置目录(从插件入口拿;拿不到时留空)。</summary>
|
||
private string PluginConfigFolder =>
|
||
ClassIsland.Shared.IAppHost.TryGetService<ClassIsland.Core.Abstractions.PluginBase>()?.PluginConfigFolder ?? "—";
|
||
|
||
private static string SafeVersion()
|
||
{
|
||
try { return ClassIsland.Core.AppBase.AppVersion ?? "—"; }
|
||
catch { return "—"; }
|
||
}
|
||
|
||
/// <summary>令牌只露头尾,避免设置页截图时把可用凭证泄露出去。</summary>
|
||
private static string Mask(string token) =>
|
||
token.Length <= 14 ? token : $"{token[..12]}…{token[^4..]}";
|
||
|
||
/* ---------------------------------------------------------------- 交互 */
|
||
|
||
private async Task ReportAsync()
|
||
{
|
||
await Bridge.ReportAsync("手动").ConfigureAwait(true);
|
||
}
|
||
|
||
/// <summary>不带课表上报一次:用来快速验证"地址 + 令牌"是否可用,不会因为课表为空而出错。</summary>
|
||
private async Task TestAsync()
|
||
{
|
||
await Bridge.ReportAsync("连接检查", includeSchedule: false).ConfigureAwait(true);
|
||
}
|
||
|
||
private async Task PullAsync()
|
||
{
|
||
await Bridge.PullPendingAsync().ConfigureAwait(true);
|
||
}
|
||
|
||
private async Task MirrorAsync()
|
||
{
|
||
await Bridge.MirrorScheduleAsync().ConfigureAwait(true);
|
||
}
|
||
|
||
private void OnSettingsChanged(object? sender, PropertyChangedEventArgs args)
|
||
{
|
||
// 影响上报链路的改动需要立刻重建定时器;纯界面项(如"显示调试信息")不用管
|
||
if (args.PropertyName is nameof(PluginSettings.ServerUrl)
|
||
or nameof(PluginSettings.DeviceToken)
|
||
or nameof(PluginSettings.AutoReport)
|
||
or nameof(PluginSettings.ReportIntervalSeconds)
|
||
or nameof(PluginSettings.ReceiveNotifications)
|
||
or nameof(PluginSettings.NotificationPollSeconds))
|
||
{
|
||
Bridge.RestartTimer();
|
||
}
|
||
|
||
Raise(nameof(StatusText));
|
||
Raise(nameof(DebugText));
|
||
}
|
||
|
||
private void OnBridgeChanged(object? sender, PropertyChangedEventArgs args)
|
||
{
|
||
// Bridge 的属性变化可能来自线程池(HttpClient 回调),绑定必须在 UI 线程上更新
|
||
if (Dispatcher.UIThread.CheckAccess())
|
||
{
|
||
RaiseStateProperties();
|
||
}
|
||
else
|
||
{
|
||
Dispatcher.UIThread.Post(RaiseStateProperties);
|
||
}
|
||
}
|
||
|
||
private void RaiseStateProperties()
|
||
{
|
||
Raise(nameof(StatusText));
|
||
Raise(nameof(DetailText));
|
||
Raise(nameof(DebugText));
|
||
}
|
||
|
||
private void OnLoaded(object sender, Avalonia.Interactivity.RoutedEventArgs args)
|
||
{
|
||
// 改完地址/令牌/间隔要重建定时器,否则"改了设置但上报节奏还是旧的"
|
||
Settings.PropertyChanged += OnSettingsChanged;
|
||
// 运行状态(上一次上报结果 / 待弹出提醒数)变了要刷新状态卡片
|
||
Bridge.PropertyChanged += OnBridgeChanged;
|
||
}
|
||
|
||
private void OnUnloaded(object sender, Avalonia.Interactivity.RoutedEventArgs args)
|
||
{
|
||
Settings.PropertyChanged -= OnSettingsChanged;
|
||
Bridge.PropertyChanged -= OnBridgeChanged;
|
||
}
|
||
|
||
private void Raise([CallerMemberName] string? propertyName = null) =>
|
||
_propertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||
} |