GetEnums API:返回所有枚举定义供前端下拉框使用
This commit is contained in:
parent
178923c007
commit
1fdffd2a41
@ -56,5 +56,24 @@ namespace CounterDrone.Core.Services
|
|||||||
|
|
||||||
// ═══ Misc ═══
|
// ═══ Misc ═══
|
||||||
void UpdateStep(string scenarioId, int step);
|
void UpdateStep(string scenarioId, int step);
|
||||||
|
|
||||||
|
/// <summary>返回所有枚举定义(供前端下拉框使用)</summary>
|
||||||
|
EnumMetadata GetEnums();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>枚举元数据</summary>
|
||||||
|
public class EnumMetadata
|
||||||
|
{
|
||||||
|
public Dictionary<string, int> DroneType { get; set; } = new();
|
||||||
|
public Dictionary<string, int> PowerType { get; set; } = new();
|
||||||
|
public Dictionary<string, int> PlatformType { get; set; } = new();
|
||||||
|
public Dictionary<string, int> AerosolType { get; set; } = new();
|
||||||
|
public Dictionary<string, int> WeatherType { get; set; } = new();
|
||||||
|
public Dictionary<string, int> WindDirection { get; set; } = new();
|
||||||
|
public Dictionary<string, int> SceneType { get; set; } = new();
|
||||||
|
public Dictionary<string, int> FormationMode { get; set; } = new();
|
||||||
|
public Dictionary<string, int> TriggerMode { get; set; } = new();
|
||||||
|
public Dictionary<string, int> ReleaseMode { get; set; } = new();
|
||||||
|
public Dictionary<string, int> EquipmentRole { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -230,6 +230,32 @@ namespace CounterDrone.Core.Services
|
|||||||
_scenarioRepo.Update(scenario);
|
_scenarioRepo.Update(scenario);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EnumMetadata GetEnums()
|
||||||
|
{
|
||||||
|
return new EnumMetadata
|
||||||
|
{
|
||||||
|
DroneType = EnumToDict<Models.DroneType>(),
|
||||||
|
PowerType = EnumToDict<Models.PowerType>(),
|
||||||
|
PlatformType = EnumToDict<Models.PlatformType>(),
|
||||||
|
AerosolType = EnumToDict<Models.AerosolType>(),
|
||||||
|
WeatherType = EnumToDict<Models.WeatherType>(),
|
||||||
|
WindDirection = EnumToDict<Models.WindDirection>(),
|
||||||
|
SceneType = EnumToDict<Models.SceneType>(),
|
||||||
|
FormationMode = EnumToDict<Models.FormationMode>(),
|
||||||
|
TriggerMode = EnumToDict<Models.TriggerMode>(),
|
||||||
|
ReleaseMode = EnumToDict<Models.ReleaseMode>(),
|
||||||
|
EquipmentRole = EnumToDict<Models.EquipmentRole>(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<string, int> EnumToDict<T>() where T : Enum
|
||||||
|
{
|
||||||
|
var dict = new Dictionary<string, int>();
|
||||||
|
foreach (T v in Enum.GetValues(typeof(T)))
|
||||||
|
dict[v.ToString()] = Convert.ToInt32(v);
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
// ========== Scenario CRUD ==========
|
// ========== Scenario CRUD ==========
|
||||||
|
|
||||||
public Scenario UpdateScenario(Scenario scenario)
|
public Scenario UpdateScenario(Scenario scenario)
|
||||||
|
|||||||
@ -88,6 +88,8 @@ namespace CounterDrone.Unity
|
|||||||
|
|
||||||
public void UpdateStep(string scenarioId, int step) => _service.UpdateStep(scenarioId, step);
|
public void UpdateStep(string scenarioId, int step) => _service.UpdateStep(scenarioId, step);
|
||||||
|
|
||||||
|
public EnumMetadata GetEnums() => _service.GetEnums();
|
||||||
|
|
||||||
[ContextMenu("Verify")]
|
[ContextMenu("Verify")]
|
||||||
void Verify()
|
void Verify()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user