Skip to content

Commit

Permalink
Merge pull request #10 from HammCn/dev
Browse files Browse the repository at this point in the history
release(v2.3.4): 发布了`v2.3.4`版本
  • Loading branch information
HammCn authored Sep 4, 2024
2 parents 388dae5 + e8e9279 commit 0126d57
Show file tree
Hide file tree
Showing 26 changed files with 338 additions and 159 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# AirPower4T 版本发布日志


## v2.3.4

### 🎉 Features:

- feat(Keys): 支持了一个键盘值枚举
- feat(Constant): 支持了一个AirConstant静态常量类

### 🐞 Bug fixes:

- fix(Constant): 使用常量替换树结构中的硬编码字符串
- fix(Validator): 优化了验证器的类型和生成逻辑
- fix(DateTime): 修复AirDateTime对象类型检查错误
- fix(Table): 更新AirTable字段配置中的默认图像大小
- fix(Entity): 简化AirEntity中的copyExposeId方法

## v2.3.3

### 🎉 Features:
Expand Down
9 changes: 4 additions & 5 deletions base/AirEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Dictionary, Field, Type } from '../decorator/Custom'
import { AirModel } from './AirModel'
import { Table } from '../decorator/TableField'
import { AirDisableDictionary } from '../model/AirDisableDictionary'
import { AirConstant } from '../config/AirConstant'

/**
* # 实体超类
Expand Down Expand Up @@ -39,28 +40,26 @@ export class AirEntity extends AirModel {
}
}

private static readonly ID = 'id'

/**
* ## 复制一个只包含 `ID` 的实体
* @returns 仅包含ID的实体
*/
copyExposeId() {
return this.copy()
.expose(AirEntity.ID)
.exposeId()
}

/**
* ## 只暴露 `ID`
*/
exposeId() {
return this.expose(AirEntity.ID)
return this.expose(AirConstant.ID)
}

/**
* ## 排除 `ID`
*/
excludeId() {
return this.exclude(AirEntity.ID)
return this.exclude(AirConstant.ID)
}
}
3 changes: 2 additions & 1 deletion base/AirEnum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AirConstant } from '../config/AirConstant'
import { AirColor } from '../enum/AirColor'
import { IDictionary } from '../interface/IDictionary'
import { AirDictionaryArray } from '../model/extend/AirDictionaryArray'
Expand Down Expand Up @@ -66,7 +67,7 @@ export class AirEnum<K extends AirEnumKey = number> implements IDictionary {
* @param key `Key`
* @param defaultLabel `可选` 默认 `Label`
*/
static getLabel(key: AirEnumKey, defaultLabel = '-'): string {
static getLabel(key: AirEnumKey, defaultLabel = AirConstant.HYPHEN): string {
return this.get(key)?.label || defaultLabel
}

Expand Down
5 changes: 3 additions & 2 deletions base/AirModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-continue */
import { AirConstant } from '../config/AirConstant'
import { AirFormFieldConfig } from '../config/AirFormFieldConfig'
import { AirSearchFieldConfig } from '../config/AirSearchFieldConfig'
import { AirTableFieldConfig } from '../config/AirTableFieldConfig'
Expand Down Expand Up @@ -105,7 +106,7 @@ export class AirModel {
let fieldData = json[
(!getNoPrefix(instance, fieldKey)
? getFieldPrefix(instance)
: ''
: AirConstant.EMPTY_STRING
)
+ (fieldAliasName || fieldKey)]
if (fieldData === undefined) {
Expand Down Expand Up @@ -139,7 +140,7 @@ export class AirModel {
(instance as IJson)[fieldKey] = fieldValueList
continue
}
if (defaultValue !== undefined && (fieldData === undefined || fieldData === null || fieldData === '')) {
if (defaultValue !== undefined && (fieldData === undefined || fieldData === null || fieldData === AirConstant.EMPTY_STRING)) {
// 如果有默认值 则先给上默认值
(instance as IJson)[fieldKey] = defaultValue
}
Expand Down
4 changes: 3 additions & 1 deletion config/AirApi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AirConstant } from './AirConstant'

/**
* # `API` 兼容类
* @author Hamm.cn
Expand All @@ -10,7 +12,7 @@ export class AirApi {
*/
public static getStorage(key: string): string {
const value = localStorage.getItem(key)
return value ? value.toString() : ''
return value ? value.toString() : AirConstant.EMPTY_STRING
}

/**
Expand Down
11 changes: 6 additions & 5 deletions config/AirConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AirUserEntity } from '../model/entity/AirUserEntity'
import { ClassConstructor } from '../type/ClassConstructor'
import { AirCodeNumber, AirMoneyDirection } from '../type/AirType'
import { AirApi } from './AirApi'
import { AirConstant } from './AirConstant'

/**
* # `AirPower` 全局配置
Expand All @@ -22,7 +23,7 @@ export class AirConfig {
/**
* ## `AirPower` 版本号
*/
static readonly version = 'v2.3.3'
static readonly version = 'v2.3.4'

/**
* ## `AppKey`
Expand All @@ -39,7 +40,7 @@ export class AirConfig {
* ## 项目名称
* 会显示在浏览器标题上
*/
static product = ''
static product = AirConstant.EMPTY_STRING

/**
* ## 接口根地址
Expand Down Expand Up @@ -309,7 +310,7 @@ export class AirConfig {
* ## 默认树结构配置数据
*/
static treeProps: INormalTreeProps = {
children: 'children',
children: AirConstant.CHILDREN,
label: 'name',
}

Expand All @@ -333,7 +334,7 @@ export class AirConfig {
* ## 默认的表格空数据兜底字符串
* `@Table` 装饰器中可以单独配置 `emptyValue`,
*/
static tableEmptyValue = '-'
static tableEmptyValue = AirConstant.HYPHEN

/**
* ## 表格是否默认开启禁用和启用按钮
Expand All @@ -344,7 +345,7 @@ export class AirConfig {
* ## 默认的表格数组显示分割字符
* `@Table` 装饰器中可以单独配置 `arraySplitor`
*/
static arraySplitor = ','
static arraySplitor = AirConstant.COMMA

/**
* ## 隐藏表格序号列
Expand Down
137 changes: 137 additions & 0 deletions config/AirConstant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* # `AirPower` 内置常量
*
* @author Hamm.cn
*/
export class AirConstant {
/**
* ## `id`
*/
static readonly ID = 'id'

/**
* ## `http://`
*/
static readonly PREFIX_HTTP = 'http://'

/**
* ## `https://`
*/
static readonly PREFIX_HTTPS = 'https://'

/**
* ## 空字符串
*/
static readonly EMPTY_STRING = ''

/**
* ## `Content-Type`
*/
static readonly CONTENT_TYPE = 'Content-Type'

/**
* ## 半角问号 `?`
*/
static readonly QUESTION_MARK = '?'

/**
* ## 连接符号 `&`
*/
static readonly AND_MARK = '&'

/**
* ## `AirModel`
*/
static readonly AIR_MODEL = 'AirModel'

/**
* ## 下划线 `_`
*/
static readonly UNDER_LINE = '_'

/**
* ## 默认进制
*/
static readonly DEFAULT_RADIX = 10

/**
* ## `.` 点
*/
static readonly DOT = '.'

/**
* ## `children`
*/
static readonly CHILDREN = 'children'

/**
* ## `'0'`
*/
static readonly ZERO_STRING = '0'

/**
* ## 半角逗号 `,`
*/
static readonly COMMA = ','

/**
* ## 横线 `-`
*/
static readonly HYPHEN = '-'

/**
* ## 时间进制
*/
static readonly TIME_RADIX = 60

/**
* ## 千
*/
static readonly THOUSAND = 1000

/**
* ## 1024
* 😄
*/
static readonly ONE_ZERO_TWO_FOUR = 1024

/**
* ## 每月最大天数
*/
static readonly DAY_OF_MONTH = 31

/**
* ## 每年月份
*/
static readonly MONTH_OF_YEAR = 12

/**
* ## 每年天数
*/
static readonly DAY_OF_YEAR = 365

/**
* ## 每周天数
*/
static readonly DAY_OF_WEEK = 7

/**
* ## 每年平均周
*/
static readonly WEEK_OF_YEAR = 52

/**
* ## 每月平均周
*/
static readonly WEEK_OF_MONTH = 4

/**
* ## 每天秒数
*/
static readonly SECONDS_OF_DAY = 86400

/**
* ## 一世纪年数
*/
static readonly YEARS_OF_CENTURY = 100
}
12 changes: 8 additions & 4 deletions config/AirGlobal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AirConfig } from './AirConfig'
import { IJson } from '../interface/IJson'
import { AirStore } from '../store/AirStore'
import { AirKeys } from '../enum/AirKeys'

/**
* # 一些全局使用的扩展方法
Expand All @@ -22,26 +23,29 @@ Window.prototype.airConfig = () => {
// eslint-disable-next-line no-console
console.log(airConfig)
}

const CONTROL_KEYS: string[] = [AirKeys.META, AirKeys.ALT]

let controlKeyDownTimer: number
document.onkeydown = (e: KeyboardEvent) => {
if (e.key === 'Meta' || e.key === 'Alt') {
if (CONTROL_KEYS.includes(e.key)) {
clearTimeout(controlKeyDownTimer)
AirStore().controlKeyDown = true
controlKeyDownTimer = setTimeout(() => {
AirStore().controlKeyDown = false
}, 5000)
}
if (e.key === 'Escape') {
if (e.key === AirKeys.ESC) {
AirStore().escKeyDown = true
}
}

document.onkeyup = (e: KeyboardEvent) => {
if (e.key === 'Meta' || e.key === 'Alt') {
if (CONTROL_KEYS.includes(e.key)) {
AirStore().controlKeyDown = false
clearTimeout(controlKeyDownTimer)
}
if (e.key === 'Escape') {
if (e.key === AirKeys.ESC) {
AirStore().escKeyDown = false
}
}
4 changes: 2 additions & 2 deletions config/AirTableFieldConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class AirTableFieldConfig extends AirFieldConfig implements ITableFieldCo

image = false

imageWidth = 60
imageWidth = 30

imageHeight = 60
imageHeight = 30

imageRadius = '10px'

Expand Down
5 changes: 3 additions & 2 deletions decorator/Custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import { AirEnum } from '../base/AirEnum'
import { AirModel } from '../base/AirModel'
import { AirConstant } from '../config/AirConstant'
import { AirDecorator } from '../helper/AirDecorator'
import { IJson } from '../interface/IJson'
import { AirDictionaryArray } from '../model/extend/AirDictionaryArray'
Expand Down Expand Up @@ -247,7 +248,7 @@ export function FieldPrefix(prefix: string) {
* @param target 目标类
*/
export function getFieldPrefix(target: AirDecoratorTarget): string {
return AirDecorator.getClassConfig(target, FIELD_PREFIX_KEY) || ''
return AirDecorator.getClassConfig(target, FIELD_PREFIX_KEY) || AirConstant.EMPTY_STRING
}

/**
Expand All @@ -269,5 +270,5 @@ export function Alias(alias: string) {
* @param key 属性名
*/
export function getAlias(target: AirDecoratorTarget, key: string): string {
return AirDecorator.getFieldConfig(target, key, ALIAS_KEY) || ''
return AirDecorator.getFieldConfig(target, key, ALIAS_KEY) || AirConstant.EMPTY_STRING
}
10 changes: 10 additions & 0 deletions enum/AirKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable no-unused-vars */
/**
* # 常见键盘值
* @author Hamm.cn
*/
export enum AirKeys {
META = 'Meta',
ALT = 'Alt',
ESC = 'Escape'
}
Loading

0 comments on commit 0126d57

Please sign in to comment.