@robot-admin/naive-ui-components 0.26.0 → 0.28.0

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.
Files changed (182) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +9 -11
  3. package/README_EN.md +8 -8
  4. package/dist/C_Form.base.css +31 -13
  5. package/dist/C_Form.css +31 -13
  6. package/dist/C_Form.d.cts +3 -2
  7. package/dist/C_Form.d.ts +3 -19
  8. package/dist/C_FormModal.d.cts +1 -1
  9. package/dist/C_FormModal.d.ts +2 -17
  10. package/dist/C_FormSearch.css +79 -79
  11. package/dist/C_FormSearch.d.cts +2 -1
  12. package/dist/C_FormSearch.d.ts +2 -2
  13. package/dist/C_FormulaEditor.d.cts +1 -1
  14. package/dist/C_FormulaEditor.d.ts +1 -1
  15. package/dist/C_Guide.d.cts +1 -1
  16. package/dist/C_Guide.d.ts +1 -1
  17. package/dist/C_Icon.d.cts +1 -1
  18. package/dist/C_Icon.d.ts +1 -1
  19. package/dist/C_Language.d.cts +1 -1
  20. package/dist/C_Language.d.ts +1 -1
  21. package/dist/C_Loading.d.cts +1 -1
  22. package/dist/C_Loading.d.ts +1 -1
  23. package/dist/C_Login.d.cts +1 -1
  24. package/dist/C_Login.d.ts +1 -1
  25. package/dist/C_Markdown.d.cts +1 -1
  26. package/dist/C_Markdown.d.ts +1 -1
  27. package/dist/C_Menu.d.ts +1 -1
  28. package/dist/C_OrgChart.d.cts +1 -1
  29. package/dist/C_OrgChart.d.ts +1 -1
  30. package/dist/C_Progress.d.cts +1 -1
  31. package/dist/C_Progress.d.ts +1 -1
  32. package/dist/C_SectionNav.d.cts +1 -1
  33. package/dist/C_SectionNav.d.ts +1 -1
  34. package/dist/C_Skeleton.d.cts +1 -1
  35. package/dist/C_Skeleton.d.ts +1 -1
  36. package/dist/C_Steps.d.cts +1 -1
  37. package/dist/C_Steps.d.ts +1 -1
  38. package/dist/C_Table.base.css +176 -171
  39. package/dist/C_Table.css +145 -158
  40. package/dist/C_Table.d.cts +1 -1
  41. package/dist/C_Table.d.ts +7 -5
  42. package/dist/C_Table2.cjs +3 -3
  43. package/dist/C_Table2.js +3 -3
  44. package/dist/C_TagsView.d.cts +1 -1
  45. package/dist/C_TagsView.d.ts +1 -1
  46. package/dist/C_Theme.d.cts +1 -1
  47. package/dist/C_Theme.d.ts +1 -1
  48. package/dist/C_Timeline.d.cts +1 -1
  49. package/dist/C_Timeline.d.ts +1 -1
  50. package/dist/C_Transfer.d.cts +1 -1
  51. package/dist/C_Transfer.d.ts +1 -1
  52. package/dist/C_Tree.d.cts +1 -1
  53. package/dist/C_Tree.d.ts +7 -5
  54. package/dist/C_Upload.d.cts +1 -1
  55. package/dist/C_Upload.d.ts +1 -1
  56. package/dist/config.cjs +1 -1
  57. package/dist/config.d.cts +1 -4
  58. package/dist/config.d.ts +1 -4
  59. package/dist/config.js +1 -1
  60. package/dist/constants.d.cts +2 -2
  61. package/dist/constants.d.ts +2 -2
  62. package/dist/constants2.d.cts +173 -402
  63. package/dist/constants2.d.ts +173 -402
  64. package/dist/constants3.d.cts +2 -2
  65. package/dist/constants3.d.ts +2 -2
  66. package/dist/constants4.d.cts +402 -173
  67. package/dist/constants4.d.ts +402 -173
  68. package/dist/data.cjs +1 -1
  69. package/dist/data.d.cts +1 -2
  70. package/dist/data.d.ts +1 -2
  71. package/dist/data.js +1 -1
  72. package/dist/data2.d.cts +5 -5
  73. package/dist/data2.d.ts +5 -5
  74. package/dist/dateRange.d.cts +3 -2
  75. package/dist/dateRange.d.ts +3 -2
  76. package/dist/helpers.cjs +1 -1
  77. package/dist/helpers.js +1 -1
  78. package/dist/index.cjs +1 -1
  79. package/dist/index.d.cts +34 -34
  80. package/dist/index.d.ts +41 -42
  81. package/dist/index.js +1 -1
  82. package/dist/index.vue.d.cts +4 -4
  83. package/dist/index.vue.d.ts +4 -4
  84. package/dist/index10.vue.d.cts +1 -1
  85. package/dist/index10.vue.d.ts +1 -1
  86. package/dist/index11.vue.d.cts +1 -1
  87. package/dist/index11.vue.d.ts +7 -4
  88. package/dist/index12.vue.d.cts +7 -4
  89. package/dist/index13.vue.d.ts +4 -4
  90. package/dist/index14.vue.d.cts +4 -4
  91. package/dist/index15.vue.d.ts +52 -54
  92. package/dist/index16.vue.d.cts +52 -54
  93. package/dist/index16.vue.d.ts +125 -13
  94. package/dist/index17.vue.d.cts +125 -13
  95. package/dist/index17.vue.d.ts +51 -123
  96. package/dist/index18.vue.d.cts +51 -123
  97. package/dist/index18.vue.d.ts +26 -47
  98. package/dist/index19.vue.d.cts +26 -47
  99. package/dist/index19.vue.d.ts +13 -38
  100. package/dist/index2.vue.d.cts +1 -1
  101. package/dist/index2.vue.d.ts +1 -1
  102. package/dist/index20.vue.d.cts +13 -38
  103. package/dist/index20.vue.d.ts +128 -11
  104. package/dist/index21.vue.d.cts +128 -11
  105. package/dist/index21.vue.d.ts +75 -25
  106. package/dist/index22.vue.d.cts +75 -25
  107. package/dist/index22.vue.d.ts +72 -78
  108. package/dist/index23.vue.d.cts +97 -75
  109. package/dist/index23.vue.d.ts +96 -68
  110. package/dist/index24.vue.d.cts +47 -89
  111. package/dist/index24.vue.d.ts +47 -89
  112. package/dist/index25.vue.d.cts +19 -127
  113. package/dist/index25.vue.d.ts +19 -127
  114. package/dist/index26.vue.d.cts +87 -94
  115. package/dist/index26.vue.d.ts +87 -94
  116. package/dist/index27.vue.d.cts +36 -66
  117. package/dist/index27.vue.d.ts +36 -66
  118. package/dist/index28.vue.d.cts +12 -96
  119. package/dist/index28.vue.d.ts +12 -96
  120. package/dist/index29.vue.d.cts +85 -94
  121. package/dist/index29.vue.d.ts +85 -94
  122. package/dist/index3.vue.d.cts +4 -4
  123. package/dist/index3.vue.d.ts +4 -4
  124. package/dist/index30.vue.d.cts +103 -21
  125. package/dist/index30.vue.d.ts +103 -21
  126. package/dist/index31.vue.d.cts +75 -0
  127. package/dist/index31.vue.d.ts +75 -0
  128. package/dist/index6.vue.d.ts +2 -2
  129. package/dist/index7.vue.d.cts +2 -2
  130. package/dist/index7.vue.d.ts +2 -2
  131. package/dist/index8.vue.d.cts +2 -2
  132. package/dist/index8.vue.d.ts +2 -2
  133. package/dist/index9.vue.d.cts +2 -2
  134. package/dist/index9.vue.d.ts +1 -1
  135. package/dist/mapUtils.d.cts +1 -1
  136. package/dist/mapUtils.d.ts +1 -1
  137. package/dist/options.cjs +1 -0
  138. package/dist/options.d.cts +9 -0
  139. package/dist/options.js +1 -0
  140. package/dist/serializeSearch.cjs +1 -1
  141. package/dist/serializeSearch.js +1 -1
  142. package/dist/style.css +256 -251
  143. package/dist/useCalendarEvents.d.cts +1 -1
  144. package/dist/useCalendarEvents.d.ts +1 -1
  145. package/dist/useCollapsePanel.d.cts +5 -5
  146. package/dist/useCollapsePanel.d.ts +5 -5
  147. package/dist/useComponentLocale.cjs +1 -1
  148. package/dist/useComponentLocale.js +1 -1
  149. package/dist/useCropperCore.d.cts +5 -5
  150. package/dist/useCropperCore.d.ts +5 -5
  151. package/dist/useDynamicFormState.d.cts +11 -969
  152. package/dist/useDynamicFormState.d.ts +11 -959
  153. package/dist/useEdgeInteraction.d.cts +3 -3
  154. package/dist/useEdgeInteraction.d.ts +3 -3
  155. package/dist/useFormConfig.d.cts +5 -5
  156. package/dist/useFormConfig.d.ts +13 -6
  157. package/dist/useFullscreen.d.cts +3 -3
  158. package/dist/useFullscreen.d.ts +3 -3
  159. package/dist/useInfiniteScroll.d.cts +4 -4
  160. package/dist/useInfiniteScroll.d.ts +4 -4
  161. package/dist/useQRCode.d.cts +2 -2
  162. package/dist/useQRCode.d.ts +2 -2
  163. package/dist/useSignatureHistory.d.cts +6 -6
  164. package/dist/useSignatureHistory.d.ts +6 -6
  165. package/dist/useSplitResize.d.cts +6 -6
  166. package/dist/useSplitResize.d.ts +6 -6
  167. package/dist/useTableQuery.d.cts +905 -0
  168. package/dist/useTableQuery.d.ts +895 -0
  169. package/dist/useWorkflowValidation.d.cts +4 -4
  170. package/dist/useWorkflowValidation.d.ts +4 -4
  171. package/docs/guides/data-workflows.md +8 -48
  172. package/docs/guides/search-workflows.md +3 -5
  173. package/docs/guides/table-density.md +9 -1
  174. package/docs/guides/usage.en.md +4 -0
  175. package/docs/guides/usage.md +41 -0
  176. package/package.json +1 -1
  177. package/dist/dictionary.cjs +0 -1
  178. package/dist/dictionary.d.cts +0 -47
  179. package/dist/dictionary.d.ts +0 -47
  180. package/dist/dictionary.js +0 -1
  181. package/dist/useDictionary.cjs +0 -1
  182. package/dist/useDictionary.js +0 -1
@@ -259,18 +259,18 @@ declare const __VLS_export: vue.DefineComponent<WorkflowProps, {
259
259
  conditionNodes: number;
260
260
  }>;
261
261
  }, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
262
- "update:modelValue": (value: WorkflowData) => any;
263
262
  change: (value: WorkflowData) => any;
263
+ "update:modelValue": (value: WorkflowData) => any;
264
+ "node-click": (node: WorkflowNode<NodeType>) => any;
264
265
  save: (data: WorkflowData) => any;
265
266
  "validate-error": (errors: ValidationError[]) => any;
266
- "node-click": (node: WorkflowNode<NodeType>) => any;
267
267
  "edge-click": (edge: WorkflowEdge) => any;
268
268
  }, string, vue.PublicProps, Readonly<WorkflowProps> & Readonly<{
269
- "onUpdate:modelValue"?: ((value: WorkflowData) => any) | undefined;
270
269
  onChange?: ((value: WorkflowData) => any) | undefined;
270
+ "onUpdate:modelValue"?: ((value: WorkflowData) => any) | undefined;
271
+ "onNode-click"?: ((node: WorkflowNode<NodeType>) => any) | undefined;
271
272
  onSave?: ((data: WorkflowData) => any) | undefined;
272
273
  "onValidate-error"?: ((errors: ValidationError[]) => any) | undefined;
273
- "onNode-click"?: ((node: WorkflowNode<NodeType>) => any) | undefined;
274
274
  "onEdge-click"?: ((edge: WorkflowEdge) => any) | undefined;
275
275
  }>, {
276
276
  readonly: boolean;
@@ -259,18 +259,18 @@ declare const __VLS_export: vue.DefineComponent<WorkflowProps, {
259
259
  conditionNodes: number;
260
260
  }>;
261
261
  }, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
262
- "update:modelValue": (value: WorkflowData) => any;
263
262
  change: (value: WorkflowData) => any;
263
+ "update:modelValue": (value: WorkflowData) => any;
264
+ "node-click": (node: WorkflowNode<NodeType>) => any;
264
265
  save: (data: WorkflowData) => any;
265
266
  "validate-error": (errors: ValidationError[]) => any;
266
- "node-click": (node: WorkflowNode<NodeType>) => any;
267
267
  "edge-click": (edge: WorkflowEdge) => any;
268
268
  }, string, vue.PublicProps, Readonly<WorkflowProps> & Readonly<{
269
- "onUpdate:modelValue"?: ((value: WorkflowData) => any) | undefined;
270
269
  onChange?: ((value: WorkflowData) => any) | undefined;
270
+ "onUpdate:modelValue"?: ((value: WorkflowData) => any) | undefined;
271
+ "onNode-click"?: ((node: WorkflowNode<NodeType>) => any) | undefined;
271
272
  onSave?: ((data: WorkflowData) => any) | undefined;
272
273
  "onValidate-error"?: ((errors: ValidationError[]) => any) | undefined;
273
- "onNode-click"?: ((node: WorkflowNode<NodeType>) => any) | undefined;
274
274
  "onEdge-click"?: ((edge: WorkflowEdge) => any) | undefined;
275
275
  }>, {
276
276
  readonly: boolean;
@@ -2,57 +2,17 @@
2
2
 
3
3
  搜索、表单和表格共享值语义,应用保留接口、权限、缓存和业务事务。新增能力均按需接入;未配置时沿用既有行为。
4
4
 
5
- ## 一个字典数据源
5
+ ## 外部选项与格式化
6
6
 
7
- 应用已接入独立字典包的插件时,表单、搜索和 C_Table 可直接消费同一实例,应用无需再导入组件库的注入 key。下面保留不使用独立 SDK、自行提供数据源的接入方式:
7
+ 组件库不注册、加载或订阅字典,也不约定第三方插件的字段或注入协议。项目可使用任意数据服务,组合成组件已有的普通配置:
8
8
 
9
- ```ts
10
- import Components from '@robot-admin/naive-ui-components'
11
- import type { DictionarySource } from '@robot-admin/naive-ui-components/config'
12
-
13
- const planState: DictionarySource = {
14
- getOptions: () => [
15
- { value: 'released', label: '已下达' },
16
- { value: 'running', label: '执行中' },
17
- ],
18
- }
19
- app.use(Components, {
20
- dictionaries: {
21
- getDictionary: name => (name === 'planState' ? planState : undefined),
22
- },
23
- })
24
- ```
25
-
26
- 字段只写 `dictionary: 'planState'`。C_Form 的 `children`、`asyncOptions`,C_FormSearch 的显式 `list/attrs.options`,C_Table 的 `render/formatter/editProps.options` 仍按各自既有优先级生效,未使用的字典不会被加载。
27
-
28
- 按需安装可通过 `/config` 导出的 `DICTIONARY_PROVIDER_KEY` 注入同一个 Provider。不要因为使用表单而导入 MachTable 根包。
29
-
30
- ### 跨包只读协议
31
-
32
- `DICTIONARY_PROVIDER_KEY` 保留原公开名称与类型,使用版本化 token `Symbol.for('@robot-admin/dictionary/provider/v1')`。独立插件和组件库无需互相导入或新增强制依赖;只需遵循 `getDictionary(name)` 和下方选项源协议。
33
-
34
- Symbol 注册表中只有固定 token,没有字典实例、请求、缓存或 resolver。实例保留在各 Vue 应用的 provide 中,SSR 请求和多个应用互不共享;页面使用同一个 token 局部 provide 时,表单、搜索、表格与独立详情按 Vue 最近祖先规则读取同一来源。
35
-
36
- 已发布旧版组件使用私有 Symbol,不能仅升级独立 SDK 就自动互通,需要同步升级组件库。原有 `app.provide(DICTIONARY_PROVIDER_KEY, provider)` 和安装选项 `dictionaries` 写法继续保留;不扫描 Vue 私有上下文,也不通过另一份全局数据源掩盖缺失配置。
37
-
38
- `DictionarySource` 支持:
39
-
40
- - `getOptions()`:同步快照,编码保留 string/number/boolean 类型。
41
- - `load({ signal })`:可选的异步准备;视图会忽略已失效的请求。
42
- - `subscribe(listener)`:可选的更新通知,返回取消订阅函数。
43
- - `getState()`:可选的共享状态快照,`status` 为 `idle/loading/ready/empty/error`,失败时可带 `error`。提供它时,订阅同时通知状态变化;源应先更新快照再通知。未提供时保持原有协议。
44
-
45
- 状态快照可选带 `options`,这代表该数组不可变,并且与 `getOptions()` 返回同一份数据。此时仅加载/失败变化不会复制选项或重建翻译索引。未提供这个承诺的旧源仍支持修改原数组后发出订阅通知。
46
-
47
- 初次绑定调用 `load({ signal })`,字段或表格的显式重试调用 `load({ signal, force: true })`。源负责合并同一字典的并发请求,某个控件卸载仅取消自己的等待,不能打断其他使用者。空数组是成功的空字典,不应通过抛错表示空结果。
48
-
49
- 表单和搜索就地显示失败与重试,表格只显示一条按字典源去重的状态条;失败保留旧标签和原值,不逐单元格弹消息。`C_Form.getDictionaryError(field)` 可读取诊断,显式 `config.onError` 仍可观测表单异常。组件不把字典错误当作字段业务校验错误,也不会覆盖校验提示。表格的显式 `feedback.error` 继续可选接管诊断。
50
-
51
- 应用已有 store/resolver 时直接桥接,不叠加第二套 TTL 缓存。源负责组织、租户、语言和业务参数隔离:请求开始时捕获作用域,参数切换后不得把旧响应写进新作用域。可由 `getDictionary` 返回该作用域的稳定源,或发布当前快照变更通知。组件仅管理可销毁的选项视图及派生索引。
9
+ - C_Form:`children` 为选项数组;`attrs.loading` 或 `optionsState.loading` 表示加载。
10
+ - C_FormSearch:`list` / `attrs.options` 为选项数组。
11
+ - C_Table:`formatter` / `render` 负责显示,`filterOptions` 负责筛选,`editType: 'select'` 和 `editProps.options` 负责编辑。
52
12
 
53
- 选项必须是有效且唯一的原始编码、字符串标签及可选 boolean disabled。空数组是已提供的空选项,不回退到旧数据。未知编码原样回显;停用历史编码可以保留在源中供展示。重复标签在反向解析时报告歧义,不自动选择第一项。高频展示使用 `createDictionaryLabelResolver(options)`,快照变化时重建一次索引。
13
+ 表单与搜索的 `optionsState` 只呈现外部受控的 `loading/error/retry`,不会主动调用重试或查询来源。错误就地显示,不修改业务模型或覆盖校验反馈;请求、共享缓存、身份切换与取消由项目的数据服务负责。组件自有 `asyncOptions` 保留原有取消和生命周期管理,`reloadOptions` 只重新加载这些字段。
54
14
 
55
- 数组编码逐项翻译,以 `、` 连接;空数组显示为空。字符串编码不按逗号或其他字符自动拆分。普通枚举仅负责文字转换,状态色仍由表格列的 `status` 显式声明。
15
+ 布尔值只在原生选择器边界编码,提交仍保留 `false/true`;字符串、数字和前导零编码保持原样。配置项变化不会覆盖搜索草稿。
56
16
 
57
17
  ## 数值:存储、显示和校验分别定义
58
18
 
@@ -75,7 +35,7 @@ weight.format('12.5004') // '12.500 t',只舍入显示,不改原值
75
35
 
76
36
  `fractionDigits: 0` 有效;HALF_UP 处理负数中点。parse 接收普通十进制原始值,format 可加千分位、前后缀;带单位/货币符号的显示文本不是接口值。合计、精确排序、汇率和税费按业务数值策略处理,不拿格式化文本计算。
77
37
 
78
- MachTable 使用侧可在全局列类型中一次接入 `valueParser` 和 `valueFormatter`;精确字符串字段提供相应业务 comparator。其 `createDictionaryColumn` 可显式设置各输出 target 的编码/标签/码名策略,`summarizeRows` 可注入已有精确运算策略。Naive 库不会依赖或代替网格内核。
38
+ MachTable 使用侧可在全局列类型中一次接入 `valueParser` 和 `valueFormatter`;精确字符串字段提供相应业务 comparator。输出策略通过公开的列格式化与导出选项定义,`summarizeRows` 可注入已有精确运算策略。Naive 库不会依赖或代替网格内核。
79
39
 
80
40
  ## 主从资源:本地空值与迟到响应
81
41
 
@@ -118,17 +118,15 @@
118
118
 
119
119
  `select` 保留字符串、数字、布尔值及多选数组的业务类型。内部布尔编码仅用于适配原生选择器,提交的 `false` 不会变成字符串或 `0`。
120
120
 
121
- ## 字典与自定义控件
121
+ ## 外部选项与自定义控件
122
122
 
123
- 字段可配置 `dictionary: 'orderStatus'`,由应用已提供的字典 Provider 解析;也可直接传入 `DictionarySource`。搜索不另建字典缓存,使用同一来源的选项、订阅与可取消加载。
124
-
125
- 显式 `list`(包括空数组)和 `attrs.options` 优先于字典,且不会加载未使用的字典。加载失败在选择器中显示重试入口;字典标签更新不会重置输入草稿。组织切换和字典加载策略仍由应用 Provider 决定。
123
+ 字段通过 `list` 或 `attrs.options` 接收普通选项数组。外部加载状态可传 `optionsState: { loading, error, retry }`,选择器就地呈现错误和重试入口;组件不会查询、注册或订阅外部来源。重试只在用户点击时调用,接口、取消与共享缓存由项目负责。
126
124
 
127
125
  `custom` 可使用 `slot` 或 `render(context)`;必须声明类型正确的 `defaultValue`,使 reset 和 clear 有确定语义。上下文提供 `value`、只读 `model`、`prop`、`size`、`disabled`、`readonly` 和 `updateValue`。修改走 `updateValue`;`fixed`、`readonly`、`disabled` 字段会拦截控件回写。自定义按钮使用 `type="button"`,避免误触发表单提交。
128
126
 
129
127
  ## 草稿、执行结果和重置
130
128
 
131
- - `v-model` / `formParams` 是可编辑草稿;字段配置或字典选项变化不拿旧 props 覆盖未提交输入。
129
+ - `v-model` / `formParams` 是可编辑草稿;字段配置或外部选项变化不拿旧 props 覆盖未提交输入。
132
130
  - `@search` 是经过校验的执行通知,保留原有时机;它不表示后台查询成功。
133
131
  - 使用 `config.onSearch` 返回任务 Promise 后,只有成功完成才更新 `appliedParams` 并发出 `@applied`。回调拒绝或显式返回 `false` 时,`searchFn()` 返回 `false`,保留上一次成功条件并允许重试。可直接返回 `useDataResource.reload()` 的 boolean 结果;接入自行收拢错误的其它控制器时,回调应检查其错误状态并返回 `false`。
134
132
  - 仅使用旧 `@search` 的接入无法观察事件监听器异步结果,因此不会伪造 `appliedParams`;需要成功快照时使用 `onSearch`。
@@ -100,7 +100,15 @@ const columns: TableColumn<Order>[] = [
100
100
  const columns = [
101
101
  { type: 'index' },
102
102
  { key: 'customer', title: '客户', maxWidth: 280 },
103
- { key: 'status', title: '状态', dictionary: 'order-status', status: true },
103
+ {
104
+ key: 'status',
105
+ title: '状态',
106
+ formatter: {
107
+ type: 'enum',
108
+ fn: value => statusLabels[value] ?? String(value ?? ''),
109
+ },
110
+ status: true,
111
+ },
104
112
  {
105
113
  key: 'planStatus',
106
114
  title: '计划状态',
@@ -296,6 +296,10 @@ const { bindings } = useTableQuery<UserRow, { keyword: string }>({
296
296
 
297
297
  When binding a headless CRUD controller through `:crud`, the table recognizes `{ error }` action results: failed deletes do not emit a successful-deletion event, and feedback already shown by the controller is not duplicated. Custom `actions.delete` callbacks may return a promise or a `{ data, error }` result.
298
298
 
299
+ For dynamic reports, bind `<C_Table :columns="report.columns" :data="report.rows" row-key="id" />` and replace the report snapshot when the request completes. Each column uses `{ key, title }`. User width, visibility, pinning, and order follow stable keys. Give separate reports distinct `config.persistKey` values and update the report key, columns, and rows together.
300
+
301
+ The table displays continuous row numbers and a pager with 10 rows per page by default. Use `:row-number="false"` for the automatic index and `:pagination="false"` to disable pagination. An explicit `{ type: 'index' }` keeps its configured position and title. Column headers and cells, including numbers, are centered by default and can be overridden with `titleAlign` and `align`.
302
+
299
303
  Tree data can use `<C_Table :data="rows" :columns="columns" :config="{ tree: { defaultExpandAll: true }, pagination: false }" />` directly. `children` is the default child key and can be changed with `tree.childrenKey`. Default expansion includes parent rows added later without reopening rows the user collapsed.
300
304
 
301
305
  `C_Tabs` is the data-driven page-scenario switcher for the global `C_*` system. It defaults to the compact
@@ -376,6 +376,47 @@ const fields = defineFormOptions([
376
376
 
377
377
  将 Headless CRUD 绑定到 `:crud` 时,表格会识别操作结果中的 `{ error }`:失败不会触发删除成功事件,也不会重复展示 CRUD 控制器已经展示的反馈。自定义 `actions.delete` 可返回 Promise,或返回 `{ data, error }` 结构。
378
378
 
379
+ ### 后端返回列和行
380
+
381
+ 接口的列定义使用 `{ key, title }` 时直接绑定。把同一次查询的列和行一起提交给响应式状态:
382
+
383
+ ```vue
384
+ <script setup lang="ts">
385
+ import { shallowRef } from 'vue'
386
+ import {
387
+ C_Table,
388
+ type TableColumn,
389
+ } from '@robot-admin/naive-ui-components/C_Table'
390
+ import { getReport } from './api'
391
+
392
+ const report = shallowRef<{
393
+ columns: TableColumn[]
394
+ rows: Record<string, unknown>[]
395
+ }>({ columns: [], rows: [] })
396
+
397
+ async function load() {
398
+ report.value = await getReport()
399
+ }
400
+ </script>
401
+
402
+ <template>
403
+ <button
404
+ type="button"
405
+ @click="load"
406
+ >查询</button
407
+ >
408
+ <C_Table
409
+ :columns="report.columns"
410
+ :data="report.rows"
411
+ row-key="id"
412
+ />
413
+ </template>
414
+ ```
415
+
416
+ 表格默认显示跨页连续序号和分页器(每页 10 条),标题及单元格均居中,数字也一样。通过 `:row-number="false"` 关闭自动序号,通过 `:pagination="false"` 或 `:config="{ pagination: false }"` 关闭分页。手动声明的 `{ type: 'index' }` 保留指定的位置和标题,表格只补一份序号。单列可以用 `align`、`titleAlign` 覆盖默认对齐。
417
+
418
+ 同一张报表的列 `key` 保持稳定时,换列仍会应用已有的宽度、显隐、固定和排序偏好。新列使用接口给出的配置,已移除的列退出当前偏好。需要跨页面刷新恢复偏好或切换多张报表时,给每张报表一个不同的 `config.persistKey`。切换报表时一起更新该标识、列和行。
419
+
379
420
  树形数据可直接使用 `<C_Table :data="rows" :columns="columns" :config="{ tree: { defaultExpandAll: true }, pagination: false }" />`;`children` 是默认子节点字段,也可通过 `tree.childrenKey` 指定。默认展开会初始化所有父节点,并在异步追加新父节点时展开新节点,不会重新展开用户手动收起的旧节点。
380
421
 
381
422
  `C_Tabs` 是面向页面场景切换的统一数据驱动标签页,名称与全局 `C_*` 体系保持一致。默认使用紧凑
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.26.0",
6
+ "version": "0.28.0",
7
7
  "description": "基于 Naive UI 的 Vue 3 组件库",
8
8
  "packageManager": "bun@1.4.2",
9
9
  "engines": {
@@ -1 +0,0 @@
1
- function e(e){let t=new Map;for(let n of e)t.has(n.value)||t.set(n.value,n.label);let n=e=>t.get(e)??String(e??``);return e=>Array.isArray(e)?e.map(n).join(`、`):n(e)}function t(t,n){return Array.isArray(t)?e(n)(t):n.find(e=>Object.is(e.value,t))?.label??String(t??``)}function n(e,t){let n=t.find(t=>Object.is(t.value,e));if(n)return{ok:!0,value:n.value};if(typeof e!=`string`)return{ok:!1,reason:`unknown`,input:e};let r=t.filter(t=>String(t.value)===e),i=r.length?r:t.filter(t=>t.label===e);return i.length===1?{ok:!0,value:i[0].value}:{ok:!1,reason:i.length?`ambiguous`:`unknown`,input:e}}function r(e){return Array.isArray(e)?e.map(r):typeof e==`string`||typeof e==`number`||typeof e==`boolean`?JSON.stringify([typeof e,e]):e}function i(e){if(Array.isArray(e))return e.map(i);if(typeof e!=`string`)return e;try{let t=JSON.parse(e);if(Array.isArray(t)&&t.length===2&&[`string`,`number`,`boolean`].includes(t[0])&&typeof t[1]===t[0])return t[1]}catch{}return e}function a(e){return e.map(e=>({...e,value:r(e.value)}))}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return e}});
@@ -1,47 +0,0 @@
1
- //#region src/core/dictionary.d.ts
2
- /**
3
- * 字典值协议与纯转换工具。数据缓存、请求与租户隔离由应用 Provider 负责。
4
- * 此模块不依赖 Vue、UI、DOM 或任何表格实现,可用于导入、导出和适配层。
5
- */
6
- type DictionaryValue = string | number | boolean;
7
- interface DictionaryOption {
8
- value: DictionaryValue;
9
- label: string;
10
- disabled?: boolean;
11
- }
12
- interface DictionarySource {
13
- getOptions(): readonly DictionaryOption[];
14
- load?(context: {
15
- signal: AbortSignal;
16
- force?: boolean;
17
- }): Promise<readonly DictionaryOption[]>;
18
- /** 可选的共享加载状态;订阅同时通知数据和状态更新。 */
19
- getState?(): DictionaryState;
20
- subscribe?(listener: () => void): () => void;
21
- }
22
- interface DictionaryState {
23
- status: 'idle' | 'loading' | 'ready' | 'empty' | 'error';
24
- error?: unknown;
25
- /** 可选的不可变数据快照;仅状态变化时应复用同一数组,不可原地修改。 */
26
- options?: readonly DictionaryOption[];
27
- }
28
- interface DictionaryProvider {
29
- getDictionary(name: string): DictionarySource | undefined;
30
- }
31
- type DictionaryBinding = string | DictionarySource;
32
- type DictionaryParseResult = {
33
- ok: true;
34
- value: DictionaryValue;
35
- } | {
36
- ok: false;
37
- reason: 'unknown' | 'ambiguous';
38
- input: unknown;
39
- };
40
- /** 每份选项快照只建一次索引,表格单元格解析不重复遍历整份字典。 */
41
- declare function createDictionaryLabelResolver(options: readonly DictionaryOption[]): (value: unknown) => string;
42
- /** 原值比较保留 boolean、数值和带前导零的字符串编码,不回写展示标签。 */
43
- declare function getDictionaryLabel(value: unknown, options: readonly DictionaryOption[]): string;
44
- /** 原码优先于标签;多义标签或字符串化编码必须交由使用侧明确处理。 */
45
- declare function parseDictionaryValue(input: unknown, options: readonly DictionaryOption[]): DictionaryParseResult;
46
- //#endregion
47
- export { DictionarySource as a, createDictionaryLabelResolver as c, DictionaryProvider as i, getDictionaryLabel as l, DictionaryOption as n, DictionaryState as o, DictionaryParseResult as r, DictionaryValue as s, DictionaryBinding as t, parseDictionaryValue as u };
@@ -1,47 +0,0 @@
1
- //#region src/core/dictionary.d.ts
2
- /**
3
- * 字典值协议与纯转换工具。数据缓存、请求与租户隔离由应用 Provider 负责。
4
- * 此模块不依赖 Vue、UI、DOM 或任何表格实现,可用于导入、导出和适配层。
5
- */
6
- type DictionaryValue = string | number | boolean;
7
- interface DictionaryOption {
8
- value: DictionaryValue;
9
- label: string;
10
- disabled?: boolean;
11
- }
12
- interface DictionarySource {
13
- getOptions(): readonly DictionaryOption[];
14
- load?(context: {
15
- signal: AbortSignal;
16
- force?: boolean;
17
- }): Promise<readonly DictionaryOption[]>;
18
- /** 可选的共享加载状态;订阅同时通知数据和状态更新。 */
19
- getState?(): DictionaryState;
20
- subscribe?(listener: () => void): () => void;
21
- }
22
- interface DictionaryState {
23
- status: 'idle' | 'loading' | 'ready' | 'empty' | 'error';
24
- error?: unknown;
25
- /** 可选的不可变数据快照;仅状态变化时应复用同一数组,不可原地修改。 */
26
- options?: readonly DictionaryOption[];
27
- }
28
- interface DictionaryProvider {
29
- getDictionary(name: string): DictionarySource | undefined;
30
- }
31
- type DictionaryBinding = string | DictionarySource;
32
- type DictionaryParseResult = {
33
- ok: true;
34
- value: DictionaryValue;
35
- } | {
36
- ok: false;
37
- reason: 'unknown' | 'ambiguous';
38
- input: unknown;
39
- };
40
- /** 每份选项快照只建一次索引,表格单元格解析不重复遍历整份字典。 */
41
- declare function createDictionaryLabelResolver(options: readonly DictionaryOption[]): (value: unknown) => string;
42
- /** 原值比较保留 boolean、数值和带前导零的字符串编码,不回写展示标签。 */
43
- declare function getDictionaryLabel(value: unknown, options: readonly DictionaryOption[]): string;
44
- /** 原码优先于标签;多义标签或字符串化编码必须交由使用侧明确处理。 */
45
- declare function parseDictionaryValue(input: unknown, options: readonly DictionaryOption[]): DictionaryParseResult;
46
- //#endregion
47
- export { DictionarySource as a, createDictionaryLabelResolver as c, DictionaryProvider as i, getDictionaryLabel as l, DictionaryOption as n, DictionaryState as o, DictionaryParseResult as r, DictionaryValue as s, DictionaryBinding as t, parseDictionaryValue as u };
@@ -1 +0,0 @@
1
- function e(e){let t=new Map;for(let n of e)t.has(n.value)||t.set(n.value,n.label);let n=e=>t.get(e)??String(e??``);return e=>Array.isArray(e)?e.map(n).join(`、`):n(e)}function t(t,n){return Array.isArray(t)?e(n)(t):n.find(e=>Object.is(e.value,t))?.label??String(t??``)}function n(e,t){let n=t.find(t=>Object.is(t.value,e));if(n)return{ok:!0,value:n.value};if(typeof e!=`string`)return{ok:!1,reason:`unknown`,input:e};let r=t.filter(t=>String(t.value)===e),i=r.length?r:t.filter(t=>t.label===e);return i.length===1?{ok:!0,value:i[0].value}:{ok:!1,reason:i.length?`ambiguous`:`unknown`,input:e}}function r(e){return Array.isArray(e)?e.map(r):typeof e==`string`||typeof e==`number`||typeof e==`boolean`?JSON.stringify([typeof e,e]):e}function i(e){if(Array.isArray(e))return e.map(i);if(typeof e!=`string`)return e;try{let t=JSON.parse(e);if(Array.isArray(t)&&t.length===2&&[`string`,`number`,`boolean`].includes(t[0])&&typeof t[1]===t[0])return t[1]}catch{}return e}function a(e){return e.map(e=>({...e,value:r(e.value)}))}export{n as a,t as i,i as n,a as o,r,e as t};
@@ -1 +0,0 @@
1
- require(`./chunk.cjs`);const e=require(`./dictionary.cjs`),t=require(`./observer.cjs`),n=require(`./config.cjs`);let r=require(`vue`);const i=Object.freeze([]);function a(e,t){let n=e.getState?.()?.options;return n===t?n:void 0}function o(e){return typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e)}function s(e,t){if(!e||typeof e.label!=`string`||!o(e.value))throw TypeError(`[dictionary] 选项必须有字符串 label 和有限的原始 value`);if(e.disabled!==void 0&&typeof e.disabled!=`boolean`)throw TypeError(`[dictionary] disabled 必须是 boolean`);if(t.has(e.value))throw TypeError(`[dictionary] 选项 value 不得重复`);return t.add(e.value),{...e}}function c(o,c={}){let l=(0,r.getCurrentInstance)()?(0,r.inject)(n.DICTIONARY_PROVIDER_KEY,void 0):void 0,u=new Map,d=(0,r.shallowReactive)(new Map),f=(0,r.shallowReactive)(new Map),p=(0,r.shallowReactive)(new Map),m=(0,r.shallowReactive)(new Map),h=!1,g=(e,t)=>!h&&u.get(e)===t,_=(e,t,n)=>g(e,t)&&!n.signal.aborted&&t.controller===n,v=(e,n,r)=>{h||r&&!g(e,r)||(n??=`[dictionary] 字典加载失败`,!(p.has(e)&&Object.is(p.get(e),n))&&(p.set(e,n),!h&&(!r||g(e,r))&&t.t(()=>c.onError?.(n,e))))},y=e=>{if(!Array.isArray(e))throw TypeError(`[dictionary] 选项源必须返回数组`);let t=new Set;return e.map(e=>s(e,t))},b=(t,n,r)=>{if(!g(t,n))return!1;let i=a(n.source,r);if(i&&n.immutableSnapshot===i)return g(t,n);let o=y(r);return!g(t,n)||(d.set(t,o),!g(t,n))?!1:(m.set(t,e.t(o)),g(t,n)&&(n.immutableSnapshot=i),g(t,n))};function x(e,t,n=!1){if(!g(e,t))return;let r=t.source.getState?.();if(g(e,t)){if(!r){n&&p.delete(e);return}f.set(e,r.status===`loading`),g(e,t)&&(r.status===`error`?v(e,r.error??`[dictionary] 字典加载失败`,t):p.delete(e))}}function S(e,t){if(g(e,t))try{b(e,t,t.source.getOptions())&&x(e,t,!0)}catch(n){v(e,n,t)}}function C(e,t,n){if(g(e,t)&&t.controller===n){if(t.controller=void 0,f.set(e,!1),t.controller)return;try{x(e,t)}catch(n){v(e,n,t)}}}function w(e,t,n,r){try{if(t.revision!==n&&r instanceof Error&&r.name===`AbortError`&&t.source.getState){x(e,t);return}}catch(n){v(e,n,t);return}v(e,r,t)}async function T(e,t,n,r){let i=new AbortController;t.controller=i;let{revision:a}=t;if(f.set(e,!0),_(e,t,i)&&(p.delete(e),_(e,t,i)))try{let o=await n.call(t.source,{signal:i.signal,...r?{force:!0}:{}});if(!_(e,t,i))return;b(e,t,a===t.revision?o:t.source.getOptions()),x(e,t)}catch(n){_(e,t,i)&&w(e,t,a,n)}finally{C(e,t,i)}}async function E(e,t,n=!1){if(!g(e,t))return;let r=t.controller;if(t.controller=void 0,r?.abort(),!g(e,t)||t.controller)return;let i=t.source.load;i?await T(e,t,i,n):S(e,t)}function D(e,n){if(S(e,n),g(e,n)){try{let r=n.source.subscribe?.(()=>{g(e,n)&&(n.revision++,S(e,n))});g(e,n)?n.unsubscribe=r:t.t(()=>r?.())}catch(t){v(e,t,n)}n.source.load&&E(e,n)}}function O({key:e,binding:t,source:n,error:r}){if(h)return;let i=u.get(e);if(i&&i.source===n&&i.binding===t||(k(e),h))return;if(!n){t!==void 0&&v(e,r??Error(`[dictionary] 未注册字典: ${String(t)}`));return}let a={binding:t,source:n,revision:0};u.set(e,a),D(e,a)}function k(e){let t=u.get(e);u.delete(e),t?.controller?.abort();try{t?.unsubscribe?.()}catch(t){h||v(e,t)}d.delete(e),f.delete(e),p.delete(e),m.delete(e)}let A=()=>{};(0,r.getCurrentScope)()&&(0,r.onScopeDispose)(j),A=(0,r.watch)(()=>[...(0,r.toValue)(o)].map(([e,t])=>{try{return{key:e,binding:t,source:typeof t==`string`?l?.getDictionary(t):t}}catch(n){return{key:e,binding:t,source:void 0,error:n}}}),e=>{let t=new Set(e.map(e=>e.key));for(let e of new Set([...u.keys(),...p.keys()]))t.has(e)||k(e);e.forEach(O)},{immediate:!0}),h&&A();function j(){if(!h){h=!0,A();for(let e of new Set([...u.keys(),...p.keys()]))k(e)}}return{dispose:j,getOptions:e=>d.get(e)??i,getLabel:(e,t)=>m.get(e)?.(t)??String(t??``),isLoading:e=>f.get(e)??!1,getError:e=>p.get(e),getSource:e=>u.get(e)?.source,async reload(e){let t=e===void 0?[...u]:u.has(e)?[[e,u.get(e)]]:[];await Promise.all(t.map(([e,t])=>E(e,t,!0)))}}}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
@@ -1 +0,0 @@
1
- import{t as e}from"./dictionary.js";import{t}from"./observer.js";import{DICTIONARY_PROVIDER_KEY as n}from"./config.js";import{getCurrentInstance as r,getCurrentScope as i,inject as a,onScopeDispose as o,shallowReactive as s,toValue as c,watch as l}from"vue";const u=Object.freeze([]);function d(e,t){let n=e.getState?.()?.options;return n===t?n:void 0}function f(e){return typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e)}function p(e,t){if(!e||typeof e.label!=`string`||!f(e.value))throw TypeError(`[dictionary] 选项必须有字符串 label 和有限的原始 value`);if(e.disabled!==void 0&&typeof e.disabled!=`boolean`)throw TypeError(`[dictionary] disabled 必须是 boolean`);if(t.has(e.value))throw TypeError(`[dictionary] 选项 value 不得重复`);return t.add(e.value),{...e}}function m(f,m={}){let h=r()?a(n,void 0):void 0,g=new Map,_=s(new Map),v=s(new Map),y=s(new Map),b=s(new Map),x=!1,S=(e,t)=>!x&&g.get(e)===t,C=(e,t,n)=>S(e,t)&&!n.signal.aborted&&t.controller===n,w=(e,n,r)=>{x||r&&!S(e,r)||(n??=`[dictionary] 字典加载失败`,!(y.has(e)&&Object.is(y.get(e),n))&&(y.set(e,n),!x&&(!r||S(e,r))&&t(()=>m.onError?.(n,e))))},T=e=>{if(!Array.isArray(e))throw TypeError(`[dictionary] 选项源必须返回数组`);let t=new Set;return e.map(e=>p(e,t))},E=(t,n,r)=>{if(!S(t,n))return!1;let i=d(n.source,r);if(i&&n.immutableSnapshot===i)return S(t,n);let a=T(r);return!S(t,n)||(_.set(t,a),!S(t,n))?!1:(b.set(t,e(a)),S(t,n)&&(n.immutableSnapshot=i),S(t,n))};function D(e,t,n=!1){if(!S(e,t))return;let r=t.source.getState?.();if(S(e,t)){if(!r){n&&y.delete(e);return}v.set(e,r.status===`loading`),S(e,t)&&(r.status===`error`?w(e,r.error??`[dictionary] 字典加载失败`,t):y.delete(e))}}function O(e,t){if(S(e,t))try{E(e,t,t.source.getOptions())&&D(e,t,!0)}catch(n){w(e,n,t)}}function k(e,t,n){if(S(e,t)&&t.controller===n){if(t.controller=void 0,v.set(e,!1),t.controller)return;try{D(e,t)}catch(n){w(e,n,t)}}}function A(e,t,n,r){try{if(t.revision!==n&&r instanceof Error&&r.name===`AbortError`&&t.source.getState){D(e,t);return}}catch(n){w(e,n,t);return}w(e,r,t)}async function j(e,t,n,r){let i=new AbortController;t.controller=i;let{revision:a}=t;if(v.set(e,!0),C(e,t,i)&&(y.delete(e),C(e,t,i)))try{let o=await n.call(t.source,{signal:i.signal,...r?{force:!0}:{}});if(!C(e,t,i))return;E(e,t,a===t.revision?o:t.source.getOptions()),D(e,t)}catch(n){C(e,t,i)&&A(e,t,a,n)}finally{k(e,t,i)}}async function M(e,t,n=!1){if(!S(e,t))return;let r=t.controller;if(t.controller=void 0,r?.abort(),!S(e,t)||t.controller)return;let i=t.source.load;i?await j(e,t,i,n):O(e,t)}function N(e,n){if(O(e,n),S(e,n)){try{let r=n.source.subscribe?.(()=>{S(e,n)&&(n.revision++,O(e,n))});S(e,n)?n.unsubscribe=r:t(()=>r?.())}catch(t){w(e,t,n)}n.source.load&&M(e,n)}}function P({key:e,binding:t,source:n,error:r}){if(x)return;let i=g.get(e);if(i&&i.source===n&&i.binding===t||(F(e),x))return;if(!n){t!==void 0&&w(e,r??Error(`[dictionary] 未注册字典: ${String(t)}`));return}let a={binding:t,source:n,revision:0};g.set(e,a),N(e,a)}function F(e){let t=g.get(e);g.delete(e),t?.controller?.abort();try{t?.unsubscribe?.()}catch(t){x||w(e,t)}_.delete(e),v.delete(e),y.delete(e),b.delete(e)}let I=()=>{};i()&&o(L),I=l(()=>[...c(f)].map(([e,t])=>{try{return{key:e,binding:t,source:typeof t==`string`?h?.getDictionary(t):t}}catch(n){return{key:e,binding:t,source:void 0,error:n}}}),e=>{let t=new Set(e.map(e=>e.key));for(let e of new Set([...g.keys(),...y.keys()]))t.has(e)||F(e);e.forEach(P)},{immediate:!0}),x&&I();function L(){if(!x){x=!0,I();for(let e of new Set([...g.keys(),...y.keys()]))F(e)}}return{dispose:L,getOptions:e=>_.get(e)??u,getLabel:(e,t)=>b.get(e)?.(t)??String(t??``),isLoading:e=>v.get(e)??!1,getError:e=>y.get(e),getSource:e=>g.get(e)?.source,async reload(e){let t=e===void 0?[...g]:g.has(e)?[[e,g.get(e)]]:[];await Promise.all(t.map(([e,t])=>M(e,t,!0)))}}}export{m as t};