This commit is contained in:
lincube
2026-03-29 15:34:17 +08:00
parent 372b5b7adc
commit bd2313fe7e
23 changed files with 2986 additions and 22 deletions

View File

@@ -0,0 +1,102 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="LanMountainDesktop.Views.ComponentEditors.ZhiJiaoHubComponentEditor">
<StackPanel Spacing="16">
<!-- 数据源选择 -->
<Border Classes="component-editor-card"
Padding="20">
<StackPanel Spacing="12">
<TextBlock x:Name="SourceLabelTextBlock"
Classes="component-editor-section-title" />
<ComboBox x:Name="SourceComboBox"
Classes="component-editor-select"
HorizontalAlignment="Stretch"
SelectionChanged="OnSourceSelectionChanged">
<ComboBoxItem x:Name="ClassIslandItem"
Classes="component-editor-select-item"
Tag="classisland" />
<ComboBoxItem x:Name="SectlItem"
Classes="component-editor-select-item"
Tag="sectl" />
</ComboBox>
<TextBlock x:Name="SourceDescriptionTextBlock"
Classes="component-editor-secondary-text"
TextWrapping="Wrap" />
</StackPanel>
</Border>
<!-- 镜像加速源选择 -->
<Border Classes="component-editor-card"
Padding="20">
<StackPanel Spacing="12">
<TextBlock x:Name="MirrorSourceLabelTextBlock"
Classes="component-editor-section-title" />
<ComboBox x:Name="MirrorSourceComboBox"
Classes="component-editor-select"
HorizontalAlignment="Stretch"
SelectionChanged="OnMirrorSourceSelectionChanged">
<ComboBoxItem x:Name="DirectMirrorItem"
Classes="component-editor-select-item"
Tag="direct" />
<ComboBoxItem x:Name="GhProxyMirrorItem"
Classes="component-editor-select-item"
Tag="gh-proxy" />
</ComboBox>
<TextBlock x:Name="MirrorSourceDescriptionTextBlock"
Classes="component-editor-secondary-text"
TextWrapping="Wrap" />
</StackPanel>
</Border>
<!-- 自动刷新设置 -->
<Border Classes="component-editor-card"
Padding="20">
<StackPanel Spacing="16">
<TextBlock x:Name="RefreshSettingsLabelTextBlock"
Classes="component-editor-section-title" />
<!-- 自动刷新开关 -->
<Grid ColumnDefinitions="*,Auto">
<StackPanel Spacing="4">
<TextBlock x:Name="AutoRefreshLabelTextBlock"
Classes="component-editor-primary-text" />
<TextBlock x:Name="AutoRefreshDescriptionTextBlock"
Classes="component-editor-secondary-text"
FontSize="12" />
</StackPanel>
<ToggleSwitch x:Name="AutoRefreshToggle"
Grid.Column="1"
IsCheckedChanged="OnAutoRefreshChanged" />
</Grid>
<!-- 刷新间隔 -->
<StackPanel x:Name="IntervalPanel"
Spacing="8">
<TextBlock x:Name="IntervalLabelTextBlock"
Classes="component-editor-primary-text" />
<NumericUpDown x:Name="IntervalNumeric"
Classes="component-editor-numeric"
Minimum="5"
Maximum="1440"
Increment="5"
ValueChanged="OnIntervalValueChanged" />
</StackPanel>
</StackPanel>
</Border>
<!-- 说明信息 -->
<Border Classes="component-editor-card"
Padding="20">
<StackPanel Spacing="8">
<TextBlock x:Name="AboutLabelTextBlock"
Classes="component-editor-section-title" />
<TextBlock x:Name="AboutDescriptionTextBlock"
Classes="component-editor-secondary-text"
TextWrapping="Wrap" />
</StackPanel>
</Border>
</StackPanel>
</UserControl>

View File

@@ -0,0 +1,152 @@
using System;
using Avalonia.Controls;
using Avalonia.Interactivity;
using LanMountainDesktop.ComponentSystem;
using LanMountainDesktop.Models;
namespace LanMountainDesktop.Views.ComponentEditors;
public partial class ZhiJiaoHubComponentEditor : ComponentEditorViewBase
{
private bool _suppressEvents;
public ZhiJiaoHubComponentEditor()
: this(null)
{
}
public ZhiJiaoHubComponentEditor(DesktopComponentEditorContext? context)
: base(context)
{
InitializeComponent();
ApplyLocalization();
LoadState();
}
private void ApplyLocalization()
{
// 标题
SourceLabelTextBlock.Text = L("zhijiaohub.settings.source", "图片源");
ClassIslandItem.Content = L("zhijiaohub.settings.classisland", "ClassIsland 图库");
SectlItem.Content = L("zhijiaohub.settings.sectl", "SECTL 图库");
// 数据源描述
SourceDescriptionTextBlock.Text = L("zhijiaohub.settings.source_desc",
"选择图片来源。ClassIsland 图库包含 ClassIsland 社区的趣味瞬间SECTL 图库包含 SECTL 社区的内容。");
// 镜像加速源
MirrorSourceLabelTextBlock.Text = L("zhijiaohub.settings.mirror_source", "镜像加速");
DirectMirrorItem.Content = L("zhijiaohub.settings.mirror_direct", "直连GitHub");
GhProxyMirrorItem.Content = L("zhijiaohub.settings.mirror_ghproxy", "镜像加速(推荐)");
MirrorSourceDescriptionTextBlock.Text = L("zhijiaohub.settings.mirror_source_desc",
"如果图片加载缓慢或失败,请尝试使用镜像加速。镜像加速通过第三方代理服务加速 GitHub 访问。");
// 刷新设置
RefreshSettingsLabelTextBlock.Text = L("zhijiaohub.settings.refresh", "刷新设置");
AutoRefreshLabelTextBlock.Text = L("zhijiaohub.settings.auto_refresh", "自动刷新");
AutoRefreshDescriptionTextBlock.Text = L("zhijiaohub.settings.auto_refresh_desc",
"定期自动刷新图片列表。");
IntervalLabelTextBlock.Text = L("zhijiaohub.settings.interval", "刷新间隔(分钟)");
// 关于
AboutLabelTextBlock.Text = L("zhijiaohub.settings.about", "关于");
AboutDescriptionTextBlock.Text = L("zhijiaohub.settings.about_desc",
"智教Hub 展示来自教育技术社区的有趣图片。图片从 GitHub 仓库获取并缓存在本地。");
}
private void LoadState()
{
_suppressEvents = true;
var snapshot = LoadSnapshot();
// 数据源
var source = ZhiJiaoHubSources.Normalize(snapshot.ZhiJiaoHubSource);
SourceComboBox.SelectedItem = source switch
{
ZhiJiaoHubSources.Sectl => SectlItem,
_ => ClassIslandItem
};
// 镜像加速源
var mirrorSource = ZhiJiaoHubMirrorSources.Normalize(snapshot.ZhiJiaoHubMirrorSource);
MirrorSourceComboBox.SelectedItem = mirrorSource switch
{
ZhiJiaoHubMirrorSources.GhProxy => GhProxyMirrorItem,
_ => DirectMirrorItem
};
// 自动刷新
AutoRefreshToggle.IsChecked = snapshot.ZhiJiaoHubAutoRefreshEnabled;
// 刷新间隔
var interval = Math.Clamp(snapshot.ZhiJiaoHubAutoRefreshIntervalMinutes, 5, 1440);
IntervalNumeric.Value = interval;
IntervalPanel.IsVisible = snapshot.ZhiJiaoHubAutoRefreshEnabled;
_suppressEvents = false;
}
private void OnSourceSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (_suppressEvents)
{
return;
}
var source = SourceComboBox.SelectedItem is ComboBoxItem item && item.Tag is string tag
? ZhiJiaoHubSources.Normalize(tag)
: ZhiJiaoHubSources.ClassIsland;
var snapshot = LoadSnapshot();
snapshot.ZhiJiaoHubSource = source;
SaveSnapshot(snapshot, nameof(ComponentSettingsSnapshot.ZhiJiaoHubSource));
}
private void OnMirrorSourceSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (_suppressEvents)
{
return;
}
var mirrorSource = MirrorSourceComboBox.SelectedItem is ComboBoxItem item && item.Tag is string tag
? ZhiJiaoHubMirrorSources.Normalize(tag)
: ZhiJiaoHubMirrorSources.Direct;
var snapshot = LoadSnapshot();
snapshot.ZhiJiaoHubMirrorSource = mirrorSource;
SaveSnapshot(snapshot, nameof(ComponentSettingsSnapshot.ZhiJiaoHubMirrorSource));
}
private void OnAutoRefreshChanged(object? sender, RoutedEventArgs e)
{
_ = sender;
_ = e;
if (_suppressEvents)
{
return;
}
var isEnabled = AutoRefreshToggle.IsChecked ?? true;
IntervalPanel.IsVisible = isEnabled;
var snapshot = LoadSnapshot();
snapshot.ZhiJiaoHubAutoRefreshEnabled = isEnabled;
SaveSnapshot(snapshot, nameof(ComponentSettingsSnapshot.ZhiJiaoHubAutoRefreshEnabled));
}
private void OnIntervalValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
if (_suppressEvents)
{
return;
}
var interval = (int)Math.Clamp(IntervalNumeric.Value ?? 30, 5, 1440);
var snapshot = LoadSnapshot();
snapshot.ZhiJiaoHubAutoRefreshIntervalMinutes = interval;
SaveSnapshot(snapshot, nameof(ComponentSettingsSnapshot.ZhiJiaoHubAutoRefreshIntervalMinutes));
}
}