feat:提交
This commit is contained in:
31
tests/dev1/dataHandle/common/decorators/json.ts
Normal file
31
tests/dev1/dataHandle/common/decorators/json.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'reflect-metadata'
|
||||
|
||||
export const jsonOptionMataDataKey = Symbol('JsonOptions')
|
||||
|
||||
export enum JsonOptionType
|
||||
{
|
||||
Ignore = 0,
|
||||
Property = 1,
|
||||
}
|
||||
|
||||
export class JsonOption
|
||||
{
|
||||
constructor(type: JsonOptionType, data: any = null)
|
||||
{
|
||||
this.type = type
|
||||
this.data = data
|
||||
}
|
||||
|
||||
type: JsonOptionType
|
||||
data: any
|
||||
}
|
||||
|
||||
export function jsonProperty(key: string | number)
|
||||
{
|
||||
return Reflect.metadata(jsonOptionMataDataKey, new JsonOption(JsonOptionType.Property, { key }))
|
||||
}
|
||||
|
||||
export function jsonIgnore()
|
||||
{
|
||||
return Reflect.metadata(jsonOptionMataDataKey, new JsonOption(JsonOptionType.Ignore))
|
||||
}
|
39
tests/dev1/dataHandle/common/decorators/model.ts
Normal file
39
tests/dev1/dataHandle/common/decorators/model.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'reflect-metadata'
|
||||
|
||||
const displayMetadataKey = Symbol('display')
|
||||
|
||||
export function display(
|
||||
name: string,
|
||||
group: string = '',
|
||||
type: string = 'color',
|
||||
)
|
||||
{
|
||||
return Reflect.metadata(displayMetadataKey, {
|
||||
name,
|
||||
group,
|
||||
type,
|
||||
})
|
||||
}
|
||||
|
||||
export function getDisplayInfo(target: any)
|
||||
{
|
||||
let keys = Object.getOwnPropertyNames(target)
|
||||
let list = []
|
||||
keys.forEach((key) =>
|
||||
{
|
||||
let info = <{ name: string; group: string; type: number }>(
|
||||
Reflect.getMetadata(displayMetadataKey, target, key)
|
||||
)
|
||||
if (info)
|
||||
{
|
||||
info
|
||||
list.push({
|
||||
prop: key,
|
||||
name: info.name,
|
||||
group: info.group,
|
||||
type: info.type,
|
||||
})
|
||||
}
|
||||
})
|
||||
return list
|
||||
}
|
Reference in New Issue
Block a user