befly-shared 1.2.2 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -22,3 +22,4 @@ export * from './layouts.js';
22
22
  export * from './pickFields.js';
23
23
  export * from './scanFiles.js';
24
24
  export * from './scanViews.js';
25
+ export * from './withDefaultColumns.js';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 为表格列添加默认配置
3
+ * @param columns - 列配置数组
4
+ * @param customConfig - 自定义特殊列配置,可覆盖默认的 specialColumnConfig
5
+ * @returns 添加默认配置后的列数组
6
+ */
7
+ export function withDefaultColumns(columns, customConfig = {}) {
8
+ /**
9
+ * 特殊列配置映射
10
+ */
11
+ const specialColumnConfig = {
12
+ operation: { width: 100, align: 'center', fixed: 'right' },
13
+ state: { width: 100, align: 'center' },
14
+ id: { width: 200, align: 'center' },
15
+ ...customConfig
16
+ };
17
+ return columns.map((col) => {
18
+ const colKey = col.colKey;
19
+ // 特殊列配置
20
+ let specialConfig = specialColumnConfig[colKey];
21
+ // 以 At 或 At2 结尾的列(时间字段)
22
+ if (!specialConfig && colKey && (colKey.endsWith('At') || colKey.endsWith('At2'))) {
23
+ specialConfig = { align: 'center' };
24
+ }
25
+ return {
26
+ width: 200,
27
+ ellipsis: true,
28
+ ...specialConfig,
29
+ ...col
30
+ };
31
+ });
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly-shared",
3
- "version": "1.2.2",
3
+ "version": "1.2.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -36,5 +36,5 @@
36
36
  "merge-anything": "^6.0.6",
37
37
  "pathe": "^2.0.3"
38
38
  },
39
- "gitHead": "91c93d26c964f8390258a2ff770f533f2c6debfc"
39
+ "gitHead": "f1d08a65a7e98e89da1d42688f1ed96fd06b444d"
40
40
  }
package/src/index.ts CHANGED
@@ -25,3 +25,4 @@ export * from './layouts.js';
25
25
  export * from './pickFields.js';
26
26
  export * from './scanFiles.js';
27
27
  export * from './scanViews.js';
28
+ export * from './withDefaultColumns.js';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 为表格列添加默认配置
3
+ * @param columns - 列配置数组
4
+ * @param customConfig - 自定义特殊列配置,可覆盖默认的 specialColumnConfig
5
+ * @returns 添加默认配置后的列数组
6
+ */
7
+ export function withDefaultColumns(columns: any[], customConfig: Record<string, any> = {}): any[] {
8
+ /**
9
+ * 特殊列配置映射
10
+ */
11
+ const specialColumnConfig: Record<string, any> = {
12
+ operation: { width: 100, align: 'center', fixed: 'right' },
13
+ state: { width: 100, align: 'center' },
14
+ id: { width: 200, align: 'center' },
15
+ ...customConfig
16
+ };
17
+
18
+ return columns.map((col) => {
19
+ const colKey = col.colKey;
20
+
21
+ // 特殊列配置
22
+ let specialConfig = specialColumnConfig[colKey];
23
+
24
+ // 以 At 或 At2 结尾的列(时间字段)
25
+ if (!specialConfig && colKey && (colKey.endsWith('At') || colKey.endsWith('At2'))) {
26
+ specialConfig = { align: 'center' };
27
+ }
28
+
29
+ return {
30
+ width: 200,
31
+ ellipsis: true,
32
+ ...specialConfig,
33
+ ...col
34
+ };
35
+ });
36
+ }
@@ -28,19 +28,19 @@ export type ApiCodeType = (typeof ApiCode)[keyof typeof ApiCode];
28
28
  */
29
29
  export declare const ErrorMessages: {
30
30
  /** 未授权 */
31
- readonly UNAUTHORIZED: '请先登录';
31
+ readonly UNAUTHORIZED: "请先登录";
32
32
  /** 禁止访问 */
33
- readonly FORBIDDEN: '无访问权限';
33
+ readonly FORBIDDEN: "无访问权限";
34
34
  /** 未找到 */
35
- readonly NOT_FOUND: '资源不存在';
35
+ readonly NOT_FOUND: "资源不存在";
36
36
  /** 服务器错误 */
37
- readonly SERVER_ERROR: '服务器错误';
37
+ readonly SERVER_ERROR: "服务器错误";
38
38
  /** 参数错误 */
39
- readonly INVALID_PARAMS: '参数错误';
39
+ readonly INVALID_PARAMS: "参数错误";
40
40
  /** Token 过期 */
41
- readonly TOKEN_EXPIRED: 'Token 已过期';
41
+ readonly TOKEN_EXPIRED: "Token 已过期";
42
42
  /** Token 无效 */
43
- readonly TOKEN_INVALID: 'Token 无效';
43
+ readonly TOKEN_INVALID: "Token 无效";
44
44
  };
45
45
  /**
46
46
  * 错误消息类型
package/types/index.d.ts CHANGED
@@ -19,3 +19,4 @@ export * from './layouts.js';
19
19
  export * from './pickFields.js';
20
20
  export * from './scanFiles.js';
21
21
  export * from './scanViews.js';
22
+ export * from './withDefaultColumns.js';
package/types/regex.d.ts CHANGED
@@ -5,111 +5,111 @@
5
5
  */
6
6
  export declare const RegexAliases: {
7
7
  /** 正整数(不含0) */
8
- readonly number: '^\\d+$';
8
+ readonly number: "^\\d+$";
9
9
  /** 整数(含负数) */
10
- readonly integer: '^-?\\d+$';
10
+ readonly integer: "^-?\\d+$";
11
11
  /** 浮点数 */
12
- readonly float: '^-?\\d+(\\.\\d+)?$';
12
+ readonly float: "^-?\\d+(\\.\\d+)?$";
13
13
  /** 正整数(不含0) */
14
- readonly positive: '^[1-9]\\d*$';
14
+ readonly positive: "^[1-9]\\d*$";
15
15
  /** 负整数 */
16
- readonly negative: '^-\\d+$';
16
+ readonly negative: "^-\\d+$";
17
17
  /** 零 */
18
- readonly zero: '^0$';
18
+ readonly zero: "^0$";
19
19
  /** 纯字母 */
20
- readonly word: '^[a-zA-Z]+$';
20
+ readonly word: "^[a-zA-Z]+$";
21
21
  /** 字母和数字 */
22
- readonly alphanumeric: '^[a-zA-Z0-9]+$';
22
+ readonly alphanumeric: "^[a-zA-Z0-9]+$";
23
23
  /** 字母、数字和下划线 */
24
- readonly alphanumeric_: '^[a-zA-Z0-9_]+$';
24
+ readonly alphanumeric_: "^[a-zA-Z0-9_]+$";
25
25
  /** 字母、数字、下划线和短横线 */
26
- readonly alphanumericDash_: '^[a-zA-Z0-9_-]+$';
26
+ readonly alphanumericDash_: "^[a-zA-Z0-9_-]+$";
27
27
  /** 小写字母 */
28
- readonly lowercase: '^[a-z]+$';
28
+ readonly lowercase: "^[a-z]+$";
29
29
  /** 大写字母 */
30
- readonly uppercase: '^[A-Z]+$';
30
+ readonly uppercase: "^[A-Z]+$";
31
31
  /** 纯中文 */
32
- readonly chinese: '^[\\u4e00-\\u9fa5]+$';
32
+ readonly chinese: "^[\\u4e00-\\u9fa5]+$";
33
33
  /** 中文和字母 */
34
- readonly chineseWord: '^[\\u4e00-\\u9fa5a-zA-Z]+$';
34
+ readonly chineseWord: "^[\\u4e00-\\u9fa5a-zA-Z]+$";
35
35
  /** 邮箱地址 */
36
- readonly email: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$';
36
+ readonly email: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
37
37
  /** 中国大陆手机号 */
38
- readonly phone: '^1[3-9]\\d{9}$';
38
+ readonly phone: "^1[3-9]\\d{9}$";
39
39
  /** 固定电话(区号-号码) */
40
- readonly telephone: '^0\\d{2,3}-?\\d{7,8}$';
40
+ readonly telephone: "^0\\d{2,3}-?\\d{7,8}$";
41
41
  /** URL 地址 */
42
- readonly url: '^https?://';
42
+ readonly url: "^https?://";
43
43
  /** IPv4 地址 */
44
- readonly ip: '^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$';
44
+ readonly ip: "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$";
45
45
  /** IPv6 地址 */
46
- readonly ipv6: '^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$';
46
+ readonly ipv6: "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$";
47
47
  /** 域名 */
48
- readonly domain: '^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,}$';
48
+ readonly domain: "^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,}$";
49
49
  /** UUID */
50
- readonly uuid: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$';
50
+ readonly uuid: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
51
51
  /** 十六进制字符串 */
52
- readonly hex: '^[0-9a-fA-F]+$';
52
+ readonly hex: "^[0-9a-fA-F]+$";
53
53
  /** Base64 编码 */
54
- readonly base64: '^[A-Za-z0-9+/=]+$';
54
+ readonly base64: "^[A-Za-z0-9+/=]+$";
55
55
  /** MD5 哈希 */
56
- readonly md5: '^[a-f0-9]{32}$';
56
+ readonly md5: "^[a-f0-9]{32}$";
57
57
  /** SHA1 哈希 */
58
- readonly sha1: '^[a-f0-9]{40}$';
58
+ readonly sha1: "^[a-f0-9]{40}$";
59
59
  /** SHA256 哈希 */
60
- readonly sha256: '^[a-f0-9]{64}$';
60
+ readonly sha256: "^[a-f0-9]{64}$";
61
61
  /** 日期 YYYY-MM-DD */
62
- readonly date: '^\\d{4}-\\d{2}-\\d{2}$';
62
+ readonly date: "^\\d{4}-\\d{2}-\\d{2}$";
63
63
  /** 时间 HH:MM:SS */
64
- readonly time: '^\\d{2}:\\d{2}:\\d{2}$';
64
+ readonly time: "^\\d{2}:\\d{2}:\\d{2}$";
65
65
  /** ISO 日期时间 */
66
- readonly datetime: '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}';
66
+ readonly datetime: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}";
67
67
  /** 年份 */
68
- readonly year: '^\\d{4}$';
68
+ readonly year: "^\\d{4}$";
69
69
  /** 月份 01-12 */
70
- readonly month: '^(0[1-9]|1[0-2])$';
70
+ readonly month: "^(0[1-9]|1[0-2])$";
71
71
  /** 日期 01-31 */
72
- readonly day: '^(0[1-9]|[12]\\d|3[01])$';
72
+ readonly day: "^(0[1-9]|[12]\\d|3[01])$";
73
73
  /** 变量名 */
74
- readonly variable: '^[a-zA-Z_][a-zA-Z0-9_]*$';
74
+ readonly variable: "^[a-zA-Z_][a-zA-Z0-9_]*$";
75
75
  /** 常量名(全大写) */
76
- readonly constant: '^[A-Z][A-Z0-9_]*$';
76
+ readonly constant: "^[A-Z][A-Z0-9_]*$";
77
77
  /** 包名(小写+连字符) */
78
- readonly package: '^[a-z][a-z0-9-]*$';
78
+ readonly package: "^[a-z][a-z0-9-]*$";
79
79
  /** 中国身份证号(18位) */
80
- readonly idCard: '^\\d{17}[\\dXx]$';
80
+ readonly idCard: "^\\d{17}[\\dXx]$";
81
81
  /** 护照号 */
82
- readonly passport: '^[a-zA-Z0-9]{5,17}$';
82
+ readonly passport: "^[a-zA-Z0-9]{5,17}$";
83
83
  /** 银行卡号(16-19位数字) */
84
- readonly bankCard: '^\\d{16,19}$';
84
+ readonly bankCard: "^\\d{16,19}$";
85
85
  /** 微信号(6-20位,字母开头,可包含字母、数字、下划线、减号) */
86
- readonly wechat: '^[a-zA-Z][a-zA-Z0-9_-]{5,19}$';
86
+ readonly wechat: "^[a-zA-Z][a-zA-Z0-9_-]{5,19}$";
87
87
  /** QQ号(5-11位数字,首位非0) */
88
- readonly qq: '^[1-9]\\d{4,10}$';
88
+ readonly qq: "^[1-9]\\d{4,10}$";
89
89
  /** 支付宝账号(手机号或邮箱) */
90
- readonly alipay: '^(1[3-9]\\d{9}|[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})$';
90
+ readonly alipay: "^(1[3-9]\\d{9}|[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})$";
91
91
  /** 用户名(4-20位,字母开头,可包含字母、数字、下划线) */
92
- readonly username: '^[a-zA-Z][a-zA-Z0-9_]{3,19}$';
92
+ readonly username: "^[a-zA-Z][a-zA-Z0-9_]{3,19}$";
93
93
  /** 昵称(2-20位,支持中文、字母、数字) */
94
- readonly nickname: '^[\\u4e00-\\u9fa5a-zA-Z0-9]{2,20}$';
94
+ readonly nickname: "^[\\u4e00-\\u9fa5a-zA-Z0-9]{2,20}$";
95
95
  /** 弱密码(至少6位) */
96
- readonly passwordWeak: '^.{6,}$';
96
+ readonly passwordWeak: "^.{6,}$";
97
97
  /** 中等密码(至少8位,包含字母和数字) */
98
- readonly passwordMedium: '^(?=.*[a-zA-Z])(?=.*\\d).{8,}$';
98
+ readonly passwordMedium: "^(?=.*[a-zA-Z])(?=.*\\d).{8,}$";
99
99
  /** 强密码(至少8位,包含大小写字母、数字和特殊字符) */
100
- readonly passwordStrong: '^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*]).{8,}$';
100
+ readonly passwordStrong: "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*]).{8,}$";
101
101
  /** 车牌号(新能源+普通) */
102
- readonly licensePlate: '^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$';
102
+ readonly licensePlate: "^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$";
103
103
  /** 邮政编码 */
104
- readonly postalCode: '^\\d{6}$';
104
+ readonly postalCode: "^\\d{6}$";
105
105
  /** 版本号(语义化版本) */
106
- readonly semver: '^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.]+)?(\\+[a-zA-Z0-9.]+)?$';
106
+ readonly semver: "^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.]+)?(\\+[a-zA-Z0-9.]+)?$";
107
107
  /** 颜色值(十六进制) */
108
- readonly colorHex: '^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$';
108
+ readonly colorHex: "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$";
109
109
  /** 空字符串 */
110
- readonly empty: '^$';
110
+ readonly empty: "^$";
111
111
  /** 非空 */
112
- readonly notempty: '.+';
112
+ readonly notempty: ".+";
113
113
  };
114
114
  /**
115
115
  * 正则别名类型
@@ -27,8 +27,6 @@ export interface FieldDefinition {
27
27
  index: boolean;
28
28
  /** 是否唯一 */
29
29
  unique: boolean;
30
- /** 字段注释 */
31
- comment: string;
32
30
  /** 是否允许为空 */
33
31
  nullable: boolean;
34
32
  /** 是否无符号(仅 number 类型) */
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 为表格列添加默认配置
3
+ * @param columns - 列配置数组
4
+ * @param customConfig - 自定义特殊列配置,可覆盖默认的 specialColumnConfig
5
+ * @returns 添加默认配置后的列数组
6
+ */
7
+ export declare function withDefaultColumns(columns: any[], customConfig?: Record<string, any>): any[];