All checks were successful
Build and Deploy Front / deploy (push) Successful in 5m51s
Co-authored-by: Cursor <cursoragent@cursor.com>
318 lines
8.1 KiB
TypeScript
318 lines
8.1 KiB
TypeScript
/**
|
||
* itfx(接口通)后端枚举常量
|
||
* 来源:itfx-master / InterfaceForward.Domain.Shared
|
||
* 运行时下拉选项通过 Dictionary/GetList?type={枚举名} 获取
|
||
*/
|
||
|
||
/** Dictionary/GetList 支持的枚举 type 参数 */
|
||
export const ItfxDictionaryType = {
|
||
ServiceProviderType: 'ServiceProviderType',
|
||
RequestProtocol: 'RequestProtocol',
|
||
RequestMethod: 'RequestMethod',
|
||
ContentType: 'ContentType',
|
||
ResponseContentType: 'ResponseContentType',
|
||
ParameterType: 'ParameterType',
|
||
ParameterPlaceholder: 'ParameterPlaceholder',
|
||
ParameterParseTypeEnum: 'ParameterParseTypeEnum',
|
||
FieldPosition: 'FieldPosition',
|
||
AuthParameterFlag: 'AuthParameterFlag',
|
||
EffectTimeUnit: 'EffectTimeUnit',
|
||
InterfaceReturnConfigType: 'InterfaceReturnConfigType',
|
||
LabelType: 'LabelType',
|
||
OptionType: 'OptionType',
|
||
LogListInputTypeEnum: 'LogListInputTypeEnum',
|
||
} as const;
|
||
|
||
export type ItfxDictionaryTypeName =
|
||
(typeof ItfxDictionaryType)[keyof typeof ItfxDictionaryType];
|
||
|
||
/** 服务商类型 */
|
||
export const ServiceProviderType = {
|
||
运输服务商: 1,
|
||
轨迹服务商: 2,
|
||
关务服务商: 3,
|
||
保险服务商: 4,
|
||
} as const;
|
||
|
||
/** 请求协议 */
|
||
export const RequestProtocol = {
|
||
Http: 1,
|
||
Https: 2,
|
||
WCF: 3,
|
||
SOAP: 4,
|
||
} as const;
|
||
|
||
/** HTTP 请求方法 */
|
||
export const RequestMethod = {
|
||
GET: 1,
|
||
POST: 2,
|
||
PUT: 3,
|
||
DELETE: 4,
|
||
OPTIONS: 5,
|
||
HEAD: 6,
|
||
PATCH: 7,
|
||
} as const;
|
||
|
||
/** 请求 Content-Type */
|
||
export const ContentType = {
|
||
None: 0,
|
||
FormUrlEncoded: 1,
|
||
FormData: 2,
|
||
Json: 3,
|
||
Xml: 4,
|
||
} as const;
|
||
|
||
/** 响应 Content-Type */
|
||
export const ResponseContentType = {
|
||
Json: 1,
|
||
Xml: 2,
|
||
pdf: 3,
|
||
Base64: 4,
|
||
csv: 5,
|
||
} as const;
|
||
|
||
/** 参数数据类型 */
|
||
export const ParameterType = {
|
||
String: 1,
|
||
Float: 2,
|
||
Object: 3,
|
||
Boolean: 4,
|
||
Array: 5,
|
||
Integer: 6,
|
||
DateTime: 7,
|
||
DateTimeOffset: 8,
|
||
} as const;
|
||
|
||
/** 固定参数占位符(Description 为实际占位符字符串) */
|
||
export const ParameterPlaceholder = {
|
||
FromAccount: 1,
|
||
FromBody: 2,
|
||
TimeStamp: 3,
|
||
DateTime: 4,
|
||
Url: 5,
|
||
Token: 6,
|
||
FromMappingBody: 7,
|
||
} as const;
|
||
|
||
export const ParameterPlaceholderText: Record<number, string> = {
|
||
[ParameterPlaceholder.FromAccount]: '$FromAccount',
|
||
[ParameterPlaceholder.FromBody]: '$FromBody',
|
||
[ParameterPlaceholder.TimeStamp]: '$TimeStamp',
|
||
[ParameterPlaceholder.DateTime]: '$DateTime',
|
||
[ParameterPlaceholder.Url]: '$Url',
|
||
[ParameterPlaceholder.Token]: '$Token',
|
||
[ParameterPlaceholder.FromMappingBody]: '$FromMappingBody',
|
||
};
|
||
|
||
/** FormUrlEncoded Body/Query KV 推荐占位符(不含已停用的 $FromBody) */
|
||
export const FormKvPlaceholderOptions = [
|
||
ParameterPlaceholderText[ParameterPlaceholder.FromAccount],
|
||
ParameterPlaceholderText[ParameterPlaceholder.FromMappingBody],
|
||
ParameterPlaceholderText[ParameterPlaceholder.TimeStamp],
|
||
ParameterPlaceholderText[ParameterPlaceholder.DateTime],
|
||
ParameterPlaceholderText[ParameterPlaceholder.Url],
|
||
ParameterPlaceholderText[ParameterPlaceholder.Token],
|
||
];
|
||
|
||
/** 参数解析类型 */
|
||
export const ParameterParseTypeEnum = {
|
||
Json: 1,
|
||
Xml: 2,
|
||
} as const;
|
||
|
||
/** 字段位置(前置/后置脚本常用) */
|
||
export const FieldPosition = {
|
||
Header: 1,
|
||
Body: 2,
|
||
Query: 3,
|
||
Url: 4,
|
||
Nothing: 5,
|
||
} as const;
|
||
|
||
/** 字段所属(不在 Dictionary API 中,仅后端 DTO 使用) */
|
||
export const FieldOwner = {
|
||
ServiceProvider: 0,
|
||
Interface: 1,
|
||
AuthConfig: 2,
|
||
} as const;
|
||
|
||
/** 授权参数标识 */
|
||
export const AuthParameterFlag = {
|
||
InParameter: 1,
|
||
Token: 2,
|
||
EffectTime: 3,
|
||
FixedEffectTime: 4,
|
||
PrefixScript: 5,
|
||
PostfixScript: 6,
|
||
} as const;
|
||
|
||
/** Token 有效时间单位 */
|
||
export const EffectTimeUnit = {
|
||
Second: 1,
|
||
Minute: 2,
|
||
Hour: 3,
|
||
} as const;
|
||
|
||
/** 接口返回配置类型 */
|
||
export const InterfaceReturnConfigType = {
|
||
StatusCode: 1,
|
||
PdfLabel: 2,
|
||
ErrorMsg: 3,
|
||
} as const;
|
||
|
||
/** 标签类型 */
|
||
export const LabelType = {
|
||
Url: 1,
|
||
Base64: 2,
|
||
} as const;
|
||
|
||
/** 操作类型 */
|
||
export const OptionType = {
|
||
无: 0,
|
||
新增: 1,
|
||
删除: 2,
|
||
修改: 3,
|
||
} as const;
|
||
|
||
/** 日志列表筛选类型 */
|
||
export const LogListInputTypeEnum = {
|
||
应用: 1,
|
||
服务商: 2,
|
||
} as const;
|
||
|
||
export type ServiceProviderTypeValue =
|
||
(typeof ServiceProviderType)[keyof typeof ServiceProviderType];
|
||
export type RequestProtocolValue =
|
||
(typeof RequestProtocol)[keyof typeof RequestProtocol];
|
||
export type RequestMethodValue =
|
||
(typeof RequestMethod)[keyof typeof RequestMethod];
|
||
export type ContentTypeValue = (typeof ContentType)[keyof typeof ContentType];
|
||
export type ResponseContentTypeValue =
|
||
(typeof ResponseContentType)[keyof typeof ResponseContentType];
|
||
export type ParameterTypeValue =
|
||
(typeof ParameterType)[keyof typeof ParameterType];
|
||
export type ParameterPlaceholderValue =
|
||
(typeof ParameterPlaceholder)[keyof typeof ParameterPlaceholder];
|
||
export type FieldPositionValue =
|
||
(typeof FieldPosition)[keyof typeof FieldPosition];
|
||
export type FieldOwnerValue = (typeof FieldOwner)[keyof typeof FieldOwner];
|
||
|
||
/** 枚举注册表:便于文档生成与 AI 技能引用 */
|
||
export const ITFX_ENUM_REGISTRY = [
|
||
{
|
||
name: 'ServiceProviderType',
|
||
label: '服务商类型',
|
||
dictionaryType: ItfxDictionaryType.ServiceProviderType,
|
||
values: ServiceProviderType,
|
||
},
|
||
{
|
||
name: 'RequestProtocol',
|
||
label: '请求协议',
|
||
dictionaryType: ItfxDictionaryType.RequestProtocol,
|
||
values: RequestProtocol,
|
||
},
|
||
{
|
||
name: 'RequestMethod',
|
||
label: 'HTTP 方法',
|
||
dictionaryType: ItfxDictionaryType.RequestMethod,
|
||
values: RequestMethod,
|
||
},
|
||
{
|
||
name: 'ContentType',
|
||
label: '请求 Content-Type',
|
||
dictionaryType: ItfxDictionaryType.ContentType,
|
||
values: ContentType,
|
||
},
|
||
{
|
||
name: 'ResponseContentType',
|
||
label: '响应 Content-Type',
|
||
dictionaryType: ItfxDictionaryType.ResponseContentType,
|
||
values: ResponseContentType,
|
||
},
|
||
{
|
||
name: 'ParameterType',
|
||
label: '参数数据类型',
|
||
dictionaryType: ItfxDictionaryType.ParameterType,
|
||
values: ParameterType,
|
||
},
|
||
{
|
||
name: 'ParameterPlaceholder',
|
||
label: '固定参数占位符',
|
||
dictionaryType: ItfxDictionaryType.ParameterPlaceholder,
|
||
values: ParameterPlaceholder,
|
||
extraLabels: ParameterPlaceholderText,
|
||
},
|
||
{
|
||
name: 'ParameterParseTypeEnum',
|
||
label: '参数解析类型',
|
||
dictionaryType: ItfxDictionaryType.ParameterParseTypeEnum,
|
||
values: ParameterParseTypeEnum,
|
||
},
|
||
{
|
||
name: 'FieldPosition',
|
||
label: '字段位置',
|
||
dictionaryType: ItfxDictionaryType.FieldPosition,
|
||
values: FieldPosition,
|
||
},
|
||
{
|
||
name: 'FieldOwner',
|
||
label: '字段所属',
|
||
dictionaryType: null,
|
||
values: FieldOwner,
|
||
},
|
||
{
|
||
name: 'AuthParameterFlag',
|
||
label: '授权参数标识',
|
||
dictionaryType: ItfxDictionaryType.AuthParameterFlag,
|
||
values: AuthParameterFlag,
|
||
},
|
||
{
|
||
name: 'EffectTimeUnit',
|
||
label: 'Token 有效时间单位',
|
||
dictionaryType: ItfxDictionaryType.EffectTimeUnit,
|
||
values: EffectTimeUnit,
|
||
},
|
||
{
|
||
name: 'InterfaceReturnConfigType',
|
||
label: '接口返回配置类型',
|
||
dictionaryType: ItfxDictionaryType.InterfaceReturnConfigType,
|
||
values: InterfaceReturnConfigType,
|
||
},
|
||
{
|
||
name: 'LabelType',
|
||
label: '标签类型',
|
||
dictionaryType: ItfxDictionaryType.LabelType,
|
||
values: LabelType,
|
||
},
|
||
{
|
||
name: 'OptionType',
|
||
label: '操作类型',
|
||
dictionaryType: ItfxDictionaryType.OptionType,
|
||
values: OptionType,
|
||
},
|
||
{
|
||
name: 'LogListInputTypeEnum',
|
||
label: '日志筛选类型',
|
||
dictionaryType: ItfxDictionaryType.LogListInputTypeEnum,
|
||
values: LogListInputTypeEnum,
|
||
},
|
||
] as const;
|
||
|
||
/** 根据枚举值映射表取显示名(key 为枚举成员名) */
|
||
export function getItfxEnumLabel(
|
||
enumValues: Record<string, number>,
|
||
value: number,
|
||
): string {
|
||
const entry = Object.entries(enumValues).find(([, v]) => v === value);
|
||
return entry?.[0] ?? String(value);
|
||
}
|
||
|
||
/** 前置脚本中 FieldPosition 数值对照 */
|
||
export const FIELD_POSITION_SCRIPT_HINT = {
|
||
[FieldPosition.Header]: 'obj.FixedFieldList,FieldPosition == 1',
|
||
[FieldPosition.Body]: 'obj.OriginalInterfaceMappedInput 或 FixedFieldList Body',
|
||
[FieldPosition.Query]: 'obj.FixedFieldList Query 字段',
|
||
[FieldPosition.Url]: 'obj.FixedFieldList Url 字段',
|
||
[FieldPosition.Nothing]: '不处理',
|
||
} as const;
|