@yeepay/yee-boss-ui 0.1.20 → 0.1.22

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
@@ -12,13 +12,11 @@
12
12
  - `PlatformConfigProvider`。
13
13
  - `usePlatformTheme` 只读主题上下文。
14
14
  - `YeePage` 页面容器。
15
- - `YeeForm` Schema 查询表单。
16
- - `useYeeGrid` 与 `gridApi/formApi`。
15
+ - `useYeeGrid` 与内置 Schema 查询区。
17
16
  - `YeeDescriptions` 配置驱动的详情展示。
18
17
  - `YeeEllipsisText` 单行/多行省略文本与按需完整提示。
19
18
  - `YeeFileUpload` 业务无关的文件选择与上传生命周期。
20
19
  - `YeeModal` 统一的 Modal / Drawer 容器。
21
- - `YeeSelect` 带完整文案提示的选择器。
22
20
  - `YeeAppShell`、`YeeHeader`、`YeeSidebar` 应用壳层布局。
23
21
  - `YeeMenu` 路由菜单样式与 `YeeTabs` 标签栏样式。
24
22
  - Tailwind CSS 语义主题 preset。
@@ -73,7 +71,7 @@ import '@yeepay/yee-boss-ui/style.css'
73
71
  createApp(App).use(YeeBossUI).mount('#app')
74
72
  ```
75
73
 
76
- 组件库会自动注册 `YeeAppShell`、`YeeDescriptions`、`YeeEllipsisText`、`YeeFileUpload`、`YeeForm`、`YeeModal`、`YeePage`、`YeeSelect` 以及应用壳层组件。`useYeeGrid` 仍按组合式 API 使用,首次调用时会由组件库自动加载 Grid 样式。
74
+ 组件库会自动注册 `YeeAppShell`、`YeeDescriptions`、`YeeEllipsisText`、`YeeFileUpload`、`YeeModal`、`YeePage` 以及应用壳层组件。`useYeeGrid` 仍按组合式 API 使用,首次调用时会由组件库自动加载 Grid 样式;查询区只在 Grid 内部渲染。
77
75
 
78
76
  如果只希望在脚本中使用全部导出,也可以从包根入口统一导入:
79
77
 
@@ -84,12 +82,10 @@ import {
84
82
  YeeDescriptions,
85
83
  YeeEllipsisText,
86
84
  YeeFileUpload,
87
- YeeForm,
88
- YeeFormApi,
85
+ YeeGridFormApi,
89
86
  YeeHeader,
90
87
  YeeModal,
91
88
  YeePage,
92
- YeeSelect,
93
89
  YeeSidebar,
94
90
  YeeTabs,
95
91
  useYeeGrid,
@@ -103,13 +99,32 @@ import {
103
99
  页面只使用少量能力、需要减少初始体积时,从根入口只导入实际使用的组件:
104
100
 
105
101
  ```ts
106
- import { YeeModal, YeePage, YeeSelect } from '@yeepay/yee-boss-ui'
107
- import type { YeeSelectOption } from '@yeepay/yee-boss-ui'
102
+ import { YeeModal, YeePage } from '@yeepay/yee-boss-ui'
108
103
  import '@yeepay/yee-boss-ui/style.css'
109
104
  ```
110
105
 
111
106
  `style.css` 是唯一需要业务引入的组件样式入口。`useYeeGrid()` 首次执行时,组件库会自动加载内部 Grid 样式;业务不需要区分或引入其它样式文件。
112
107
 
108
+ ### Vite 模板自动导入
109
+
110
+ 如果项目使用 `unplugin-vue-components`,可以直接复用组件库提供的 resolver。它会按组件的 feature entry 自动注入导入,并生成 `GlobalComponents` 类型声明:
111
+
112
+ ```ts
113
+ import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
114
+ import Components from 'unplugin-vue-components/vite'
115
+ import { YeeBossUIResolver } from '@yeepay/yee-boss-ui/resolver'
116
+
117
+ Components({
118
+ dts: 'src/types/components.d.ts',
119
+ resolvers: [
120
+ YeeBossUIResolver(),
121
+ AntDesignVueResolver(),
122
+ ],
123
+ })
124
+ ```
125
+
126
+ 该 resolver 只覆盖可以按名称自动导入的公共组件;`useYeeGrid()` 返回的 Grid 适配器仍应在脚本中显式使用。
127
+
113
128
  ### 应用壳层
114
129
 
115
130
  应用壳层只提供布局和展示状态,不读取路由、权限、用户 Store 或 Wujie 上下文。菜单权限、路由跳转、标签增删、刷新、主题切换、全屏和用户操作由应用处理,再通过 Props、Events 和插槽接入。
@@ -220,11 +235,10 @@ import type {
220
235
  YeeFileUploadExpose,
221
236
  YeeGridSlots,
222
237
  YeeModalProps,
223
- YeeSelectProps,
224
238
  } from '@yeepay/yee-boss-ui'
225
239
  ```
226
240
 
227
- `YeeModal` 和 `YeeSelect` 的 Props 同时包含 Ant Design Vue 原生透传属性。`useYeeGrid<Row, QueryValues>` 会把行类型传递给列、事件、查询函数和具名插槽,不需要在页面中重复断言类型。
241
+ `YeeModal` 的 Props 包含 Ant Design Vue 原生透传属性。`useYeeGrid<Row, QueryValues>` 会把行类型传递给列、事件、查询函数和具名插槽,不需要在页面中重复断言类型。
228
242
 
229
243
  ## Tailwind CSS
230
244
 
@@ -377,80 +391,72 @@ async function submit(): Promise<void> {
377
391
 
378
392
  Drawer 模式使用 `<YeeModal v-model:open="open" type="drawer" placement="right">`,`placement`、`getContainer`、`zIndex` 等原生属性会继续透传。
379
393
 
380
- ### YeeSelect
394
+ ### YeeGrid 查询区
381
395
 
382
- `YeeSelect` 保持 Ant Design Vue `Select` 的透传能力,并针对当前选中项和默认 option 提供完整文案提示。
396
+ 查询区不再作为独立组件提供。`useYeeGrid` 配置 `formOptions` 后,`YeeGrid` 内部会使用 Ant Design Vue `Form` / `FormItem` 渲染查询区。Schema 的 `component` 是判别字段,选择组件后,`componentProps` 会提示对应 Ant Design Vue 组件或 `YeeFileUpload` 的原生属性。
383
397
 
384
- ```vue
385
- <script setup lang="ts">
386
- import { shallowRef } from 'vue'
387
- import {
388
- YeeSelect,
389
- type YeeSelectExpose,
390
- type YeeSelectOption,
391
- type YeeSelectValue,
392
- } from '@yeepay/yee-boss-ui'
398
+ 查询区默认使用 `layout: 'horizontal'`,标签右对齐;未设置 `labelWidth` 或传入 `labelWidth: 'auto'` 时,标签列按当前标签内容自适应。传入数字时使用固定标签宽度,例如 `labelWidth: 120`;需要上下排列时传入 `layout: 'vertical'`,此时标签左对齐且不使用 `labelWidth`。当字段的 `label` 为空字符串时,标签节点和标签间距都会省略,控件会占满当前字段区域。
393
399
 
394
- const status = shallowRef<YeeSelectValue>()
395
- const selectRef = shallowRef<YeeSelectExpose>()
396
- const statusOptions: YeeSelectOption[] = [
397
- { label: '成功', value: 'SUCCESS' },
398
- { label: '失败', value: 'FAILED' },
399
- ]
400
+ 查询字段默认占用 1 列。可以在字段 Schema 上设置 `span` 控制字段(包括标签和值)横跨的网格列数,支持 `1`、`2`、`3`,例如 `span: 2` 表示占用两列:
400
401
 
401
- function focusSelect(): void {
402
- selectRef.value?.focus()
402
+ ```ts
403
+ {
404
+ component: 'Textarea',
405
+ componentProps: {
406
+ autoSize: { minRows: 1, maxRows: 3 },
407
+ placeholder: '请输入备注',
408
+ },
409
+ fieldName: 'remark',
410
+ label: '备注',
411
+ span: 2,
403
412
  }
404
- </script>
413
+ ```
405
414
 
406
- <template>
407
- <YeeSelect
408
- ref="selectRef"
409
- v-model:value="status"
410
- allow-clear
411
- show-search
412
- :options="statusOptions"
413
- >
414
- <template #option="option">
415
- {{ option.label }}
416
- </template>
417
- </YeeSelect>
418
- <a-button @click="focusSelect">
419
- 聚焦选择器
420
- </a-button>
421
- </template>
415
+ 网格按屏幕宽度响应:默认(`>= 1024px`)为 3 列,`768px` 到 `1023px` 为 2 列,小于 `768px` 为 1 列。当 `span` 大于当前屏幕可用列数时,会自动收窄到当前可用列数,不会产生横向溢出。`span` 控制的是字段外层网格宽度,`labelWidth` 只控制水平布局中的标签列宽度。
416
+
417
+ `span` 的类型是公开导出的 `YeeGridFormFieldSpan`(`1 | 2 | 3`),通常直接在 Schema 字面量中配置即可;需要单独声明布局变量时,可以从包根入口导入该类型:
418
+
419
+ ```ts
420
+ import type { YeeGridFormFieldSpan } from '@yeepay/yee-boss-ui'
421
+
422
+ const detailSpan: YeeGridFormFieldSpan = 2
422
423
  ```
423
424
 
424
- 通过 `YeeSelectExpose` 可以调用 `focus()`、`blur()` `scrollTo()`。`change`、`select`、`deselect`、`search`、`clear`、`focus`、`blur`、`popupScroll`、`dropdownVisibleChange` 等原生事件均有参数提示;`option`、`optionLabel`、`tagRender`、`dropdownRender`、`maxTagPlaceholder` 等作用域插槽也会提示对应参数。
425
+ 启用 `showCollapseButton` 时,`collapsedRows` 按实际网格行数计算,跨列字段会消耗对应的列数;字段无法完整放入当前行时会自动换到下一行。展开后仍会显示全部未隐藏字段。`gridApi.formApi.updateSchema` 也支持动态更新字段的 `span`。
425
426
 
426
- ### YeeForm
427
+ 字段设置 `required: true` 后会参与必填校验。点击查询、按 Enter 查询或开启 `submitOnChange` 触发提交时,查询区会先校验所有未隐藏的必填字段;校验失败时不会发起查询,标签显示必填标记,Ant Design Vue 原生支持 `status` 的控件显示红色错误状态。错误信息不渲染在控件下方;字段修改后会重新校验已经出错的字段,重置查询会清除错误状态。
427
428
 
428
- `YeeForm` 可以独立使用,也会在 `useYeeGrid` 配置 `formOptions` 后自动挂载。Schema 的 `component` 是判别字段,选择组件后,`componentProps` 会提示对应 Ant Design Vue 组件或 `YeeFileUpload` 的原生属性。
429
+ 必填校验将 `undefined`、`null`、空字符串(包括只包含空白字符的字符串)、空数组和 `NaN` 视为空值;`false`、`0` 和空对象会被视为有值。隐藏字段不会参与校验。
429
430
 
430
431
  内置支持:`AutoComplete`、`Cascader`、`Checkbox`、`CheckboxGroup`、`DatePicker`、`Input`、`InputNumber`、`InputPassword`、`Mentions`、`Radio`、`RadioGroup`、`RangePicker`、`Rate`、`Segmented`、`Select`、`Slider`、`Switch`、`Textarea`、`TimePicker`、`TimeRangePicker`、`TreeSelect` 和 `Upload`。
431
432
 
432
433
  ```vue
433
434
  <script setup lang="ts">
434
- import {
435
- YeeForm,
436
- YeeFormApi,
437
- type YeeFormOptions,
438
- } from '@yeepay/yee-boss-ui'
435
+ import { useYeeGrid } from '@yeepay/yee-boss-ui'
436
+ import type { YeeGridFormOptions, YeeGridOptions, YeeGridPage, YeeGridQueryParams } from '@yeepay/yee-boss-ui'
439
437
 
440
438
  interface QueryValues {
441
439
  channel?: 'OFFLINE' | 'ONLINE'
442
440
  enabled?: boolean
443
441
  orderNo?: string
442
+ remark?: string
444
443
  }
445
444
 
446
- const formApi = new YeeFormApi<QueryValues>()
447
- const formOptions: YeeFormOptions<QueryValues> = {
445
+ const formOptions: YeeGridFormOptions<QueryValues> = {
448
446
  schema: [
449
447
  {
450
448
  component: 'Input',
451
449
  componentProps: { allowClear: true, placeholder: '请输入订单号' },
452
450
  fieldName: 'orderNo',
453
451
  label: '订单号',
452
+ required: true,
453
+ },
454
+ {
455
+ component: 'Textarea',
456
+ componentProps: { autoSize: { minRows: 1, maxRows: 3 }, placeholder: '请输入备注' },
457
+ fieldName: 'remark',
458
+ label: '备注',
459
+ span: 2,
454
460
  },
455
461
  {
456
462
  component: 'Switch',
@@ -465,25 +471,46 @@ const formOptions: YeeFormOptions<QueryValues> = {
465
471
  ],
466
472
  }
467
473
 
468
- function query(values: QueryValues): void {
469
- console.info(values.orderNo)
474
+ const gridOptions: YeeGridOptions<{ orderNo: string }, QueryValues> = {
475
+ columns: [{ field: 'orderNo', title: '订单号' }],
476
+ proxyConfig: {
477
+ ajax: {
478
+ query: async (
479
+ _params: YeeGridQueryParams<{ orderNo: string }>,
480
+ values: QueryValues,
481
+ ): Promise<YeeGridPage<{ orderNo: string }>> => ({
482
+ items: [{ orderNo: values.orderNo ?? '-' }],
483
+ total: 1,
484
+ }),
485
+ },
486
+ },
470
487
  }
488
+
489
+ const [OrderGrid] = useYeeGrid({ formOptions, gridOptions })
471
490
  </script>
472
491
 
473
492
  <template>
474
- <YeeForm :api="formApi" :on-submit="query" :options="formOptions">
475
- <template #channel="{ field, setValue, value, values }">
493
+ <OrderGrid>
494
+ <template #form-channel="{ field, setValue, value, values }">
476
495
  <button type="button" @click="setValue(value === 'ONLINE' ? 'OFFLINE' : 'ONLINE')">
477
496
  {{ field.label }}:{{ values.channel ?? '未选择' }}
478
497
  </button>
479
498
  </template>
480
- </YeeForm>
499
+ </OrderGrid>
481
500
  </template>
482
501
  ```
483
502
 
484
- 字段同名插槽可以覆盖任意内置组件;只使用自定义内容时,将 `component` 设置为 `Custom`。插槽提供 `field`、`value`、`values` 和 `setValue`,其中字段值会根据 `QueryValues` 自动提示类型,并统一写回 `YeeFormApi`。
503
+ 查询字段插槽使用 `form-${fieldName}` 命名,可以覆盖任意内置组件;只使用自定义内容时,将 `component` 设置为 `Custom`。插槽提供 `field`、`value`、`values` 和 `setValue`,其中字段值会根据 `QueryValues` 自动提示类型,并统一写回 `gridApi.formApi`。
485
504
 
486
- `YeeFormApi` 提供 `getFieldValue`、`getValues`、`setFieldValue`、`setValues`、`resetForm` 和 `updateSchema`;字段名和值会保持 `QueryValues` 中声明的类型。
505
+ `gridApi.formApi` 提供 `getFieldValue`、`getValues`、`setFieldValue`、`setValues`、`resetForm` 和 `updateSchema`;字段名和值会保持 `QueryValues` 中声明的类型。
506
+
507
+ 例如,字段已经存在时可以只更新它的布局:
508
+
509
+ ```ts
510
+ gridApi.formApi.updateSchema([
511
+ { fieldName: 'remark', span: 3 },
512
+ ])
513
+ ```
487
514
 
488
515
  ## YeePage 与 VXE Grid
489
516
 
@@ -495,7 +522,7 @@ function query(values: QueryValues): void {
495
522
 
496
523
  ```vue
497
524
  <script setup lang="ts">
498
- import type { YeeFormOptions, YeeGridOptions } from '@yeepay/yee-boss-ui'
525
+ import type { YeeGridFormOptions, YeeGridOptions } from '@yeepay/yee-boss-ui'
499
526
  import { useYeeGrid, YeePage } from '@yeepay/yee-boss-ui'
500
527
 
501
528
  interface OrderItem {
@@ -506,7 +533,7 @@ interface QueryValues {
506
533
  orderNo?: string
507
534
  }
508
535
 
509
- const formOptions: YeeFormOptions<QueryValues> = {
536
+ const formOptions: YeeGridFormOptions<QueryValues> = {
510
537
  schema: [
511
538
  {
512
539
  component: 'Input',
@@ -576,7 +603,7 @@ defineExpose({ reload: gridApi.reload })
576
603
 
577
604
  `table-title`、`toolbar-actions`、`toolbar-tools` 以及列配置中的具名插槽都有类型提示,其中列插槽的 `row` 会保持 `OrderItem` 类型。`YeeGridApi` 提供 `query`、`reload`、`setGridOptions`、`setLoading`、`setState` 和 `toggleSearchForm`;需要隐藏查询区时,可在 `useYeeGrid` 配置中设置 `showSearchForm: false`,不再提供工具栏显隐按钮。
578
605
 
579
- 组件的 TypeScript 导出使用 `YeeForm`、`YeeGrid`、`YeePage`,Vue 模板标签对应 `yee-form`、`yee-grid`、`yee-page`。新代码统一使用 `useYeeGrid`,不提供旧命名兼容别名。查询接口统一返回 `{ items, total }`。
606
+ 组件的 TypeScript 导出使用 `YeeGrid`(由 `useYeeGrid` 返回)和 `YeePage`,Vue 模板标签对应 `yee-grid`、`yee-page`。查询区只通过 `YeeGrid` `formOptions` 配置,不再提供独立查询表单组件。查询接口统一返回 `{ items, total }`。
580
607
 
581
608
  ## 开发
582
609