namespace NginxMan; public sealed class PortalContentDialog : Form { private readonly TextBox _txtSiteName; private readonly TextBox _txtHeadline; private readonly TextBox _txtIntroduction; public PortalContentDialog(PortalContentSettings content) { Text = "主页内容设置"; StartPosition = FormStartPosition.CenterParent; FormBorderStyle = FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; ShowInTaskbar = false; ClientSize = new Size(610, 360); Font = new Font("Microsoft YaHei UI", 9F); var root = new TableLayoutPanel { Dock = DockStyle.Fill, ColumnCount = 2, RowCount = 6, Padding = new Padding(18), BackColor = Color.White }; root.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100)); root.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100)); root.RowStyles.Add(new RowStyle(SizeType.Absolute, 42)); root.RowStyles.Add(new RowStyle(SizeType.Absolute, 44)); root.RowStyles.Add(new RowStyle(SizeType.Absolute, 44)); root.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); root.RowStyles.Add(new RowStyle(SizeType.Absolute, 34)); root.RowStyles.Add(new RowStyle(SizeType.Absolute, 42)); var description = new Label { Text = "这些文字会展示在统一入口页上。可以直接修改,也可以恢复默认示例。", Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleLeft, ForeColor = Color.FromArgb(70, 85, 96) }; root.Controls.Add(description, 0, 0); root.SetColumnSpan(description, 2); _txtSiteName = CreateTextBox(content.SiteName, 80, "例如:服务导航"); _txtHeadline = CreateTextBox(content.Headline, 120, "例如:欢迎访问统一服务入口"); _txtIntroduction = CreateTextBox( content.Introduction, 500, "例如:请选择下方网站或服务,点击卡片即可开始访问。"); _txtIntroduction.Multiline = true; _txtIntroduction.ScrollBars = ScrollBars.Vertical; root.Controls.Add(CreateLabel("入口页名称"), 0, 1); root.Controls.Add(_txtSiteName, 1, 1); root.Controls.Add(CreateLabel("主页标题"), 0, 2); root.Controls.Add(_txtHeadline, 1, 2); root.Controls.Add(CreateLabel("主页简介"), 0, 3); root.Controls.Add(_txtIntroduction, 1, 3); var hint = new Label { Text = "入口页名称同时用于浏览器标签、页头名称和页脚名称。", Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleLeft, ForeColor = Color.FromArgb(100, 110, 120) }; root.Controls.Add(hint, 1, 4); var buttons = new FlowLayoutPanel { Dock = DockStyle.Fill, FlowDirection = FlowDirection.RightToLeft, WrapContents = false, Padding = new Padding(0, 6, 0, 0) }; var saveButton = CreateButton("保存", 86); var cancelButton = CreateButton("取消", 86); var defaultsButton = CreateButton("恢复默认示例", 116); saveButton.Click += (s, e) => SaveAndClose(); cancelButton.DialogResult = DialogResult.Cancel; defaultsButton.Click += (s, e) => LoadDefaults(); buttons.Controls.Add(saveButton); buttons.Controls.Add(cancelButton); buttons.Controls.Add(defaultsButton); root.Controls.Add(buttons, 0, 5); root.SetColumnSpan(buttons, 2); AcceptButton = saveButton; CancelButton = cancelButton; Controls.Add(root); } public string SiteName => _txtSiteName.Text.Trim(); public string Headline => _txtHeadline.Text.Trim(); public string Introduction => _txtIntroduction.Text.Trim(); private void SaveAndClose() { if (string.IsNullOrWhiteSpace(SiteName) || string.IsNullOrWhiteSpace(Headline) || string.IsNullOrWhiteSpace(Introduction)) { MessageBox.Show( "入口页名称、主页标题和主页简介都不能为空。", "NginxMan", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DialogResult = DialogResult.OK; Close(); } private void LoadDefaults() { _txtSiteName.Text = PortalContentSettings.DefaultSiteName; _txtHeadline.Text = PortalContentSettings.DefaultHeadline; _txtIntroduction.Text = PortalContentSettings.DefaultIntroduction; _txtSiteName.Focus(); } private static TextBox CreateTextBox(string value, int maxLength, string placeholder) => new() { Text = value, MaxLength = maxLength, PlaceholderText = placeholder, Dock = DockStyle.Fill, BorderStyle = BorderStyle.FixedSingle }; private static Label CreateLabel(string text) => new() { Text = text, Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleLeft }; private static Button CreateButton(string text, int width) => new() { Text = text, Width = width, Height = 28, Margin = new Padding(8, 0, 0, 0), FlatStyle = FlatStyle.Flat }; }