优化地图编辑中的字段管理
This commit is contained in:
@@ -59,11 +59,25 @@ public static class DashboardShortcutCatalog
|
||||
|
||||
public static readonly int MaxKeysPerUser = 16;
|
||||
|
||||
/// <summary>Platform 域固定保留、不可删除的快捷入口。</summary>
|
||||
public static readonly IReadOnlyList<string> MandatoryPlatformKeys =
|
||||
[
|
||||
"admin-maps",
|
||||
"admin-map-editor",
|
||||
"admin-cars",
|
||||
"admin-map-monitor",
|
||||
"admin-vehicle-hub",
|
||||
"admin-task-templates"
|
||||
];
|
||||
|
||||
public static readonly IReadOnlyList<string> DefaultPlatformKeys =
|
||||
[
|
||||
"admin-maps",
|
||||
"admin-map-editor",
|
||||
"admin-task-templates",
|
||||
"admin-cars",
|
||||
"admin-map-monitor",
|
||||
"admin-vehicle-hub",
|
||||
"admin-task-templates",
|
||||
"admin-config-system-center",
|
||||
"admin-config-ops-center",
|
||||
"admin-config-strategy"
|
||||
@@ -96,4 +110,8 @@ public static class DashboardShortcutCatalog
|
||||
|
||||
public static string NormalizeKey(string key) =>
|
||||
LegacyKeyAliases.TryGetValue(key.Trim(), out var canon) ? canon : key.Trim();
|
||||
|
||||
public static bool IsMandatoryKey(string key, string scope) =>
|
||||
string.Equals(scope, PageCatalog.ScopePlatform, StringComparison.OrdinalIgnoreCase)
|
||||
&& MandatoryPlatformKeys.Contains(NormalizeKey(key), StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
@@ -34,14 +34,17 @@ public sealed class DashboardShortcutService
|
||||
|
||||
if (row == null)
|
||||
{
|
||||
var defaults = FilterKeys(DashboardShortcutCatalog.DefaultKeysForScope(scope), scope, allowed);
|
||||
var defaults = EnsureMandatoryKeys(
|
||||
FilterKeys(DashboardShortcutCatalog.DefaultKeysForScope(scope), scope, allowed),
|
||||
scope, allowed);
|
||||
return new QuickEntriesResult(
|
||||
defaults.Take(DashboardShortcutCatalog.MaxKeysPerUser).ToList(),
|
||||
UsingDefaults: true);
|
||||
}
|
||||
|
||||
var keys = ParseKeys(row.KeysJson);
|
||||
var filtered = FilterKeys(keys, scope, allowed)
|
||||
var filtered = EnsureMandatoryKeys(
|
||||
FilterKeys(keys, scope, allowed), scope, allowed)
|
||||
.Take(DashboardShortcutCatalog.MaxKeysPerUser)
|
||||
.ToList();
|
||||
return new QuickEntriesResult(filtered, UsingDefaults: false);
|
||||
@@ -52,7 +55,8 @@ public sealed class DashboardShortcutService
|
||||
{
|
||||
scope = NormalizeScope(scope);
|
||||
var allowed = AllowedPages(userId, scope);
|
||||
var sanitized = FilterKeys(Deduplicate(keys ?? []), scope, allowed);
|
||||
var sanitized = EnsureMandatoryKeys(
|
||||
FilterKeys(Deduplicate(keys ?? []), scope, allowed), scope, allowed);
|
||||
if (sanitized.Count > DashboardShortcutCatalog.MaxKeysPerUser)
|
||||
sanitized = sanitized.Take(DashboardShortcutCatalog.MaxKeysPerUser).ToList();
|
||||
|
||||
@@ -114,6 +118,32 @@ public sealed class DashboardShortcutService
|
||||
return outKeys;
|
||||
}
|
||||
|
||||
private static List<string> EnsureMandatoryKeys(
|
||||
List<string> keys, string scope, HashSet<string> allowedPages)
|
||||
{
|
||||
if (!string.Equals(scope, PageCatalog.ScopePlatform, StringComparison.OrdinalIgnoreCase))
|
||||
return keys;
|
||||
|
||||
var result = new List<string>();
|
||||
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var raw in DashboardShortcutCatalog.MandatoryPlatformKeys)
|
||||
{
|
||||
var key = DashboardShortcutCatalog.NormalizeKey(raw);
|
||||
if (!DashboardShortcutCatalog.IsValidKey(key)) continue;
|
||||
var pageKey = DashboardShortcutCatalog.PageKeyFor(key);
|
||||
if (!allowedPages.Contains(pageKey)) continue;
|
||||
if (seen.Add(key)) result.Add(key);
|
||||
}
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
if (seen.Add(key)) result.Add(key);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<string> Deduplicate(IReadOnlyList<string> keys)
|
||||
{
|
||||
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
Reference in New Issue
Block a user