king-design-analyzer 2.1.9 → 2.2.1
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/components/actions.json +109 -0
- package/components/advancedset.json +128 -0
- package/components/affix.json +8 -0
- package/components/aksk.json +172 -0
- package/components/anchor.json +220 -0
- package/components/anchorlink.json +111 -0
- package/components/az.json +15 -2
- package/components/badge.json +8 -0
- package/components/billtypes.json +14 -2
- package/components/breadcrumb.json +9 -1
- package/components/button.json +192 -0
- package/components/buttonlink.json +74 -0
- package/components/card.json +14 -4
- package/components/cardcol.json +142 -0
- package/components/cardcols.json +121 -0
- package/components/cardcontent.json +20 -3
- package/components/cardtabs.json +172 -0
- package/components/carousel.json +7 -0
- package/components/cascader.json +576 -368
- package/components/checkbox.json +51 -4
- package/components/cidrinput.json +140 -0
- package/components/code.json +8 -1
- package/components/collapse.json +335 -341
- package/components/colorpicker.json +217 -0
- package/components/configprovider.json +96 -0
- package/components/copy.json +7 -0
- package/components/copyhover.json +111 -0
- package/components/copyrow.json +125 -0
- package/components/datepicker.json +656 -524
- package/components/description.json +98 -0
- package/components/descriptions.json +10 -3
- package/components/diagram.json +295 -0
- package/components/dialog.json +526 -455
- package/components/divider.json +9 -1
- package/components/drawer.json +603 -558
- package/components/dropdown.json +464 -384
- package/components/duration.json +125 -0
- package/components/editable.json +66 -0
- package/components/ellipsis.json +34 -1
- package/components/filtertablefieldsdialog.json +128 -0
- package/components/flex.json +152 -0
- package/components/form.json +143 -3
- package/components/formiteminput.json +214 -0
- package/components/formitemspinner.json +213 -0
- package/components/formitemswitch.json +185 -0
- package/components/formitemtableconfigs.json +210 -0
- package/components/grid.json +7 -0
- package/components/header.json +165 -0
- package/components/icon.json +13 -1
- package/components/icontooltip.json +19 -1
- package/components/input.json +196 -8
- package/components/instancelist.json +194 -0
- package/components/instancenum.json +196 -0
- package/components/ipinput.json +117 -0
- package/components/kspstatus.json +205 -0
- package/components/kvcode.json +120 -0
- package/components/layoutcontent.json +24 -3
- package/components/layoutlistcontent.json +157 -0
- package/components/layoutpermissioncontent.json +156 -0
- package/components/layoutstandardlist.json +276 -0
- package/components/layouttabs.json +168 -0
- package/components/lazymount.json +87 -0
- package/components/lazyteleport.json +119 -0
- package/components/menu.json +11 -3
- package/components/notification.json +351 -0
- package/components/pagination.json +12 -0
- package/components/paginationplus.json +30 -3
- package/components/password.json +121 -0
- package/components/popover.json +457 -437
- package/components/projects.json +129 -0
- package/components/protable.json +99 -8
- package/components/queuevisualrange.json +110 -0
- package/components/radio.json +82 -2
- package/components/rate.json +200 -0
- package/components/region.json +14 -2
- package/components/scrollselect.json +140 -0
- package/components/search.json +221 -0
- package/components/searchinput.json +132 -0
- package/components/searchitems.json +215 -0
- package/components/searchselect.json +195 -0
- package/components/select.json +749 -666
- package/components/sidebar.json +198 -0
- package/components/skeleton.json +234 -0
- package/components/slider.json +12 -2
- package/components/spin.json +10 -2
- package/components/spinner.json +419 -429
- package/components/split.json +263 -0
- package/components/sshkeys.json +138 -0
- package/components/status.json +60 -3
- package/components/steps.json +7 -0
- package/components/switch.json +12 -3
- package/components/table.json +24 -2
- package/components/tablecolumnid.json +14 -2
- package/components/tabs.json +14 -2
- package/components/tag.json +8 -5
- package/components/timeline.json +215 -0
- package/components/timepicker.json +147 -3
- package/components/timerange.json +262 -0
- package/components/tip.json +27 -0
- package/components/tooltip.json +492 -395
- package/components/tour.json +418 -372
- package/components/transfer.json +79 -8
- package/components/tree.json +28 -5
- package/components/treeselect.json +612 -475
- package/components/upload.json +474 -473
- package/components/vdialog.json +309 -0
- package/components/vdrawer.json +335 -0
- package/components/virtuallist.json +7 -0
- package/dist/ast/index.d.mts +65 -2
- package/dist/ast/index.d.ts +65 -2
- package/dist/ast/index.js +4 -3
- package/dist/ast/index.mjs +2 -1
- package/dist/chunk-4OTQAQ6J.mjs +341 -0
- package/dist/{chunk-F26GUCGG.js → chunk-4WXOYU2N.js} +32 -9
- package/dist/chunk-6HOIRUQB.mjs +409 -0
- package/dist/chunk-DHLWNT53.js +364 -0
- package/dist/{chunk-H2ET6MMM.mjs → chunk-IPJJMPOO.mjs} +155 -66
- package/dist/{chunk-WYSRJVX4.js → chunk-JJ6AB4ZH.js} +2 -2
- package/dist/{chunk-2W6OCG2S.js → chunk-JNRGUR3O.js} +155 -67
- package/dist/chunk-KF5YBEM5.js +143 -0
- package/dist/{chunk-OJOHB64C.mjs → chunk-LRTDTFFQ.mjs} +28 -5
- package/dist/{chunk-DSWKLUIX.mjs → chunk-NZL6T22V.mjs} +1 -1
- package/dist/chunk-QC6VTSA3.mjs +117 -0
- package/dist/chunk-V5N65MRP.js +411 -0
- package/dist/full/index.d.mts +2 -0
- package/dist/full/index.d.ts +2 -0
- package/dist/full/index.js +7 -6
- package/dist/full/index.mjs +5 -4
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -13
- package/dist/index.mjs +6 -5
- package/dist/metadata/index.d.mts +38 -3
- package/dist/metadata/index.d.ts +38 -3
- package/dist/metadata/index.js +26 -16
- package/dist/metadata/index.mjs +26 -15
- package/dist/resolve-BsLBxlBi.d.mts +24 -0
- package/dist/resolve-BsLBxlBi.d.ts +24 -0
- package/dist/runtime/index.d.mts +2 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +4 -4
- package/dist/runtime/index.mjs +2 -2
- package/dist/shared/index.d.mts +10 -0
- package/dist/shared/index.d.ts +10 -0
- package/dist/shared/index.js +23 -0
- package/dist/shared/index.mjs +2 -0
- package/dist/static/index.js +5 -5
- package/dist/static/index.mjs +2 -2
- package/docs_for_llm/actions.doc.md +87 -0
- package/docs_for_llm/advancedset.doc.md +98 -0
- package/docs_for_llm/affix.doc.md +20 -7
- package/docs_for_llm/aksk.doc.md +111 -0
- package/docs_for_llm/anchor.doc.md +155 -0
- package/docs_for_llm/anchorlink.doc.md +75 -0
- package/docs_for_llm/az.doc.md +17 -11
- package/docs_for_llm/badge.doc.md +11 -5
- package/docs_for_llm/billtypes.doc.md +17 -11
- package/docs_for_llm/breadcrumb.doc.md +80 -4
- package/docs_for_llm/button.doc.md +91 -18
- package/docs_for_llm/buttonlink.doc.md +64 -0
- package/docs_for_llm/card.doc.md +58 -8
- package/docs_for_llm/cardcol.doc.md +78 -0
- package/docs_for_llm/cardcols.doc.md +84 -0
- package/docs_for_llm/cardcontent.doc.md +31 -10
- package/docs_for_llm/cardtabs.doc.md +106 -0
- package/docs_for_llm/carousel.doc.md +79 -7
- package/docs_for_llm/cascader.doc.md +106 -23
- package/docs_for_llm/checkbox.doc.md +25 -13
- package/docs_for_llm/cidrinput.doc.md +83 -0
- package/docs_for_llm/code.doc.md +22 -11
- package/docs_for_llm/collapse.doc.md +147 -14
- package/docs_for_llm/colorpicker.doc.md +104 -0
- package/docs_for_llm/configprovider.doc.md +77 -0
- package/docs_for_llm/copy.doc.md +15 -13
- package/docs_for_llm/copyhover.doc.md +59 -0
- package/docs_for_llm/copyrow.doc.md +80 -0
- package/docs_for_llm/datepicker.doc.md +66 -35
- package/docs_for_llm/description.doc.md +75 -0
- package/docs_for_llm/descriptions.doc.md +122 -10
- package/docs_for_llm/diagram.doc.md +343 -0
- package/docs_for_llm/dialog.doc.md +97 -77
- package/docs_for_llm/divider.doc.md +14 -7
- package/docs_for_llm/drawer.doc.md +114 -69
- package/docs_for_llm/dropdown.doc.md +290 -22
- package/docs_for_llm/duration.doc.md +76 -0
- package/docs_for_llm/editable.doc.md +36 -14
- package/docs_for_llm/ellipsis.doc.md +10 -5
- package/docs_for_llm/filtertablefieldsdialog.doc.md +99 -0
- package/docs_for_llm/flex.doc.md +83 -0
- package/docs_for_llm/form.doc.md +196 -18
- package/docs_for_llm/formiteminput.doc.md +128 -0
- package/docs_for_llm/formitemspinner.doc.md +105 -0
- package/docs_for_llm/formitemswitch.doc.md +113 -0
- package/docs_for_llm/formitemtableconfigs.doc.md +95 -0
- package/docs_for_llm/grid.doc.md +78 -5
- package/docs_for_llm/header.doc.md +114 -0
- package/docs_for_llm/icon.doc.md +12 -8
- package/docs_for_llm/icontooltip.doc.md +121 -0
- package/docs_for_llm/input.doc.md +199 -41
- package/docs_for_llm/instancelist.doc.md +113 -0
- package/docs_for_llm/instancenum.doc.md +95 -0
- package/docs_for_llm/ipinput.doc.md +77 -0
- package/docs_for_llm/kspstatus.doc.md +82 -0
- package/docs_for_llm/kvcode.doc.md +76 -0
- package/docs_for_llm/layoutcontent.doc.md +54 -17
- package/docs_for_llm/layoutlistcontent.doc.md +168 -0
- package/docs_for_llm/layoutpermissioncontent.doc.md +93 -0
- package/docs_for_llm/layoutstandardlist.doc.md +129 -0
- package/docs_for_llm/layouttabs.doc.md +101 -0
- package/docs_for_llm/lazymount.doc.md +82 -0
- package/docs_for_llm/lazyteleport.doc.md +85 -0
- package/docs_for_llm/menu.doc.md +139 -14
- package/docs_for_llm/message.doc.md +93 -10
- package/docs_for_llm/notification.doc.md +214 -0
- package/docs_for_llm/pagination.doc.md +30 -17
- package/docs_for_llm/paginationplus.doc.md +31 -10
- package/docs_for_llm/password.doc.md +86 -0
- package/docs_for_llm/popover.doc.md +24 -55
- package/docs_for_llm/progress.doc.md +13 -10
- package/docs_for_llm/projects.doc.md +91 -0
- package/docs_for_llm/protable.doc.md +98 -15
- package/docs_for_llm/queuevisualrange.doc.md +78 -0
- package/docs_for_llm/radio.doc.md +23 -8
- package/docs_for_llm/rate.doc.md +127 -0
- package/docs_for_llm/region.doc.md +25 -13
- package/docs_for_llm/scrollselect.doc.md +90 -0
- package/docs_for_llm/search.doc.md +120 -0
- package/docs_for_llm/searchinput.doc.md +111 -0
- package/docs_for_llm/searchitems.doc.md +116 -0
- package/docs_for_llm/searchselect.doc.md +126 -0
- package/docs_for_llm/select.doc.md +208 -49
- package/docs_for_llm/sidebar.doc.md +133 -0
- package/docs_for_llm/skeleton.doc.md +152 -0
- package/docs_for_llm/slider.doc.md +42 -22
- package/docs_for_llm/spin.doc.md +18 -6
- package/docs_for_llm/spinner.doc.md +28 -18
- package/docs_for_llm/split.doc.md +170 -0
- package/docs_for_llm/sshkeys.doc.md +88 -0
- package/docs_for_llm/status.doc.md +14 -9
- package/docs_for_llm/steps.doc.md +81 -7
- package/docs_for_llm/switch.doc.md +32 -16
- package/docs_for_llm/table.doc.md +317 -55
- package/docs_for_llm/tablecolumnid.doc.md +36 -16
- package/docs_for_llm/tabs.doc.md +117 -12
- package/docs_for_llm/tag.doc.md +167 -15
- package/docs_for_llm/timeline.doc.md +187 -0
- package/docs_for_llm/timepicker.doc.md +74 -36
- package/docs_for_llm/timerange.doc.md +157 -0
- package/docs_for_llm/tip.doc.md +50 -11
- package/docs_for_llm/tooltip.doc.md +99 -27
- package/docs_for_llm/tour.doc.md +125 -28
- package/docs_for_llm/transfer.doc.md +99 -33
- package/docs_for_llm/tree.doc.md +129 -24
- package/docs_for_llm/treeselect.doc.md +101 -44
- package/docs_for_llm/upload.doc.md +63 -32
- package/docs_for_llm/useCRUD.doc.md +49 -0
- package/docs_for_llm/useCountdown.doc.md +43 -0
- package/docs_for_llm/useDetail.doc.md +48 -0
- package/docs_for_llm/useDialog.doc.md +46 -0
- package/docs_for_llm/useEntity.doc.md +45 -0
- package/docs_for_llm/useEventListener.doc.md +44 -0
- package/docs_for_llm/useFalseUntilTruthy.doc.md +41 -0
- package/docs_for_llm/useGetCopyAuthText.doc.md +35 -0
- package/docs_for_llm/useGetUserPermission.doc.md +43 -0
- package/docs_for_llm/useGroup.doc.md +48 -0
- package/docs_for_llm/useIdEntities.doc.md +48 -0
- package/docs_for_llm/useIdEntity.doc.md +103 -0
- package/docs_for_llm/useInterval.doc.md +43 -0
- package/docs_for_llm/useLayoutStandardList.doc.md +38 -0
- package/docs_for_llm/useMessage.doc.md +46 -0
- package/docs_for_llm/useModifyCache.doc.md +37 -0
- package/docs_for_llm/useOpenDialog.doc.md +41 -0
- package/docs_for_llm/usePagination.doc.md +60 -0
- package/docs_for_llm/usePersist.doc.md +54 -0
- package/docs_for_llm/usePoll.doc.md +41 -0
- package/docs_for_llm/useRoutePlus.doc.md +34 -0
- package/docs_for_llm/useRouterPlus.doc.md +34 -0
- package/docs_for_llm/useSearch.doc.md +68 -0
- package/docs_for_llm/useShell.doc.md +43 -0
- package/docs_for_llm/useSkip.doc.md +41 -0
- package/docs_for_llm/useStorageIdEntity.doc.md +46 -0
- package/docs_for_llm/useStore.doc.md +34 -0
- package/docs_for_llm/useTable.doc.md +57 -0
- package/docs_for_llm/useTableGroup.doc.md +47 -0
- package/docs_for_llm/useTableSort.doc.md +40 -0
- package/docs_for_llm/useToState.doc.md +112 -0
- package/docs_for_llm/useUser.doc.md +38 -0
- package/docs_for_llm/useValidForm.doc.md +41 -0
- package/docs_for_llm/vdialog.doc.md +154 -0
- package/docs_for_llm/vdrawer.doc.md +148 -0
- package/docs_for_llm/virtuallist.doc.md +157 -3
- package/hooks/useCRUD.json +61 -0
- package/hooks/useCountdown.json +49 -0
- package/hooks/useDetail.json +67 -0
- package/hooks/useDialog.json +49 -0
- package/hooks/useEntity.json +61 -0
- package/hooks/useEventListener.json +61 -0
- package/hooks/useFalseUntilTruthy.json +43 -0
- package/hooks/useGetCopyAuthText.json +36 -0
- package/hooks/useGetUserPermission.json +55 -0
- package/hooks/useGroup.json +49 -0
- package/hooks/useIdEntities.json +61 -0
- package/hooks/useInterval.json +55 -0
- package/hooks/useLayoutStandardList.json +36 -0
- package/hooks/useMessage.json +73 -0
- package/hooks/useModifyCache.json +36 -0
- package/hooks/useOpenDialog.json +43 -0
- package/hooks/usePagination.json +49 -0
- package/hooks/usePersist.json +61 -0
- package/hooks/usePoll.json +43 -0
- package/hooks/useRoutePlus.json +36 -0
- package/hooks/useRouterPlus.json +36 -0
- package/hooks/useSearch.json +56 -0
- package/hooks/useShell.json +49 -0
- package/hooks/useSkip.json +43 -0
- package/hooks/useStorageIdEntity.json +67 -0
- package/hooks/useStore.json +36 -0
- package/hooks/useTable.json +49 -0
- package/hooks/useTableGroup.json +43 -0
- package/hooks/useTableSort.json +43 -0
- package/hooks/useUser.json +36 -0
- package/hooks/useValidForm.json +43 -0
- package/package.json +14 -8
- package/dist/chunk-D3Y6FGWA.js +0 -153
- package/dist/chunk-HPAUCD5I.js +0 -156
- package/dist/chunk-L4DS3EXI.mjs +0 -133
- package/dist/chunk-NZ6TLWMD.mjs +0 -151
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# 增强路由跳转 (useRouterPlus)
|
|
2
|
+
|
|
3
|
+
对 vue-router 的导航能力做统一封装,提供新开页签跳转和可回退的导航能力。
|
|
4
|
+
|
|
5
|
+
**关键词**: useRouterPlus, goNewPage, goBack, 路由跳转, 新开页签, vue-router
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useRouterPlus } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 返回值
|
|
13
|
+
```typescript
|
|
14
|
+
{ $router: Router; goNewPage: (to: string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric, currentLocation?: RouteLocationNormalizedLoadedGeneric) => void; goBack: (back?: string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric) => void; }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
18
|
+
### 调用 goBack 但没有提供兜底地址,历史栈不足时体验不稳定
|
|
19
|
+
> **错误用法**: `goBack();`
|
|
20
|
+
> **正确写法**: `goBack({ name: 'instance-list' });`
|
|
21
|
+
> **说明**: 在业务列表/详情页之间跳转时,建议提供明确回退目标。
|
|
22
|
+
|
|
23
|
+
## 使用示例
|
|
24
|
+
### 跳转详情页或新页签打开
|
|
25
|
+
在列表页操作列中统一处理跳转行为
|
|
26
|
+
|
|
27
|
+
```vue
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import { useRouterPlus } from '@ksyun-internal/versatile';
|
|
30
|
+
|
|
31
|
+
const { goNewPage, goBack } = useRouterPlus();
|
|
32
|
+
</script>
|
|
33
|
+
```
|
|
34
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# 搜索状态管理 (useSearch)
|
|
2
|
+
|
|
3
|
+
管理 Search 和 SearchItems 常用的搜索状态,统一维护 searchKey、searchValue、searchItems 及其变更方法。配合列表页分页时可在筛选变化后重置页码。
|
|
4
|
+
|
|
5
|
+
**关键词**: useSearch, Search, SearchItems, 列表筛选, 搜索状态, 检索条件
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useSearch } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| options | `{ defaultSearchKey?: string; page?: Ref<number> }` | 否 | 初始化配置,可指定默认搜索字段,并传入分页页码以便搜索变化时联动重置 |
|
|
16
|
+
|
|
17
|
+
## 返回值
|
|
18
|
+
```typescript
|
|
19
|
+
{ searchKey: Ref<string>; searchKeyRela: Ref<string>; searchValue: Ref<string>; searchItems: Ref<T | undefined>; searchItemsRef: Ref<any>; handleChangeSearchValue: Function; handleChangeSingleValue: Function; handleChangeSearchSingleValue: Function; }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
23
|
+
### 列表页搜索变化时没有传入 page,导致筛选后仍停留在旧页码
|
|
24
|
+
> **错误用法**: `const search = useSearch();`
|
|
25
|
+
> **正确写法**: `const search = useSearch({ page });`
|
|
26
|
+
> **说明**: 在分页列表中建议把 page 传给 useSearch,让搜索条件变化时同步回到第一页。
|
|
27
|
+
|
|
28
|
+
### 重复自己维护 searchKey/searchValue,和 hook 返回值并存
|
|
29
|
+
> **错误用法**: `const searchKey = ref('name'); const searchValue = ref(''); const { searchItems } = useSearch();`
|
|
30
|
+
> **正确写法**: `const { searchKey, searchValue, searchItems } = useSearch({ defaultSearchKey: 'name' });`
|
|
31
|
+
> **说明**: 优先使用 useSearch 返回的整套状态,避免来源分裂。
|
|
32
|
+
|
|
33
|
+
## 使用示例
|
|
34
|
+
### 列表页搜索状态
|
|
35
|
+
在列表页中统一维护搜索 key、搜索值和搜索项
|
|
36
|
+
|
|
37
|
+
```vue
|
|
38
|
+
<script setup lang="ts">
|
|
39
|
+
import { Search, SearchItems, usePagination, useSearch } from '@ksyun-internal/versatile';
|
|
40
|
+
|
|
41
|
+
const { page } = usePagination();
|
|
42
|
+
const { searchKey, searchValue, searchItems } = useSearch({
|
|
43
|
+
defaultSearchKey: 'name',
|
|
44
|
+
page,
|
|
45
|
+
});
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<Search v-model:search-key="searchKey" v-model:search-value="searchValue" :searches="[]" />
|
|
50
|
+
<SearchItems v-model="searchItems" />
|
|
51
|
+
</template>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 手动处理搜索值变更
|
|
55
|
+
通过返回的方法接管批量搜索或单值搜索的更新逻辑
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<script setup lang="ts">
|
|
59
|
+
import { useSearch } from '@ksyun-internal/versatile';
|
|
60
|
+
|
|
61
|
+
const { handleChangeSearchValue } = useSearch();
|
|
62
|
+
|
|
63
|
+
const onSearch = (value?: string) => {
|
|
64
|
+
handleChangeSearchValue(value, value);
|
|
65
|
+
};
|
|
66
|
+
</script>
|
|
67
|
+
```
|
|
68
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Shell 内容挂载 (useShell)
|
|
2
|
+
|
|
3
|
+
在弹窗显示时把 shell 或命令内容挂载到指定容器引用,适合命令预览、终端输出展示等场景。
|
|
4
|
+
|
|
5
|
+
**关键词**: useShell, shell, 命令预览, dialog content, 终端输出, shellRef
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useShell } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| content | `WatchSource<string | undefined | null>` | 是 | 需要展示的 shell 内容 |
|
|
16
|
+
| isShowDialog | `Ref<boolean>` | 是 | 弹窗显隐状态 |
|
|
17
|
+
|
|
18
|
+
## 返回值
|
|
19
|
+
```typescript
|
|
20
|
+
{ shellRef: Ref<any> }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
24
|
+
### 传入一次性字符串字面量,后续更新不会同步
|
|
25
|
+
> **错误用法**: `useShell('kubectl get pods', isShowDialog);`
|
|
26
|
+
> **正确写法**: `const content = ref('kubectl get pods'); useShell(content, isShowDialog);`
|
|
27
|
+
> **说明**: 内容建议使用 Ref 或 getter,便于后续更新时同步渲染。
|
|
28
|
+
|
|
29
|
+
## 使用示例
|
|
30
|
+
### 命令预览弹窗
|
|
31
|
+
在弹窗打开时渲染命令或脚本内容
|
|
32
|
+
|
|
33
|
+
```vue
|
|
34
|
+
<script setup lang="ts">
|
|
35
|
+
import { ref } from 'vue';
|
|
36
|
+
import { useShell } from '@ksyun-internal/versatile';
|
|
37
|
+
|
|
38
|
+
const content = ref('kubectl get pods');
|
|
39
|
+
const isShowDialog = ref(false);
|
|
40
|
+
const { shellRef } = useShell(content, isShowDialog);
|
|
41
|
+
</script>
|
|
42
|
+
```
|
|
43
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# 头部返回跳转 (useSkip)
|
|
2
|
+
|
|
3
|
+
从 Header 的 back 配置中提取统一跳转逻辑,适合详情页和购买链路页的返回按钮行为。
|
|
4
|
+
|
|
5
|
+
**关键词**: useSkip, Header back, 返回跳转, 详情页返回, goLink, layout header
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useSkip } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| back | `Ref<LayoutHeaderProps['back']>` | 是 | Header 的 back 配置项 |
|
|
16
|
+
|
|
17
|
+
## 返回值
|
|
18
|
+
```typescript
|
|
19
|
+
{ goLink: () => any }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
23
|
+
### 直接传普通对象而不是 Ref,导致 back 配置变化无法联动
|
|
24
|
+
> **错误用法**: `useSkip({ to: { name: 'list' } });`
|
|
25
|
+
> **正确写法**: `const back = ref({ to: { name: 'list' } }); useSkip(back);`
|
|
26
|
+
> **说明**: hook 设计为消费 Header back 的响应式配置。
|
|
27
|
+
|
|
28
|
+
## 使用示例
|
|
29
|
+
### Header 返回按钮
|
|
30
|
+
复用 Header back 配置实现统一返回跳转
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<script setup lang="ts">
|
|
34
|
+
import { ref } from 'vue';
|
|
35
|
+
import { useSkip } from '@ksyun-internal/versatile';
|
|
36
|
+
|
|
37
|
+
const back = ref({ to: { name: 'instance-list' } });
|
|
38
|
+
const { goLink } = useSkip(back);
|
|
39
|
+
</script>
|
|
40
|
+
```
|
|
41
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# 带存储的 ID 实体映射 (useStorageIdEntity)
|
|
2
|
+
|
|
3
|
+
在 useIdEntity 的基础上增加存储键能力,适合把当前选中的实体 ID 与本地缓存联动,支持刷新后恢复选择。
|
|
4
|
+
|
|
5
|
+
**关键词**: useStorageIdEntity, 本地记忆选择, storage, 实体映射, 刷新恢复, workspace
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useStorageIdEntity } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| id | `Ref<string | number | undefined | null>` | 是 | 当前选中的实体 ID |
|
|
16
|
+
| list | `Ref<Entity[] | undefined | null>` | 是 | 实体源列表 |
|
|
17
|
+
| key | `keyof Entity` | 是 | 实体主键字段 |
|
|
18
|
+
| storageName | `string` | 否 | 本地存储使用的键名 |
|
|
19
|
+
| emit | `(entity: Entity | undefined) => void` | 否 | 实体变化时的回调 |
|
|
20
|
+
|
|
21
|
+
## 返回值
|
|
22
|
+
```typescript
|
|
23
|
+
Ref<Entity | undefined>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
27
|
+
### 多个页面复用同一个 storageName,导致选择串数据
|
|
28
|
+
> **错误用法**: `useStorageIdEntity(id, list, 'id', 'selected-id');`
|
|
29
|
+
> **正确写法**: `useStorageIdEntity(id, list, 'id', 'instance-workspace-id');`
|
|
30
|
+
> **说明**: storageName 建议按业务域区分,避免不同页面互相覆盖。
|
|
31
|
+
|
|
32
|
+
## 使用示例
|
|
33
|
+
### 记住上次选择的实体
|
|
34
|
+
页面刷新后仍恢复用户上次选择的对象
|
|
35
|
+
|
|
36
|
+
```vue
|
|
37
|
+
<script setup lang="ts">
|
|
38
|
+
import { ref } from 'vue';
|
|
39
|
+
import { useStorageIdEntity } from '@ksyun-internal/versatile';
|
|
40
|
+
|
|
41
|
+
const selectedId = ref('ws-001');
|
|
42
|
+
const workspaceList = ref([{ WorkspaceId: 'ws-001', WorkspaceName: '工作空间1' }]);
|
|
43
|
+
const currentWorkspace = useStorageIdEntity(selectedId, workspaceList, 'WorkspaceId', 'workspace-id');
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# 轻量全局状态 (useStore)
|
|
2
|
+
|
|
3
|
+
读取和写入 versatile 内部维护的轻量全局状态,当前暴露地域 key 和地域列表的读写能力。
|
|
4
|
+
|
|
5
|
+
**关键词**: useStore, regionKey, regionList, 全局状态, 地域缓存, 共享状态
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useStore } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 返回值
|
|
13
|
+
```typescript
|
|
14
|
+
{ setRegionKey: (regionKey: string) => void; setRegionList: (regionList: any[]) => void; regionKey: ComputedRef<string>; regionList: ComputedRef<any[]>; }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
18
|
+
### 直接修改 regionList/regionKey,而不是走 setter
|
|
19
|
+
> **错误用法**: `regionKey.value = 'cn-beijing-6';`
|
|
20
|
+
> **正确写法**: `setRegionKey('cn-beijing-6');`
|
|
21
|
+
> **说明**: 返回的状态是 computed,只读修改应通过 setter 完成。
|
|
22
|
+
|
|
23
|
+
## 使用示例
|
|
24
|
+
### 共享地域状态
|
|
25
|
+
在 Region、AZ 或购买页中共享当前地域选择
|
|
26
|
+
|
|
27
|
+
```vue
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import { useStore } from '@ksyun-internal/versatile';
|
|
30
|
+
|
|
31
|
+
const { regionKey, regionList, setRegionKey, setRegionList } = useStore();
|
|
32
|
+
</script>
|
|
33
|
+
```
|
|
34
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# 表格状态管理 (useTable)
|
|
2
|
+
|
|
3
|
+
集中管理表格勾选、展开、列显隐和导出相关状态,适合原子 Table 和业务表格容器共享同一套表格控制逻辑。
|
|
4
|
+
|
|
5
|
+
**关键词**: useTable, Table, 勾选状态, 列显隐, 导出表格, rowKey
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useTable } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| options | `{ rowKey?: string; notCheckTip?: string; tableFields?: TableFields }` | 否 | 表格配置,可指定 rowKey、未勾选提示文案和列配置定义 |
|
|
16
|
+
|
|
17
|
+
## 返回值
|
|
18
|
+
```typescript
|
|
19
|
+
{ checkedKeys: Ref<string[]>; expandedKeys: Ref<(string | number)[]>; isChecked: ComputedRef<number>; canCheck: ComputedRef<{ disabled: boolean; msg: string }>; tableRef: Ref<Table | undefined>; componentRef: Ref<any>; noCheckedColFields: Ref<string[]>; setRowKey: Function; exportTableData: Function; hideCol: Function; getTableColTitle: ((key: string) => string) | null; initTableColumnProps: Function; }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
23
|
+
### 多选或导出场景没有稳定 rowKey,导致勾选数据不稳定
|
|
24
|
+
> **错误用法**: `const table = useTable();`
|
|
25
|
+
> **正确写法**: `const table = useTable({ rowKey: 'id' });`
|
|
26
|
+
> **说明**: 在业务表格中建议显式指定 rowKey,避免勾选项和导出数据映射错乱。
|
|
27
|
+
|
|
28
|
+
## 使用示例
|
|
29
|
+
### 管理表格勾选和列显隐
|
|
30
|
+
在列表页中集中维护勾选状态和动态列配置
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<script setup lang="ts">
|
|
34
|
+
import { useTable } from '@ksyun-internal/versatile';
|
|
35
|
+
|
|
36
|
+
const tableFields = [
|
|
37
|
+
{ key: 'name', label: '实例名称', checked: true },
|
|
38
|
+
{ key: 'status', label: '状态', checked: true },
|
|
39
|
+
];
|
|
40
|
+
const { checkedKeys, tableRef, canCheck, initTableColumnProps } = useTable({
|
|
41
|
+
rowKey: 'id',
|
|
42
|
+
tableFields,
|
|
43
|
+
});
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 导出当前表格数据
|
|
48
|
+
通过 hook 暴露的导出方法触发表格导出
|
|
49
|
+
|
|
50
|
+
```vue
|
|
51
|
+
<script setup lang="ts">
|
|
52
|
+
import { useTable } from '@ksyun-internal/versatile';
|
|
53
|
+
|
|
54
|
+
const { exportTableData } = useTable({ rowKey: 'id' });
|
|
55
|
+
</script>
|
|
56
|
+
```
|
|
57
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# 表格分组筛选状态 (useTableGroup)
|
|
2
|
+
|
|
3
|
+
管理 Table 或 ProTable 的 group 筛选状态,并可与 SearchItems 联动生成可展示的筛选项。
|
|
4
|
+
|
|
5
|
+
**关键词**: useTableGroup, group, ProTable, 表格筛选, SearchItems, 状态分组
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useTableGroup } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| options | `{ page?: Ref<number>; key?: string; defalutValue?: any; searchItemsRef?: Ref<any>; labelMaps?: Record<string, string> | Ref<Record<string, string>>; groupLabel?: string | Record<string, string | { label: string }>; isShowSearchItem?: boolean }` | 否 | 分组筛选配置,可联动分页、SearchItems 和字段标签映射 |
|
|
16
|
+
|
|
17
|
+
## 返回值
|
|
18
|
+
```typescript
|
|
19
|
+
{ status: ComputedRef<any>; group: Ref<Record<string, any>>; resetGroup: Function; changeGroup: Function; }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
23
|
+
### SearchItems 展示 group 条件时没有提供 labelMaps 或 groupLabel
|
|
24
|
+
> **错误用法**: `useTableGroup({ searchItemsRef });`
|
|
25
|
+
> **正确写法**: `useTableGroup({ searchItemsRef, labelMaps, groupLabel: '状态' });`
|
|
26
|
+
> **说明**: 如果要把 group 同步到 SearchItems,建议补齐展示文案映射。
|
|
27
|
+
|
|
28
|
+
## 使用示例
|
|
29
|
+
### 配合 ProTable 的 group 筛选
|
|
30
|
+
将 group 状态和 SearchItems 联动,统一驱动表格筛选
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<script setup lang="ts">
|
|
34
|
+
import { ref } from 'vue';
|
|
35
|
+
import { usePagination, useTableGroup } from '@ksyun-internal/versatile';
|
|
36
|
+
|
|
37
|
+
const { page } = usePagination();
|
|
38
|
+
const searchItemsRef = ref();
|
|
39
|
+
const { group, changeGroup, resetGroup } = useTableGroup({
|
|
40
|
+
page,
|
|
41
|
+
key: 'status',
|
|
42
|
+
searchItemsRef,
|
|
43
|
+
labelMaps: { using: '运行中', shutdown: '已关机' },
|
|
44
|
+
});
|
|
45
|
+
</script>
|
|
46
|
+
```
|
|
47
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# 表格排序状态 (useTableSort)
|
|
2
|
+
|
|
3
|
+
统一管理表格排序字段和方向,并提供多种派生排序状态,适合请求参数、UI 高亮和布尔/整数映射场景。
|
|
4
|
+
|
|
5
|
+
**关键词**: useTableSort, 排序, TableSortValue, ProTable, 列表排序, sort
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useTableSort } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| page | `Ref<number | undefined>` | 否 | 分页页码,传入后在切换排序时可联动重置页码 |
|
|
16
|
+
|
|
17
|
+
## 返回值
|
|
18
|
+
```typescript
|
|
19
|
+
{ sort: Ref<TableSortValue>; curSortKey: ComputedRef<string | undefined>; curSortType: ComputedRef<'desc' | 'asc' | undefined>; curSortTypeByInt: ComputedRef<0 | 1 | -1>; curSortTypeByBoolean: ComputedRef<boolean | ''>; changeSort: Function; }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
23
|
+
### 自己维护 asc/desc 和 0/1/-1 的映射,重复实现 hook 已有能力
|
|
24
|
+
> **错误用法**: `const sortType = computed(() => sort.value.type === 'asc' ? 1 : -1);`
|
|
25
|
+
> **正确写法**: `const { curSortTypeByInt } = useTableSort(page);`
|
|
26
|
+
> **说明**: hook 已经提供多种派生排序表示,优先复用。
|
|
27
|
+
|
|
28
|
+
## 使用示例
|
|
29
|
+
### 列表排序状态
|
|
30
|
+
将排序状态集中管理,并把变更方法绑定给表格
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<script setup lang="ts">
|
|
34
|
+
import { usePagination, useTableSort } from '@ksyun-internal/versatile';
|
|
35
|
+
|
|
36
|
+
const { page } = usePagination();
|
|
37
|
+
const { sort, curSortKey, curSortType, changeSort } = useTableSort(page);
|
|
38
|
+
</script>
|
|
39
|
+
```
|
|
40
|
+
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Props 转 State (useToState)
|
|
2
|
+
|
|
3
|
+
将 props 中的属性转换为响应式 state,支持 v-model 双向绑定。当 props 变化时自动更新 state,当 state 变化时自动触发 emit 更新父组件。
|
|
4
|
+
|
|
5
|
+
**关键词**: useToState, props, state, v-model, 双向绑定, 响应式
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useToState } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| props | `P extends object` | 是 | 组件的 props 对象(通过 defineProps 获取) |
|
|
16
|
+
| key | `keyof P` | 是 | 要监听的 prop 名称(字符串) |
|
|
17
|
+
| emit | `Emits<K & string, P[K]>` | 是 | 组件的 emit 函数(通过 defineEmits 获取),需要包含 update:key 事件 |
|
|
18
|
+
| defaults | `NonNullable<P[K]>` | 否 | 默认值。如果提供,返回的 Ref 将保证不为 undefined |
|
|
19
|
+
|
|
20
|
+
## 重载签名 (Overloads)
|
|
21
|
+
### `useToState<P, K>(props: P, key: K, emit: Emits): Ref<P[K]>`
|
|
22
|
+
基础用法,返回可能为 undefined 的响应式值
|
|
23
|
+
|
|
24
|
+
### `useToState<P, K>(props: P, key: K, emit: Emits, defaults: NonNullable<P[K]>): Ref<NonNullable<P[K]>>`
|
|
25
|
+
带默认值用法,返回保证非 undefined 的响应式值
|
|
26
|
+
|
|
27
|
+
## 返回值
|
|
28
|
+
```typescript
|
|
29
|
+
Ref<P[K]>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
33
|
+
### 忘记传递 emit 参数
|
|
34
|
+
> **错误用法**: `const value = useToState(props, 'modelValue');`
|
|
35
|
+
> **正确写法**: `const value = useToState(props, 'modelValue', emit);`
|
|
36
|
+
> **说明**: useToState 需要 emit 函数来实现双向绑定,缺少 emit 会导致编译错误
|
|
37
|
+
|
|
38
|
+
### emit 没有定义对应的 update:key 事件
|
|
39
|
+
> **错误用法**: `const emit = defineEmits(['change']);
|
|
40
|
+
const value = useToState(props, 'modelValue', emit);`
|
|
41
|
+
> **正确写法**: `const emit = defineEmits(['update:modelValue']);
|
|
42
|
+
const value = useToState(props, 'modelValue', emit);`
|
|
43
|
+
> **说明**: useToState 内部会调用 emit('update:key', newValue),必须在 defineEmits 中声明对应事件
|
|
44
|
+
|
|
45
|
+
### key 参数不是 props 中定义的属性
|
|
46
|
+
> **错误用法**: `const props = defineProps<{ name: string }>();
|
|
47
|
+
const value = useToState(props, 'age', emit);`
|
|
48
|
+
> **正确写法**: `const props = defineProps<{ name: string; age?: number }>();
|
|
49
|
+
const value = useToState(props, 'age', emit);`
|
|
50
|
+
> **说明**: key 必须是 props 中已定义的属性名
|
|
51
|
+
|
|
52
|
+
## 使用示例
|
|
53
|
+
### 基础用法
|
|
54
|
+
将 modelValue prop 转换为响应式 state
|
|
55
|
+
|
|
56
|
+
```vue
|
|
57
|
+
<script setup lang="ts">
|
|
58
|
+
import { useToState } from '@ksyun-internal/versatile';
|
|
59
|
+
|
|
60
|
+
type Props = { modelValue?: string };
|
|
61
|
+
type Emits = { (e: 'update:modelValue', v?: string): void };
|
|
62
|
+
|
|
63
|
+
const props = defineProps<Props>();
|
|
64
|
+
const emit = defineEmits<Emits>();
|
|
65
|
+
|
|
66
|
+
const value = useToState(props, 'modelValue', emit);
|
|
67
|
+
</script>
|
|
68
|
+
<template>
|
|
69
|
+
<input v-model="value" />
|
|
70
|
+
</template>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 带默认值用法
|
|
74
|
+
提供默认值,确保返回值不为 undefined
|
|
75
|
+
|
|
76
|
+
```vue
|
|
77
|
+
<script setup lang="ts">
|
|
78
|
+
import { useToState } from '@ksyun-internal/versatile';
|
|
79
|
+
|
|
80
|
+
const props = defineProps<{ count?: number }>();
|
|
81
|
+
const emit = defineEmits(['update:count']);
|
|
82
|
+
|
|
83
|
+
// 默认值为 0,count 永远不为 undefined
|
|
84
|
+
const count = useToState(props, 'count', emit, 0);
|
|
85
|
+
</script>
|
|
86
|
+
<template>
|
|
87
|
+
<div>{{ count }}</div>
|
|
88
|
+
</template>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 对象类型值
|
|
92
|
+
将对象类型的 prop 转换为响应式 state
|
|
93
|
+
|
|
94
|
+
```vue
|
|
95
|
+
<script setup lang="ts">
|
|
96
|
+
import { useToState } from '@ksyun-internal/versatile';
|
|
97
|
+
|
|
98
|
+
type FormData = { name: string; age: number };
|
|
99
|
+
type Props = { modelValue?: FormData };
|
|
100
|
+
type Emits = { (e: 'update:modelValue', v?: FormData): void };
|
|
101
|
+
|
|
102
|
+
const props = defineProps<Props>();
|
|
103
|
+
const emit = defineEmits<Emits>();
|
|
104
|
+
|
|
105
|
+
const formData = useToState(props, 'modelValue', emit, { name: '', age: 0 });
|
|
106
|
+
</script>
|
|
107
|
+
<template>
|
|
108
|
+
<input v-model="formData.name" />
|
|
109
|
+
<input v-model.number="formData.age" />
|
|
110
|
+
</template>
|
|
111
|
+
```
|
|
112
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# 当前用户信息 (useUser)
|
|
2
|
+
|
|
3
|
+
获取当前登录用户信息,适合在业务组件中读取 root 权限、当前用户 ID 或账号属性。
|
|
4
|
+
|
|
5
|
+
**关键词**: useUser, 当前用户, 权限, isRoot, curUserId, 账号信息
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useUser } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 返回值
|
|
13
|
+
```typescript
|
|
14
|
+
Ref<UserInfo | undefined>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
18
|
+
### 直接访问 user.value 的属性,没有处理未加载完成的情况
|
|
19
|
+
> **错误用法**: `const isRoot = user.value.isRoot;`
|
|
20
|
+
> **正确写法**: `const isRoot = user.value?.isRoot;`
|
|
21
|
+
> **说明**: 返回值是 Ref<UserInfo | undefined>,初始化阶段可能为空。
|
|
22
|
+
|
|
23
|
+
## 使用示例
|
|
24
|
+
### 读取当前用户信息
|
|
25
|
+
在页面初始化时获取当前用户及权限信息
|
|
26
|
+
|
|
27
|
+
```vue
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import { useUser } from '@ksyun-internal/versatile';
|
|
30
|
+
|
|
31
|
+
const user = useUser();
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<div v-if="user">{{ user.curUserId }}</div>
|
|
36
|
+
</template>
|
|
37
|
+
```
|
|
38
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# 表单校验管理 (useValidForm)
|
|
2
|
+
|
|
3
|
+
封装 Form 实例的校验、重置和滚动定位能力,适合页面表单和弹窗表单统一管理。
|
|
4
|
+
|
|
5
|
+
**关键词**: useValidForm, 表单校验, Form, validateByScroll, reset, 滚动定位
|
|
6
|
+
|
|
7
|
+
## 导入语句
|
|
8
|
+
```typescript
|
|
9
|
+
import { useValidForm } from '@ksyun-internal/versatile';
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 参数 (Params)
|
|
13
|
+
| 参数名 | 类型 | 必填 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| models | `Ref<T>` | 否 | 表单模型对象,可在 reset 时恢复默认值 |
|
|
16
|
+
|
|
17
|
+
## 返回值
|
|
18
|
+
```typescript
|
|
19
|
+
{ formRef: Ref<Form | undefined>; validate: Function; validateByScroll: Function; reset: Function; scrollIntoFirstInvalidFormItem: Function; }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 常见错误与正确用法 (Anti-Hallucination)
|
|
23
|
+
### 希望 reset 恢复初始模型,但没有把 models 传给 hook
|
|
24
|
+
> **错误用法**: `const { reset } = useValidForm();`
|
|
25
|
+
> **正确写法**: `const { reset } = useValidForm(models);`
|
|
26
|
+
> **说明**: 如果需要重置业务表单值,建议把模型 Ref 传入 useValidForm。
|
|
27
|
+
|
|
28
|
+
## 使用示例
|
|
29
|
+
### 页面表单校验
|
|
30
|
+
在提交前统一校验并定位第一个错误项
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<script setup lang="ts">
|
|
34
|
+
import { ref } from 'vue';
|
|
35
|
+
import { useValidForm } from '@ksyun-internal/versatile';
|
|
36
|
+
|
|
37
|
+
const models = ref({ name: '', region: '' });
|
|
38
|
+
const { formRef, validateByScroll } = useValidForm(models);
|
|
39
|
+
</script>
|
|
40
|
+
```
|
|
41
|
+
|