@yqg/simple 1.0.1-beta.1.0 → 1.0.1-beta.1.2

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/README.md CHANGED
@@ -63,8 +63,35 @@ Vue.component('yqg-simple-form', YqgSimpleForm)
63
63
 
64
64
  ## 混入 (Mixins)
65
65
 
66
+ ### 引入方式
67
+
68
+ ```javascript
69
+ import { table, modal, watermark } from '@yqg/simple/mixin'
70
+
71
+ export default {
72
+ mixins: [table, modal, watermark],
73
+ // ...
74
+ }
75
+ ```
76
+
77
+ ### 可用的混入
78
+
79
+ - `table` - 表格混入,提供表格相关的通用方法
80
+ - `tableSelection` - 表格选择混入
81
+ - `modal` - 模态框混入,提供模态框相关的通用方法
82
+ - `watermark` - 水印混入,提供水印功能
83
+ - `commonTable` - 通用表格混入
84
+ - `clientTable` - 客户端表格混入
85
+ - `enumType` - 枚举类型混入
86
+ - `cardList` - 卡片列表混入
87
+
88
+ ### 按需引入
89
+
66
90
  ```javascript
67
- import { table, modal, watermark } from '@yqg/simple'
91
+ // 引入单个混入
92
+ import table from '@yqg/simple/src/mixin/table'
93
+ import modal from '@yqg/simple/src/mixin/modal'
94
+ import watermark from '@yqg/simple/src/mixin/watermark'
68
95
 
69
96
  export default {
70
97
  mixins: [table, modal, watermark],
@@ -92,9 +119,8 @@ export default {
92
119
  ```javascript
93
120
  import { util, formatMap, object, constant } from '@yqg/simple'
94
121
 
95
- // 使用加密工具
96
- const encrypted = util.aesEncrypt('secret message')
97
- const decrypted = util.aesDecrypt(encrypted)
122
+ // 使用字符串工具
123
+ const snakeCase = util.camelCaseToUnderscore('userName') // 'user_name'
98
124
 
99
125
  // 使用对象工具
100
126
  const value = object.pickValue(data, 'user.name')
@@ -109,10 +135,9 @@ const formatted = formatMap.formatValue(value, options)
109
135
  支持通过子路径按需引入工具函数,减少打包体积:
110
136
 
111
137
  ```javascript
112
- // 加密和字符串工具
113
- import { aesEncrypt, aesDecrypt, camelCaseToUnderscore } from '@yqg/simple/util/tool'
138
+ // 字符串工具
139
+ import { camelCaseToUnderscore } from '@yqg/simple/util/tool'
114
140
 
115
- const encrypted = aesEncrypt('secret message')
116
141
  const snakeCase = camelCaseToUnderscore('userName') // 'user_name'
117
142
 
118
143
  // 对象操作工具
@@ -166,10 +191,10 @@ const data = myStorage.get()
166
191
  所有工具函数都提供完整的 TypeScript 类型声明,开发时会有智能提示:
167
192
 
168
193
  ```typescript
169
- import { aesEncrypt, pickValue, merge } from '@yqg/simple/util'
194
+ import { camelCaseToUnderscore, pickValue, merge } from '@yqg/simple/util'
170
195
 
171
- // ✅ 编辑器自动提示:aesEncrypt(message: string, key?: string): string
172
- const encrypted = aesEncrypt('hello')
196
+ // ✅ 编辑器自动提示:camelCaseToUnderscore(camelStr: string): string
197
+ const snakeCase = camelCaseToUnderscore('userName')
173
198
 
174
199
  // ✅ 编辑器自动提示:pickValue<T = any>(obj: any, keyString: string): T | undefined
175
200
  const value = pickValue<number>({ a: { b: 1 } }, 'a.b')
@@ -180,10 +205,8 @@ const merged = merge({ a: 1 }, { b: 2 })
180
205
 
181
206
  ### 工具函数 API
182
207
 
183
- #### 加密工具 (`util/tool`)
208
+ #### 字符串工具 (`util/tool`)
184
209
 
185
- - `aesEncrypt(message: string, key?: string): string` - AES 加密
186
- - `aesDecrypt(ciphertext: string, key?: string): string` - AES 解密
187
210
  - `camelCaseToUnderscore(camelStr: string): string` - 驼峰转下划线
188
211
 
189
212
  #### 对象工具 (`util/object`)
@@ -255,12 +278,210 @@ class Storage {
255
278
 
256
279
  ## 常量
257
280
 
281
+ 组件库提供了丰富的常量定义,包括表单字段定义、表格配置等。
282
+
283
+ ### 引入方式
284
+
285
+ #### 从主入口引入
286
+
258
287
  ```javascript
259
- import * as constant from '@yqg/simple/constant'
288
+ import { constant } from '@yqg/simple'
289
+
290
+ // 使用
291
+ const dateDef = constant.dateTimeDef
292
+ const requiredField = constant.required({ field: 'name', label: '姓名' })
293
+ ```
260
294
 
261
- // 或按需引入
262
- import * as commonFields from '@yqg/simple/constant/common-fields'
263
- import * as fields from '@yqg/simple/constant/fields'
295
+ #### 按需引入(推荐)
296
+
297
+ ```javascript
298
+ // 引入 fields.ts(包含 common-fields 的所有导出)
299
+ import {
300
+ extendsDefValue,
301
+ dateTimeDayStartDef,
302
+ dateTimeDayEndDef,
303
+ // 以下来自 common-fields
304
+ dateTimeDef,
305
+ required,
306
+ merge,
307
+ id,
308
+ timeCreate,
309
+ timeUpdate,
310
+ remark
311
+ } from '@yqg/simple/constant/fields'
312
+
313
+ // 引入 common-fields
314
+ import {
315
+ dateTimeDef,
316
+ required,
317
+ merge,
318
+ primaryStaticProps,
319
+ successStaticProps,
320
+ warningStaticProps,
321
+ fixedLeft,
322
+ fixedRight,
323
+ staticComp,
324
+ blockItem,
325
+ hiddenItem,
326
+ id,
327
+ time,
328
+ timeCreate,
329
+ timeUpdate,
330
+ remark
331
+ } from '@yqg/simple/constant/common-fields'
332
+
333
+ // 引入表格常量
334
+ import { defaultPagination } from '@yqg/simple/constant/table'
335
+ ```
336
+
337
+ ### 常用常量 API
338
+
339
+ #### fields 相关 (`constant/fields`)
340
+
341
+ **字段定义辅助函数:**
342
+
343
+ - `extendsDefValue(options)` - 扩展 DefValue 组件
344
+ ```javascript
345
+ const customDef = extendsDefValue({
346
+ props: { showTime: true },
347
+ filter: 'dateTime'
348
+ })
349
+ ```
350
+
351
+ - `dateTimeDayStartDef` - 日期时间定义(默认 00:00:00)
352
+ ```javascript
353
+ // 用于搜索开始时间
354
+ const startTimeDef = {
355
+ ...dateTimeDayStartDef,
356
+ field: 'startTime',
357
+ label: '开始时间'
358
+ }
359
+ ```
360
+
361
+ - `dateTimeDayEndDef` - 日期时间定义(默认 23:59:59)
362
+ ```javascript
363
+ // 用于搜索结束时间
364
+ const endTimeDef = {
365
+ ...dateTimeDayEndDef,
366
+ field: 'endTime',
367
+ label: '结束时间'
368
+ }
369
+ ```
370
+
371
+ #### common-fields 相关 (`constant/common-fields`)
372
+
373
+ **辅助函数:**
374
+
375
+ - `merge<T>(...args)` - 合并字段定义
376
+ ```javascript
377
+ const customField = merge(dateTimeDef, { required: true, label: '创建时间' })
378
+ ```
379
+
380
+ - `required(def)` - 标记字段为必填
381
+ ```javascript
382
+ const nameField = required({ field: 'name', label: '姓名' })
383
+ ```
384
+
385
+ - `fixedLeft(def, width?)` - 固定列到左侧
386
+ ```javascript
387
+ const idColumn = fixedLeft(id, 100)
388
+ ```
389
+
390
+ - `fixedRight(def, width?)` - 固定列到右侧
391
+ ```javascript
392
+ const opColumn = fixedRight(op, 150)
393
+ ```
394
+
395
+ - `staticComp(def)` - 将字段转为静态组件(只读)
396
+ ```javascript
397
+ const readOnlyName = staticComp({ field: 'name', label: '姓名' })
398
+ ```
399
+
400
+ **样式定义:**
401
+
402
+ - `primaryStaticProps` - 主色文本样式
403
+ - `successStaticProps` - 成功色文本样式
404
+ - `warningStaticProps` - 警告色文本样式
405
+ - `sizeLongProps` - 长宽度输入框样式
406
+
407
+ **布局定义:**
408
+
409
+ - `blockItem` - 块级表单项
410
+ - `hiddenItem` - 隐藏表单项
411
+ - `rangeItem` - 范围表单项
412
+
413
+ **常用字段定义:**
414
+
415
+ - `dateTimeDef` - 日期时间字段
416
+ ```javascript
417
+ { type: 'date', props: { showTime: true }, filter: 'dateTime' }
418
+ ```
419
+
420
+ - `id` - ID 字段
421
+ ```javascript
422
+ { field: 'id', label: 'ID' }
423
+ ```
424
+
425
+ - `time` - 时间字段
426
+ - `timeCreate` - 创建时间字段
427
+ - `timeUpdate` - 更新时间字段
428
+ - `timeCreated` - 创建时间字段(别名)
429
+ - `timeUpdated` - 更新时间字段(别名)
430
+ - `remark` - 备注字段(文本域)
431
+ - `op` - 操作列字段
432
+
433
+ **七牛上传字段:**
434
+
435
+ - `qiniuFileDef` - 七牛文件上传字段
436
+ - `qiniuImageDef` - 七牛图片上传字段
437
+
438
+ ### 使用示例
439
+
440
+ ```javascript
441
+ import {
442
+ merge,
443
+ required,
444
+ dateTimeDayStartDef,
445
+ dateTimeDayEndDef,
446
+ id,
447
+ timeCreate,
448
+ timeUpdate,
449
+ remark,
450
+ fixedLeft,
451
+ fixedRight
452
+ } from '@yqg/simple/constant/fields'
453
+
454
+ export default {
455
+ data() {
456
+ return {
457
+ // 表单字段定义
458
+ formFields: [
459
+ required(merge(id, { label: '用户ID' })),
460
+ required({ field: 'name', label: '姓名' }),
461
+ {
462
+ ...dateTimeDayStartDef,
463
+ field: 'startTime',
464
+ label: '开始时间'
465
+ },
466
+ {
467
+ ...dateTimeDayEndDef,
468
+ field: 'endTime',
469
+ label: '结束时间'
470
+ },
471
+ remark
472
+ ],
473
+
474
+ // 表格列定义
475
+ tableColumns: [
476
+ fixedLeft(id, 80),
477
+ { field: 'name', label: '姓名' },
478
+ timeCreate,
479
+ timeUpdate,
480
+ fixedRight({ field: 'op', label: '操作' }, 120)
481
+ ]
482
+ }
483
+ }
484
+ }
264
485
  ```
265
486
 
266
487
  ## 文档
@@ -1,6 +1,6 @@
1
1
  import type { Def } from '@yqg/type';
2
- import type { CommonObject } from './common-fields.ts';
3
- export * from './common-fields.ts';
2
+ import type { CommonObject } from './common-fields';
3
+ export * from './common-fields';
4
4
  export declare const extendsDefValue: (options: CommonObject) => CommonObject;
5
5
  export declare const dateTimeDayStartDef: Def;
6
6
  export declare const dateTimeDayEndDef: Def;