x-next 1.13.0 → 1.14.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 (138) hide show
  1. package/AI_CODING.md +6 -5
  2. package/AI_USAGE/catalog.md +106 -105
  3. package/AI_USAGE/components/alert-api.md +48 -0
  4. package/AI_USAGE/components/alert.md +222 -3
  5. package/AI_USAGE/components/bar-chart-api.md +177 -0
  6. package/AI_USAGE/components/bar-chart.md +297 -3
  7. package/AI_USAGE/components/boxicons.md +147 -0
  8. package/AI_USAGE/components/button-api.md +144 -0
  9. package/AI_USAGE/components/button.md +447 -3
  10. package/AI_USAGE/components/charts.md +81 -0
  11. package/AI_USAGE/components/checkbox-api.md +145 -0
  12. package/AI_USAGE/components/checkbox.md +365 -3
  13. package/AI_USAGE/components/color-picker-api.md +52 -0
  14. package/AI_USAGE/components/color-picker.md +211 -3
  15. package/AI_USAGE/components/config-provider-api.md +38 -0
  16. package/AI_USAGE/components/config-provider.md +250 -3
  17. package/AI_USAGE/components/date-picker-api.md +1114 -0
  18. package/AI_USAGE/components/date-picker.md +378 -3
  19. package/AI_USAGE/components/dialog-api.md +142 -0
  20. package/AI_USAGE/components/dialog.md +284 -3
  21. package/AI_USAGE/components/draggable-api.md +146 -0
  22. package/AI_USAGE/components/draggable.md +259 -0
  23. package/AI_USAGE/components/drawer-api.md +78 -0
  24. package/AI_USAGE/components/drawer.md +227 -0
  25. package/AI_USAGE/components/dropdown-api.md +529 -0
  26. package/AI_USAGE/components/dropdown.md +392 -3
  27. package/AI_USAGE/components/empty-api.md +36 -0
  28. package/AI_USAGE/components/empty.md +227 -3
  29. package/AI_USAGE/components/finicon.md +88 -0
  30. package/AI_USAGE/components/form-api.md +524 -0
  31. package/AI_USAGE/components/form.md +454 -0
  32. package/AI_USAGE/components/grid-api.md +527 -0
  33. package/AI_USAGE/components/grid.md +224 -0
  34. package/AI_USAGE/components/heatmap-api.md +122 -0
  35. package/AI_USAGE/components/heatmap.md +220 -0
  36. package/AI_USAGE/components/icon-api.md +4707 -0
  37. package/AI_USAGE/components/icon.md +257 -0
  38. package/AI_USAGE/components/image-api.md +440 -0
  39. package/AI_USAGE/components/image.md +465 -0
  40. package/AI_USAGE/components/input-api.md +184 -0
  41. package/AI_USAGE/components/input-number-api.md +66 -0
  42. package/AI_USAGE/components/input-number.md +294 -0
  43. package/AI_USAGE/components/input-tag-api.md +114 -0
  44. package/AI_USAGE/components/input-tag.md +482 -0
  45. package/AI_USAGE/components/input.md +293 -3
  46. package/AI_USAGE/components/layout-api.md +147 -0
  47. package/AI_USAGE/components/layout.md +230 -0
  48. package/AI_USAGE/components/line-chart-api.md +197 -0
  49. package/AI_USAGE/components/line-chart.md +279 -3
  50. package/AI_USAGE/components/link-api.md +42 -0
  51. package/AI_USAGE/components/link.md +197 -0
  52. package/AI_USAGE/components/menu-api.md +516 -0
  53. package/AI_USAGE/components/menu.md +268 -0
  54. package/AI_USAGE/components/message-api.md +215 -0
  55. package/AI_USAGE/components/message-box-api.md +108 -0
  56. package/AI_USAGE/components/message-box.md +268 -3
  57. package/AI_USAGE/components/message.md +231 -3
  58. package/AI_USAGE/components/network-api.md +91 -0
  59. package/AI_USAGE/components/network.md +378 -0
  60. package/AI_USAGE/components/notification-api.md +236 -0
  61. package/AI_USAGE/components/notification.md +275 -3
  62. package/AI_USAGE/components/pagination-api.md +62 -0
  63. package/AI_USAGE/components/pagination.md +380 -3
  64. package/AI_USAGE/components/pie-chart-api.md +109 -0
  65. package/AI_USAGE/components/pie-chart.md +245 -3
  66. package/AI_USAGE/components/popconfirm-api.md +75 -0
  67. package/AI_USAGE/components/popconfirm.md +231 -3
  68. package/AI_USAGE/components/popover-api.md +75 -0
  69. package/AI_USAGE/components/popover.md +208 -3
  70. package/AI_USAGE/components/popup-api.md +75 -0
  71. package/AI_USAGE/components/popup.md +52 -0
  72. package/AI_USAGE/components/progress-api.md +44 -0
  73. package/AI_USAGE/components/progress.md +248 -3
  74. package/AI_USAGE/components/radio-api.md +165 -0
  75. package/AI_USAGE/components/radio.md +259 -3
  76. package/AI_USAGE/components/rate-api.md +54 -0
  77. package/AI_USAGE/components/rate.md +233 -3
  78. package/AI_USAGE/components/resize-box-api.md +56 -0
  79. package/AI_USAGE/components/resize-box.md +231 -0
  80. package/AI_USAGE/components/scrollbar-api.md +77 -0
  81. package/AI_USAGE/components/scrollbar.md +218 -0
  82. package/AI_USAGE/components/select-api.md +758 -0
  83. package/AI_USAGE/components/select.md +640 -3
  84. package/AI_USAGE/components/skeleton-api.md +85 -0
  85. package/AI_USAGE/components/skeleton.md +150 -0
  86. package/AI_USAGE/components/slider-api.md +51 -0
  87. package/AI_USAGE/components/slider.md +233 -3
  88. package/AI_USAGE/components/space-api.md +38 -0
  89. package/AI_USAGE/components/space.md +145 -0
  90. package/AI_USAGE/components/spin-api.md +43 -0
  91. package/AI_USAGE/components/spin.md +205 -0
  92. package/AI_USAGE/components/steps-api.md +111 -0
  93. package/AI_USAGE/components/steps.md +201 -3
  94. package/AI_USAGE/components/switch-api.md +58 -0
  95. package/AI_USAGE/components/switch.md +290 -3
  96. package/AI_USAGE/components/table-api.md +2919 -0
  97. package/AI_USAGE/components/table.md +1414 -0
  98. package/AI_USAGE/components/tabs-api.md +135 -0
  99. package/AI_USAGE/components/tabs.md +308 -3
  100. package/AI_USAGE/components/tag-api.md +124 -0
  101. package/AI_USAGE/components/tag.md +292 -0
  102. package/AI_USAGE/components/textarea-api.md +55 -0
  103. package/AI_USAGE/components/textarea.md +326 -3
  104. package/AI_USAGE/components/time-picker-api.md +137 -0
  105. package/AI_USAGE/components/time-picker.md +271 -3
  106. package/AI_USAGE/components/time-range-selector-api.md +44 -0
  107. package/AI_USAGE/components/time-range-selector.md +355 -0
  108. package/AI_USAGE/components/timeline-api.md +93 -0
  109. package/AI_USAGE/components/timeline.md +312 -0
  110. package/AI_USAGE/components/tooltip-api.md +77 -0
  111. package/AI_USAGE/components/tooltip.md +182 -0
  112. package/AI_USAGE/components/trend-chart-api.md +119 -0
  113. package/AI_USAGE/components/trend-chart.md +335 -0
  114. package/AI_USAGE/components/trigger-api.md +124 -0
  115. package/AI_USAGE/components/trigger.md +185 -0
  116. package/AI_USAGE/components/upload-api.md +200 -0
  117. package/AI_USAGE/components/upload.md +711 -3
  118. package/AI_USAGE/components/watermark-api.md +87 -0
  119. package/AI_USAGE/components/watermark.md +200 -0
  120. package/AI_USAGE/core.md +1 -1
  121. package/AI_USAGE/index.md +35 -7
  122. package/AI_USAGE/recipes/form-on-demand.md +1 -1
  123. package/AI_USAGE.md +33651 -5
  124. package/CHANGELOG.md +18 -0
  125. package/dist/_utils/inherit-component-type.d.ts +11 -0
  126. package/dist/components/date-picker/index.d.ts +420 -5
  127. package/dist/components/form-input/index.d.ts +617 -2
  128. package/dist/components/layout/index.d.ts +689 -1
  129. package/dist/components/menu/index.d.ts +786 -1
  130. package/dist/es/_utils/inherit-component-type.js +6 -0
  131. package/dist/es/components/date-picker/index.js +18 -17
  132. package/dist/es/components/form-input/index.js +12 -11
  133. package/dist/es/components/layout/index.js +10 -9
  134. package/dist/es/components/menu/hooks/use-level.js +5 -5
  135. package/dist/es/components/menu/index.js +13 -10
  136. package/dist/index.cjs +3 -3
  137. package/dist/index.umd.js +3 -3
  138. package/package.json +10 -5
@@ -1,12 +1,14 @@
1
1
  <!-- Generated by pnpm generate:ai-usage. Edit script/ai-usage/content.md and script/ai-usage/. -->
2
2
  # Steps AI 使用
3
3
 
4
- 适用版本:x-next@1.13.0;来源指纹:`18e9b8eefa53b4bd91134fb4486778509ccf3a8d614a1bd387a6d469b623ddcf`。
4
+ 适用版本:x-next@1.14.0;来源指纹:`014984639d816a2c7e25eb22690c586b0b2e8efba6846bec8a4e424db41a09e9`。
5
5
 
6
- 先读 [通用接入](../core.md)。公开导出:`Steps`;模型:v-model:current;已核对事件:change。
6
+ 先读 [通用接入](../core.md)。公开导出:`Step, Steps`;主要模型:v-model:current。完整 Props、Events、Slots、实例方法与服务签名见 [本地 API](./steps-api.md),包含本组件族全部子组件和别名。
7
7
 
8
8
  按需样式:`x-next/style/steps`(包含 base.css、steps.css)。代码块未单独引样式时在应用入口加载全量样式,或按实际所有组件加载 JS 入口;不要仅因复制一个组件页就漏掉其中的 Button 等组合依赖。
9
9
 
10
+ ## 已核验行为与示例
11
+
10
12
  [组件文档与 live demo](https://x-next.yjmf.com/components/steps)。子组件的公开名称是 `Step`。使用 `v-model:current`,序号从 **1** 开始,`defaultCurrent=1`、`status='process'`、`type='default'`、`direction='horizontal'`;点击切换需开启 `changeable`,默认关闭。
11
13
 
12
14
  `change(step, event)` 返回步骤号和 `Event`。Step 支持 `title`、`description`、`disabled`、`status`;`node` / `icon` 插槽提供步骤与状态,默认 / `description` 插槽可替换文案。业务完成状态由业务自身维护。
@@ -30,4 +32,200 @@ function changed(step: number, _event: Event) { feedback.value = `已切换到
30
32
  </template>
31
33
  ```
32
34
 
33
- 返回 [AI 索引](../index.md)。精选示例不是完整 API 表,新能力先查同版本公开类型与组件文档。
35
+ ## 场景用法
36
+
37
+ 以下示例从本地 `src/docs/components/steps.md` 显式导入到独立 AI 源,补齐局部注册、状态和样式后进行严格模板检查。上方已核验行为优先;原始 prop 默认值、包装透传和示例业务适配分别查 [完整 API](./steps-api.md) 与场景说明。类型通过不代表所有散文和交互已验证。
38
+
39
+ ### 用途与选型
40
+
41
+ 用于展示流程步骤、进度节点和当前处理状态,适合表单分步、审批流、发布流程和导航式任务。
42
+
43
+
44
+ ### 何时使用
45
+
46
+ - 需要明确展示任务拆分后的阶段和当前进度。
47
+ - 需要让用户按步骤完成流程,或在可点击模式下跳转到某个阶段。
48
+ - 需要在流程中标记完成、等待、处理中或错误状态。
49
+
50
+
51
+ ### 基础用法
52
+
53
+ ```vue
54
+ <script setup lang="ts">
55
+ import 'x-next/style.css';
56
+ import { Steps, Step } from 'x-next';
57
+ import { ref } from 'vue';
58
+
59
+ const current = ref(2);
60
+ </script>
61
+ <template>
62
+ <Steps :current="current">
63
+ <Step title="填写信息" description="录入基础资料" />
64
+ <Step title="确认订单" description="核对费用和地址" />
65
+ <Step title="完成提交" description="等待系统处理" />
66
+ </Steps>
67
+ </template>
68
+ ```
69
+
70
+ ### 状态
71
+
72
+ ```vue
73
+ <script setup lang="ts">
74
+ import 'x-next/style.css';
75
+ import { Steps, Step } from 'x-next';
76
+
77
+ </script>
78
+ <template>
79
+ <Steps :current="2" status="error">
80
+ <Step title="创建任务" description="已完成" />
81
+ <Step title="执行校验" description="校验失败" />
82
+ <Step title="发布结果" description="等待修复后继续" />
83
+ </Steps>
84
+
85
+ <Steps :current="2">
86
+ <Step title="排队" />
87
+ <Step title="处理中" />
88
+ <Step title="结束" status="error" description="可单独覆盖 Step 状态" />
89
+ </Steps>
90
+ </template>
91
+ ```
92
+
93
+ ### 标签位置和垂直方向
94
+
95
+ ```vue
96
+ <script setup lang="ts">
97
+ import 'x-next/style.css';
98
+ import { Steps, Step } from 'x-next';
99
+ import { ref } from 'vue';
100
+
101
+ const current = ref(2);
102
+ </script>
103
+ <template>
104
+ <Steps :current="2" label-placement="vertical">
105
+ <Step title="提交" description="表单资料" />
106
+ <Step title="审核" description="人工确认" />
107
+ <Step title="归档" description="流程结束" />
108
+ </Steps>
109
+
110
+ <Steps :current="current" direction="vertical">
111
+ <Step title="创建项目" description="准备基础配置" />
112
+ <Step title="配置权限" description="选择成员和角色" />
113
+ <Step title="启动项目" description="生成工作空间" />
114
+ </Steps>
115
+ </template>
116
+ ```
117
+
118
+ ### 小尺寸和无线条
119
+
120
+ ```vue
121
+ <script setup lang="ts">
122
+ import 'x-next/style.css';
123
+ import { Steps, Step } from 'x-next';
124
+
125
+ </script>
126
+ <template>
127
+ <Steps :current="2" small>
128
+ <Step title="开始" />
129
+ <Step title="处理中" />
130
+ <Step title="完成" />
131
+ </Steps>
132
+
133
+ <Steps :current="2" line-less>
134
+ <Step title="草稿" description="本地保存" />
135
+ <Step title="提交" description="等待处理" />
136
+ <Step title="发布" description="对外可见" />
137
+ </Steps>
138
+ </template>
139
+ ```
140
+
141
+ ### 类型
142
+
143
+ ```vue
144
+ <script setup lang="ts">
145
+ import 'x-next/style.css';
146
+ import { Steps, Step } from 'x-next';
147
+
148
+ </script>
149
+ <template>
150
+ <Steps type="arrow" :current="2">
151
+ <Step title="选择商品" description="确认清单" />
152
+ <Step title="支付订单" description="处理中" />
153
+ <Step title="发货" description="等待仓库" />
154
+ </Steps>
155
+
156
+ <Steps type="dot" :current="2">
157
+ <Step title="启动" description="初始化" />
158
+ <Step title="运行" description="任务执行中" />
159
+ <Step title="收尾" description="生成报告" />
160
+ </Steps>
161
+
162
+ <Steps type="navigation" :current="2">
163
+ <Step title="账户" description="基础信息" />
164
+ <Step title="权限" description="角色策略" />
165
+ <Step title="确认" description="提交配置" />
166
+ </Steps>
167
+ </template>
168
+ ```
169
+
170
+ ### 可点击切换
171
+
172
+ ```vue
173
+ <script setup lang="ts">
174
+ import 'x-next/style.css';
175
+ import { Steps, Step } from 'x-next';
176
+ import { ref } from 'vue';
177
+
178
+ const current = ref(1);
179
+ const handleChange = (step: number) => {
180
+ current.value = step;
181
+ };
182
+ </script>
183
+ <template>
184
+ <Steps changeable :current="current" @change="handleChange">
185
+ <Step title="资料" />
186
+ <Step title="配置" />
187
+ <Step title="预览" disabled />
188
+ <Step title="完成" />
189
+ </Steps>
190
+ <p>当前步骤:{{ current }}</p>
191
+ </template>
192
+ ```
193
+
194
+ ### 自定义内容
195
+
196
+ ```vue
197
+ <script setup lang="ts">
198
+ import 'x-next/style.css';
199
+ import { Steps, Step } from 'x-next';
200
+
201
+ </script>
202
+ <template>
203
+ <Steps :current="2" label-placement="vertical">
204
+ <Step title="设计">
205
+ <template #icon="{ step }">{{ step }}</template>
206
+
207
+ <template #description>产出交互稿</template>
208
+ </Step>
209
+ <Step>
210
+ <template #node="{ status }">
211
+ <span>{{ status === 'process' ? '中' : '2' }}</span>
212
+ </template>
213
+
214
+ <template #description>实现页面和接口</template>
215
+ </Step>
216
+ <Step title="验收" description="确认上线" />
217
+ </Steps>
218
+ </template>
219
+ ```
220
+
221
+ ### 交互说明
222
+
223
+ - `current` 按 1 开始计数;受控使用时需要在 `change` 或 `update:current` 中同步外部值。
224
+ - `Step.status` 会覆盖 `Steps` 根据 `current` 和 `status` 自动计算出的状态。
225
+ - `type="arrow"` 和 `type="navigation"` 会强制横向展示。
226
+ - `type="dot"` 会根据方向自动调整标签位置,且不使用 `small` 尺寸。
227
+ - 只有设置 `changeable` 后点击步骤才会触发切换;`disabled` 的步骤不会触发切换。
228
+
229
+
230
+
231
+ 返回 [AI 索引](../index.md)。先查本页与 [本地 API](./steps-api.md);需要更深类型时查 [公开组件导航](../catalog.md),不默认上网查找本包用法。
@@ -0,0 +1,58 @@
1
+ <!-- Generated by pnpm generate:ai-usage. Edit script/ai-usage/content.md and script/ai-usage/. -->
2
+ # Switch 完整公开 API
3
+
4
+ 适用版本:x-next@1.14.0;来源指纹:`014984639d816a2c7e25eb22690c586b0b2e8efba6846bec8a4e424db41a09e9`。
5
+
6
+ 从同版本构建的公开声明、运行时 props/emits 和显式 expose 生成。运行时导入始终使用 `x-next`,声明路径仅作定位。插槽类型未细化时,具体槽名与作用域见本地用法示例。
7
+
8
+ ## Switch API
9
+
10
+ 公开声明:`dist/components/form-switch/index.d.ts`。 类型中的 undefined 表示可省略;原始 prop 默认值不等于继承配置或服务默认值。
11
+
12
+ ### Props
13
+
14
+ | 名称 | 用途 | 公开类型 | 必填 | 声明默认值 |
15
+ | --- | --- | --- | --- | --- |
16
+ | modelValue | 绑定值 | undefined &#124; string &#124; number &#124; false &#124; true | 否 | undefined |
17
+ | defaultChecked | 默认选中状态,非受控模式 | undefined &#124; false &#124; true | 否 | false |
18
+ | disabled | 是否禁用 | undefined &#124; false &#124; true | 否 | false |
19
+ | loading | 是否加载中 | undefined &#124; false &#124; true | 否 | false |
20
+ | autofocus | 是否自动获取焦点 | undefined &#124; false &#124; true | 否 | false |
21
+ | type | 开关类型 | undefined &#124; "round" &#124; "circle" &#124; "line" | 否 | "circle" |
22
+ | size | 开关尺寸 | undefined &#124; "mini" &#124; "small" &#124; "medium" &#124; "large" | 否 | 未声明 |
23
+ | checkedValue | 选中时的值 | undefined &#124; string &#124; number &#124; false &#124; true | 否 | true |
24
+ | uncheckedValue | 未选中时的值 | undefined &#124; string &#124; number &#124; false &#124; true | 否 | false |
25
+ | checkedColor | 选中时颜色 | undefined &#124; string | 否 | 未声明 |
26
+ | uncheckedColor | 未选中时颜色 | undefined &#124; string | 否 | 未声明 |
27
+ | beforeChange | 切换前钩子,返回 false 或 Promise reject 时阻止切换 | undefined &#124; (newValue: string &#124; number &#124; boolean) => Promise<boolean &#124; void> &#124; boolean &#124; void | 否 | 未声明 |
28
+ | checkedText | 选中时文案,type="line" 时不显示 | undefined &#124; string | 否 | 未声明 |
29
+ | uncheckedText | 未选中时文案,type="line" 时不显示 | undefined &#124; string | 否 | 未声明 |
30
+
31
+ ### Events
32
+
33
+ | 事件 | 用途 | 监听器签名(即事件参数) |
34
+ | --- | --- | --- |
35
+ | update:modelValue | 值更新时触发 | undefined &#124; (value: string &#124; number &#124; boolean) => any |
36
+ | change | 值变化时触发 | undefined &#124; (value: string &#124; number &#124; boolean, ev: Event) => any |
37
+ | focus | 获取焦点时触发 | undefined &#124; (ev: FocusEvent) => any |
38
+ | blur | 失去焦点时触发 | undefined &#124; (ev: FocusEvent) => any |
39
+ | click | 点击时触发,返回本次尝试切换的目标值 | undefined &#124; (value: string &#124; number &#124; boolean, ev: MouseEvent) => any |
40
+
41
+ ### Slots
42
+
43
+ | 名称 | 用途 | 公开类型 |
44
+ | --- | --- | --- |
45
+ | checked | 选中时文案 | 文档列出的实际插槽;公开类型未细化,作用域见场景用法 |
46
+ | unchecked | 未选中时文案 | 文档列出的实际插槽;公开类型未细化,作用域见场景用法 |
47
+ | checked-icon | 选中时按钮图标 | 文档列出的实际插槽;公开类型未细化,作用域见场景用法 |
48
+ | unchecked-icon | 未选中时按钮图标 | 文档列出的实际插槽;公开类型未细化,作用域见场景用法 |
49
+
50
+ ### 实例方法 / 暴露值
51
+
52
+ | 名称 | 公开类型 |
53
+ | --- | --- |
54
+ | focus | 公开声明未细化(用法和实现已显式暴露) |
55
+ | blur | 公开声明未细化(用法和实现已显式暴露) |
56
+
57
+
58
+ 返回 [Switch 用法](./switch.md)。
@@ -1,12 +1,14 @@
1
1
  <!-- Generated by pnpm generate:ai-usage. Edit script/ai-usage/content.md and script/ai-usage/. -->
2
2
  # Switch AI 使用
3
3
 
4
- 适用版本:x-next@1.13.0;来源指纹:`18e9b8eefa53b4bd91134fb4486778509ccf3a8d614a1bd387a6d469b623ddcf`。
4
+ 适用版本:x-next@1.14.0;来源指纹:`014984639d816a2c7e25eb22690c586b0b2e8efba6846bec8a4e424db41a09e9`。
5
5
 
6
- 先读 [通用接入](../core.md)。公开导出:`Switch`;模型:v-model;已核对事件:change。
6
+ 先读 [通用接入](../core.md)。公开导出:`Switch`;主要模型:v-model。完整 Props、Events、Slots、实例方法与服务签名见 [本地 API](./switch-api.md),包含本组件族全部子组件和别名。
7
7
 
8
8
  按需样式:`x-next/style/form-switch`(包含 base.css、form-switch.css)。代码块未单独引样式时在应用入口加载全量样式,或按实际所有组件加载 JS 入口;不要仅因复制一个组件页就漏掉其中的 Button 等组合依赖。
9
9
 
10
+ ## 已核验行为与示例
11
+
10
12
  [组件文档与 live demo](https://x-next.yjmf.com/components/switch)。普通 `v-model` 支持 `boolean | string | number`;`checkedValue=true`、`uncheckedValue=false`、`defaultChecked=false`,默认 `type='circle'`。`disabled` / `loading` 阻止切换。
11
13
 
12
14
  `change(value, event)` 返回新值和 `Event`;`beforeChange(newValue)` 可返回布尔值或 Promise,`false` 或拒绝阻止切换。`checked` / `unchecked` 插槽及 `checkedText` / `uncheckedText` 显示两态文案;`type='line'` 或有效尺寸为 `'mini'`(含继承尺寸)时均不显示文案。
@@ -29,4 +31,289 @@ function changed(value: boolean | string | number, _event: Event) {
29
31
  </template>
30
32
  ```
31
33
 
32
- 返回 [AI 索引](../index.md)。精选示例不是完整 API 表,新能力先查同版本公开类型与组件文档。
34
+ ## 场景用法
35
+
36
+ 以下示例从本地 `src/docs/components/switch.md` 显式导入到独立 AI 源,补齐局部注册、状态和样式后进行严格模板检查。上方已核验行为优先;原始 prop 默认值、包装透传和示例业务适配分别查 [完整 API](./switch-api.md) 与场景说明。类型通过不代表所有散文和交互已验证。
37
+
38
+ ### 用途与选型
39
+
40
+ 用于表达启用/停用、打开/关闭这类二元状态。
41
+
42
+
43
+ ### 基础用法
44
+
45
+ ```vue
46
+ <script setup lang="ts">
47
+ import 'x-next/style.css';
48
+ import { Switch } from 'x-next';
49
+ import { ref } from 'vue';
50
+
51
+ const enabled = ref(false);
52
+ </script>
53
+ <template>
54
+ <Switch v-model="enabled" />
55
+ </template>
56
+ ```
57
+
58
+ ### 文案和自定义值
59
+
60
+ ```vue
61
+ <script setup lang="ts">
62
+ import 'x-next/style.css';
63
+ import { Switch } from 'x-next';
64
+ const enabled = ref(false);
65
+
66
+ import { ref } from 'vue';
67
+
68
+ const status = ref<'enabled' | 'disabled'>('enabled');
69
+ </script>
70
+ <template>
71
+ <Switch
72
+ v-model="status"
73
+ checked-value="enabled"
74
+ unchecked-value="disabled"
75
+ checked-text="开"
76
+ unchecked-text="关"
77
+ />
78
+ <span>{{ status }}</span>
79
+ </template>
80
+ ```
81
+
82
+ ### 类型
83
+
84
+ ```vue
85
+ <script setup lang="ts">
86
+ import 'x-next/style.css';
87
+ import { Switch } from 'x-next';
88
+ import { ref } from 'vue';
89
+ const enabled = ref(false);
90
+ </script>
91
+ <template>
92
+ <Switch v-model="enabled" type="circle" />
93
+ <Switch v-model="enabled" type="round" />
94
+ <Switch v-model="enabled" type="line" />
95
+ </template>
96
+ ```
97
+
98
+ ### 尺寸
99
+
100
+ 四档尺寸的高度依次为 16 / 16 / 24 / 28px;`mini` 与 `small` 目前共用同一档视觉规格。
101
+
102
+ ```vue
103
+ <script setup lang="ts">
104
+ import 'x-next/style.css';
105
+ import { Switch } from 'x-next';
106
+ import { ref } from 'vue';
107
+ const enabled = ref(false);
108
+ </script>
109
+ <template>
110
+ <Switch v-model="enabled" size="mini" />
111
+ <Switch v-model="enabled" size="small" />
112
+ <Switch v-model="enabled" size="medium" checked-text="开" unchecked-text="关" />
113
+ <Switch v-model="enabled" size="large" checked-text="开" unchecked-text="关" />
114
+ </template>
115
+ ```
116
+
117
+ ### 禁用
118
+
119
+ ```vue
120
+ <script setup lang="ts">
121
+ import 'x-next/style.css';
122
+ import { Switch } from 'x-next';
123
+
124
+ </script>
125
+ <template>
126
+ <Switch disabled />
127
+ <Switch :model-value="true" disabled />
128
+ </template>
129
+ ```
130
+
131
+ ### 加载中
132
+
133
+ ```vue
134
+ <script setup lang="ts">
135
+ import 'x-next/style.css';
136
+ import { Switch } from 'x-next';
137
+
138
+ </script>
139
+ <template>
140
+ <Switch loading />
141
+ <Switch :model-value="true" loading />
142
+ </template>
143
+ ```
144
+
145
+ ### 自定义颜色
146
+
147
+ ```vue
148
+ <script setup lang="ts">
149
+ import 'x-next/style.css';
150
+ import { Switch } from 'x-next';
151
+ import { ref } from 'vue';
152
+ const enabled = ref(false);
153
+ </script>
154
+ <template>
155
+ <Switch
156
+ v-model="enabled"
157
+ checked-color="#0f766e"
158
+ unchecked-color="#94a3b8"
159
+ checked-text="启用"
160
+ unchecked-text="停用"
161
+ />
162
+ <Switch
163
+ v-model="enabled"
164
+ type="line"
165
+ checked-color="#0f766e"
166
+ unchecked-color="#94a3b8"
167
+ />
168
+ </template>
169
+ ```
170
+
171
+ ### 切换前校验
172
+
173
+ ```vue
174
+ <script setup lang="ts">
175
+ import 'x-next/style.css';
176
+ import { Switch } from 'x-next';
177
+ import { ref } from 'vue';
178
+
179
+ const enabled = ref(false);
180
+ const beforeChange = async (nextValue: boolean | string | number) => {
181
+ await new Promise((resolve) => window.setTimeout(resolve, 600));
182
+ return nextValue === true;
183
+ };
184
+ </script>
185
+ <template>
186
+ <Switch v-model="enabled" :before-change="beforeChange" />
187
+ </template>
188
+ ```
189
+
190
+ ### 自定义图标
191
+
192
+ ```vue
193
+ <script setup lang="ts">
194
+ import 'x-next/style.css';
195
+ import { Switch } from 'x-next';
196
+ import { ref } from 'vue';
197
+ const enabled = ref(false);
198
+ </script>
199
+ <template>
200
+ <Switch v-model="enabled">
201
+ <template #checked-icon>✓</template>
202
+ <template #unchecked-icon>×</template>
203
+ </Switch>
204
+ </template>
205
+ ```
206
+
207
+ ### 事件回调
208
+
209
+ ```vue
210
+ <script setup lang="ts">
211
+ import 'x-next/style.css';
212
+ import { Switch } from 'x-next';
213
+ import { ref } from 'vue';
214
+
215
+ const enabled = ref(false);
216
+ const eventLog = ref('等待操作');
217
+ const clickCount = ref(0);
218
+ const handleChange = (value: boolean | string | number) => {
219
+ eventLog.value = `当前值:${value}`;
220
+ };
221
+ const handleClick = (value: boolean | string | number) => {
222
+ clickCount.value += 1;
223
+ eventLog.value = `点击第 ${clickCount.value} 次,目标值:${value}`;
224
+ };
225
+ </script>
226
+ <template>
227
+ <Switch v-model="enabled" @change="handleChange" @click="handleClick" />
228
+ <span>{{ eventLog }}</span>
229
+ </template>
230
+ ```
231
+
232
+ ### 原生属性
233
+
234
+ ```vue
235
+ <script setup lang="ts">
236
+ import 'x-next/style.css';
237
+ import { Switch } from 'x-next';
238
+
239
+ import type { ButtonHTMLAttributes } from 'vue';
240
+ const nativeAttrs1 = { "id": "notification-switch", "name": "notification", "aria-label": "通知开关" } satisfies ButtonHTMLAttributes;
241
+ </script>
242
+ <template>
243
+ <Switch v-bind="nativeAttrs1"
244
+
245
+
246
+ autofocus
247
+
248
+ />
249
+ </template>
250
+ ```
251
+
252
+ ### 方法
253
+
254
+ ```vue
255
+ <script setup lang="ts">
256
+ import 'x-next/style.css';
257
+ import { Switch, Button } from 'x-next';
258
+ import { ref } from 'vue';
259
+
260
+ const enabled = ref(false);
261
+ const switchRef = ref();
262
+ </script>
263
+ <template>
264
+ <Switch ref="switchRef" v-model="enabled" />
265
+ <Button @click="switchRef?.focus()">聚焦</Button>
266
+ <Button @click="switchRef?.blur()">失焦</Button>
267
+ </template>
268
+ ```
269
+
270
+ ### 在 Form 中校验
271
+
272
+ 组件放进 `x-form-item` 后会自动继承 Form 的尺寸与禁用状态,并按 FormItem 的校验规则展示错误。默认 `validateTrigger` 为 `change`,即值变化时触发校验。
273
+
274
+ ```vue
275
+ <script setup lang="ts">
276
+ import 'x-next/style.css';
277
+ import { Form, FormItem, Switch, Space, Button } from 'x-next';
278
+ const enabled = ref(false);
279
+ const status = ref<'enabled' | 'disabled'>('enabled');
280
+
281
+ import { reactive, ref } from 'vue';
282
+ import type { FormInstance, FieldRule } from 'x-next';
283
+
284
+ const formState = reactive({ enabled: false });
285
+ const formRules: Record<string, FieldRule[]> = {
286
+ enabled: [{ type: 'boolean', true: true, message: '需要启用通知' }],
287
+ };
288
+ const formRef = ref<FormInstance>();
289
+ const validateResult = ref('');
290
+
291
+ const handleValidate = async () => {
292
+ const errors = await formRef.value!.validate();
293
+ validateResult.value = errors
294
+ ? `校验失败:${Object.values(errors).map((error) => error.message).join(';')}`
295
+ : '校验通过';
296
+ };
297
+ const handleReset = () => {
298
+ formRef.value!.resetFields();
299
+ validateResult.value = '已重置';
300
+ };
301
+ </script>
302
+ <template>
303
+ <Form ref="formRef" :model="formState" :rules="formRules">
304
+ <FormItem field="enabled" label="启用通知">
305
+ <Switch v-model="formState.enabled" />
306
+ </FormItem>
307
+ <FormItem>
308
+ <Space>
309
+ <Button type="primary" @click="handleValidate">校验</Button>
310
+ <Button @click="handleReset">重置</Button>
311
+ </Space>
312
+ </FormItem>
313
+ </Form>
314
+ <p role="status">{{ validateResult }}</p>
315
+ </template>
316
+ ```
317
+
318
+
319
+ 返回 [AI 索引](../index.md)。先查本页与 [本地 API](./switch-api.md);需要更深类型时查 [公开组件导航](../catalog.md),不默认上网查找本包用法。