x-next 1.12.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.
- package/AI_CODING.md +6 -5
- package/AI_USAGE/catalog.md +106 -105
- package/AI_USAGE/components/alert-api.md +48 -0
- package/AI_USAGE/components/alert.md +222 -3
- package/AI_USAGE/components/bar-chart-api.md +177 -0
- package/AI_USAGE/components/bar-chart.md +297 -3
- package/AI_USAGE/components/boxicons.md +147 -0
- package/AI_USAGE/components/button-api.md +144 -0
- package/AI_USAGE/components/button.md +447 -3
- package/AI_USAGE/components/charts.md +81 -0
- package/AI_USAGE/components/checkbox-api.md +145 -0
- package/AI_USAGE/components/checkbox.md +365 -3
- package/AI_USAGE/components/color-picker-api.md +52 -0
- package/AI_USAGE/components/color-picker.md +211 -3
- package/AI_USAGE/components/config-provider-api.md +38 -0
- package/AI_USAGE/components/config-provider.md +250 -3
- package/AI_USAGE/components/date-picker-api.md +1114 -0
- package/AI_USAGE/components/date-picker.md +378 -3
- package/AI_USAGE/components/dialog-api.md +142 -0
- package/AI_USAGE/components/dialog.md +284 -3
- package/AI_USAGE/components/draggable-api.md +146 -0
- package/AI_USAGE/components/draggable.md +259 -0
- package/AI_USAGE/components/drawer-api.md +78 -0
- package/AI_USAGE/components/drawer.md +227 -0
- package/AI_USAGE/components/dropdown-api.md +529 -0
- package/AI_USAGE/components/dropdown.md +392 -3
- package/AI_USAGE/components/empty-api.md +36 -0
- package/AI_USAGE/components/empty.md +227 -3
- package/AI_USAGE/components/finicon.md +88 -0
- package/AI_USAGE/components/form-api.md +524 -0
- package/AI_USAGE/components/form.md +454 -0
- package/AI_USAGE/components/grid-api.md +527 -0
- package/AI_USAGE/components/grid.md +224 -0
- package/AI_USAGE/components/heatmap-api.md +122 -0
- package/AI_USAGE/components/heatmap.md +220 -0
- package/AI_USAGE/components/icon-api.md +4707 -0
- package/AI_USAGE/components/icon.md +257 -0
- package/AI_USAGE/components/image-api.md +440 -0
- package/AI_USAGE/components/image.md +465 -0
- package/AI_USAGE/components/input-api.md +184 -0
- package/AI_USAGE/components/input-number-api.md +66 -0
- package/AI_USAGE/components/input-number.md +294 -0
- package/AI_USAGE/components/input-tag-api.md +114 -0
- package/AI_USAGE/components/input-tag.md +482 -0
- package/AI_USAGE/components/input.md +293 -3
- package/AI_USAGE/components/layout-api.md +147 -0
- package/AI_USAGE/components/layout.md +230 -0
- package/AI_USAGE/components/line-chart-api.md +197 -0
- package/AI_USAGE/components/line-chart.md +279 -3
- package/AI_USAGE/components/link-api.md +42 -0
- package/AI_USAGE/components/link.md +197 -0
- package/AI_USAGE/components/menu-api.md +516 -0
- package/AI_USAGE/components/menu.md +268 -0
- package/AI_USAGE/components/message-api.md +215 -0
- package/AI_USAGE/components/message-box-api.md +108 -0
- package/AI_USAGE/components/message-box.md +268 -3
- package/AI_USAGE/components/message.md +231 -3
- package/AI_USAGE/components/network-api.md +91 -0
- package/AI_USAGE/components/network.md +378 -0
- package/AI_USAGE/components/notification-api.md +236 -0
- package/AI_USAGE/components/notification.md +275 -3
- package/AI_USAGE/components/pagination-api.md +62 -0
- package/AI_USAGE/components/pagination.md +386 -5
- package/AI_USAGE/components/pie-chart-api.md +109 -0
- package/AI_USAGE/components/pie-chart.md +245 -3
- package/AI_USAGE/components/popconfirm-api.md +75 -0
- package/AI_USAGE/components/popconfirm.md +231 -3
- package/AI_USAGE/components/popover-api.md +75 -0
- package/AI_USAGE/components/popover.md +208 -3
- package/AI_USAGE/components/popup-api.md +75 -0
- package/AI_USAGE/components/popup.md +52 -0
- package/AI_USAGE/components/progress-api.md +44 -0
- package/AI_USAGE/components/progress.md +248 -3
- package/AI_USAGE/components/radio-api.md +165 -0
- package/AI_USAGE/components/radio.md +259 -3
- package/AI_USAGE/components/rate-api.md +54 -0
- package/AI_USAGE/components/rate.md +233 -3
- package/AI_USAGE/components/resize-box-api.md +56 -0
- package/AI_USAGE/components/resize-box.md +231 -0
- package/AI_USAGE/components/scrollbar-api.md +77 -0
- package/AI_USAGE/components/scrollbar.md +218 -0
- package/AI_USAGE/components/select-api.md +758 -0
- package/AI_USAGE/components/select.md +640 -3
- package/AI_USAGE/components/skeleton-api.md +85 -0
- package/AI_USAGE/components/skeleton.md +150 -0
- package/AI_USAGE/components/slider-api.md +51 -0
- package/AI_USAGE/components/slider.md +233 -3
- package/AI_USAGE/components/space-api.md +38 -0
- package/AI_USAGE/components/space.md +145 -0
- package/AI_USAGE/components/spin-api.md +43 -0
- package/AI_USAGE/components/spin.md +205 -0
- package/AI_USAGE/components/steps-api.md +111 -0
- package/AI_USAGE/components/steps.md +201 -3
- package/AI_USAGE/components/switch-api.md +58 -0
- package/AI_USAGE/components/switch.md +290 -3
- package/AI_USAGE/components/table-api.md +2919 -0
- package/AI_USAGE/components/table.md +1414 -0
- package/AI_USAGE/components/tabs-api.md +135 -0
- package/AI_USAGE/components/tabs.md +308 -3
- package/AI_USAGE/components/tag-api.md +124 -0
- package/AI_USAGE/components/tag.md +292 -0
- package/AI_USAGE/components/textarea-api.md +55 -0
- package/AI_USAGE/components/textarea.md +326 -3
- package/AI_USAGE/components/time-picker-api.md +137 -0
- package/AI_USAGE/components/time-picker.md +271 -3
- package/AI_USAGE/components/time-range-selector-api.md +44 -0
- package/AI_USAGE/components/time-range-selector.md +355 -0
- package/AI_USAGE/components/timeline-api.md +93 -0
- package/AI_USAGE/components/timeline.md +312 -0
- package/AI_USAGE/components/tooltip-api.md +77 -0
- package/AI_USAGE/components/tooltip.md +182 -0
- package/AI_USAGE/components/trend-chart-api.md +119 -0
- package/AI_USAGE/components/trend-chart.md +335 -0
- package/AI_USAGE/components/trigger-api.md +124 -0
- package/AI_USAGE/components/trigger.md +185 -0
- package/AI_USAGE/components/upload-api.md +200 -0
- package/AI_USAGE/components/upload.md +711 -3
- package/AI_USAGE/components/watermark-api.md +87 -0
- package/AI_USAGE/components/watermark.md +200 -0
- package/AI_USAGE/core.md +1 -1
- package/AI_USAGE/index.md +35 -7
- package/AI_USAGE/recipes/form-on-demand.md +1 -1
- package/AI_USAGE.md +33657 -7
- package/CHANGELOG.md +40 -0
- package/dist/_utils/inherit-component-type.d.ts +11 -0
- package/dist/components/date-picker/index.d.ts +420 -5
- package/dist/components/form-input/index.d.ts +617 -2
- package/dist/components/layout/index.d.ts +689 -1
- package/dist/components/menu/index.d.ts +786 -1
- package/dist/components/network/Network.vue.d.ts +7 -3
- package/dist/components/network/index.d.ts +10 -2
- package/dist/components/network/props.d.ts +5 -0
- package/dist/components/network/utils.d.ts +3 -3
- package/dist/components/pagination/page-item-ellipsis.vue.d.ts +4 -1
- package/dist/components/pagination/page-item-step.vue.d.ts +101 -130
- package/dist/components/pagination/page-item.vue.d.ts +1 -0
- package/dist/components/pagination/page-jumper.vue.d.ts +1 -1
- package/dist/components/pagination/page-options.vue.d.ts +6 -4
- package/dist/components/pagination/utils.d.ts +3 -0
- package/dist/components/time-range-selector/index.d.ts +6 -6
- package/dist/es/_container/resize-observer-v2.js +1 -1
- package/dist/es/_container/resize-observer.js +1 -1
- package/dist/es/_hooks/use-resize-observer.js +1 -1
- package/dist/es/_styles/palette-aliases.js +4 -4
- package/dist/es/_utils/inherit-component-type.js +6 -0
- package/dist/es/_virtual/advancedFormat.js +1 -1
- package/dist/es/_virtual/customParseFormat.js +1 -1
- package/dist/es/_virtual/dayjs.min.js +1 -1
- package/dist/es/_virtual/isBetween.js +1 -1
- package/dist/es/_virtual/quarterOfYear.js +1 -1
- package/dist/es/_virtual/weekOfYear.js +1 -1
- package/dist/es/_virtual/weekYear.js +1 -1
- package/dist/es/_virtual/zh-cn.js +1 -1
- package/dist/es/components/button/Button.js +53 -42
- package/dist/es/components/date-picker/index.js +18 -17
- package/dist/es/components/draggable/useDraggable.js +1 -1
- package/dist/es/components/form/Form.vue2.js +1 -1
- package/dist/es/components/form/FormItem.vue2.js +1 -1
- package/dist/es/components/form-input/index.js +12 -11
- package/dist/es/components/form-input-number/InputNumber.js +1 -1
- package/dist/es/components/form-slider/Slider.vue2.js +1 -1
- package/dist/es/components/form-slider/slider-ticks.vue2.js +1 -1
- package/dist/es/components/form-slider/utils.js +1 -1
- package/dist/es/components/layout/index.js +10 -9
- package/dist/es/components/menu/MenuItem.js +1 -1
- package/dist/es/components/menu/hooks/use-level.js +5 -5
- package/dist/es/components/menu/index.js +13 -10
- package/dist/es/components/menu/overflow-wrap.js +1 -1
- package/dist/es/components/network/Network.vue.js +17 -12
- package/dist/es/components/network/Network.vue2.js +78 -70
- package/dist/es/components/network/utils.js +112 -71
- package/dist/es/components/pagination/Pagination.js +132 -123
- package/dist/es/components/pagination/page-item-ellipsis.vue.js +10 -10
- package/dist/es/components/pagination/page-item-ellipsis.vue2.js +24 -19
- package/dist/es/components/pagination/page-item-step.vue.js +14 -11
- package/dist/es/components/pagination/page-item-step.vue2.js +20 -22
- package/dist/es/components/pagination/page-item.vue.js +10 -9
- package/dist/es/components/pagination/page-item.vue2.js +24 -19
- package/dist/es/components/pagination/page-jumper.vue2.js +23 -23
- package/dist/es/components/pagination/page-options.vue.js +15 -10
- package/dist/es/components/pagination/page-options.vue2.js +21 -17
- package/dist/es/components/pagination/utils.js +4 -2
- package/dist/es/components/progress/circle.vue2.js +1 -1
- package/dist/es/components/progress/line.vue2.js +1 -1
- package/dist/es/components/progress/steps.vue2.js +1 -1
- package/dist/es/components/rate/Rate.js +1 -1
- package/dist/es/components/virtual-list-v2/virtual-list-item.js +1 -1
- package/dist/es/locale/en-US.js +2 -0
- package/dist/es/locale/zh-CN.js +2 -0
- package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/dayjs.min.js +1 -1
- package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/locale/zh-cn.js +1 -1
- package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/advancedFormat.js +1 -1
- package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/customParseFormat.js +1 -1
- package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/isBetween.js +1 -1
- package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/quarterOfYear.js +1 -1
- package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/weekOfYear.js +1 -1
- package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/dayjs@1.11.21/node_modules/dayjs/plugin/weekYear.js +1 -1
- package/dist/es/style.css +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.umd.js +3 -3
- package/dist/locale/interface.d.ts +3 -0
- package/dist/style/base.css +1 -1
- package/dist/style/button.css +1 -1
- package/dist/style/form-select.css +1 -1
- package/dist/style/network.css +1 -1
- package/dist/style/pagination.css +1 -1
- package/dist/style/table.css +1 -1
- package/dist/style.css +1 -1
- package/package.json +10 -5
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/index.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/is.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/locale/en-US.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/array.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/base.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/boolean.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/custom.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/number.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/object.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/string.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/rules/type.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/b-validate@1.5.3/node_modules/b-validate/es/util.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/compute-scroll-into-view@3.1.1/node_modules/compute-scroll-into-view/dist/index.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/number-precision@1.6.0/node_modules/number-precision/build/index.es.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/scroll-into-view-if-needed@3.1.0/node_modules/scroll-into-view-if-needed/dist/index.js +0 -0
- /package/dist/es/{Users/xuyu/Code/x-next/node_modules → node_modules}/.pnpm/sortablejs@1.15.7/node_modules/sortablejs/modular/sortable.esm.js +0 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
<!-- Generated by pnpm generate:ai-usage. Edit script/ai-usage/content.md and script/ai-usage/. -->
|
|
2
|
+
# Tag AI 使用
|
|
3
|
+
|
|
4
|
+
适用版本:x-next@1.14.0;来源指纹:`014984639d816a2c7e25eb22690c586b0b2e8efba6846bec8a4e424db41a09e9`。
|
|
5
|
+
|
|
6
|
+
先读 [通用接入](../core.md)。公开导出:`Tag`;主要模型:v-model:visible、v-model:checked。完整 Props、Events、Slots、实例方法与服务签名见 [本地 API](./tag-api.md),包含本组件族全部子组件和别名。
|
|
7
|
+
|
|
8
|
+
按需样式:`x-next/style/tag`(包含 base.css、tag.css)。代码块未单独引样式时在应用入口加载全量样式,或按实际所有组件加载 JS 入口;不要仅因复制一个组件页就漏掉其中的 Button 等组合依赖。
|
|
9
|
+
|
|
10
|
+
## 场景用法
|
|
11
|
+
|
|
12
|
+
以下示例从本地 `src/docs/components/tag.md` 显式导入到独立 AI 源,补齐局部注册、状态和样式后进行严格模板检查。上方已核验行为优先;原始 prop 默认值、包装透传和示例业务适配分别查 [完整 API](./tag-api.md) 与场景说明。类型通过不代表所有散文和交互已验证。
|
|
13
|
+
|
|
14
|
+
### 用途与选型
|
|
15
|
+
|
|
16
|
+
用于标记状态、属性、分类或筛选条件,常见于列表、表格、详情页和筛选区域。
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### 何时使用
|
|
20
|
+
|
|
21
|
+
- 标记对象的状态、分类、来源或属性。
|
|
22
|
+
- 展示可关闭的筛选条件。
|
|
23
|
+
- 用作轻量级的可选项,但不承载复杂表单交互。
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### 基础用法
|
|
27
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<script setup lang="ts">
|
|
30
|
+
import 'x-next/style.css';
|
|
31
|
+
import { Tag } from 'x-next';
|
|
32
|
+
|
|
33
|
+
</script>
|
|
34
|
+
<template>
|
|
35
|
+
<Tag>默认标签</Tag>
|
|
36
|
+
<Tag color="blue">蓝色标签</Tag>
|
|
37
|
+
<Tag color="green">绿色标签</Tag>
|
|
38
|
+
<Tag color="#0f766e">自定义颜色</Tag>
|
|
39
|
+
</template>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 内置颜色
|
|
43
|
+
|
|
44
|
+
```vue
|
|
45
|
+
<script setup lang="ts">
|
|
46
|
+
import 'x-next/style.css';
|
|
47
|
+
import { Tag } from 'x-next';
|
|
48
|
+
const colors = [
|
|
49
|
+
'red',
|
|
50
|
+
'orangered',
|
|
51
|
+
'orange',
|
|
52
|
+
'gold',
|
|
53
|
+
'lime',
|
|
54
|
+
'green',
|
|
55
|
+
'cyan',
|
|
56
|
+
'blue',
|
|
57
|
+
'better-blue',
|
|
58
|
+
'purple',
|
|
59
|
+
'pink-purple',
|
|
60
|
+
'magenta',
|
|
61
|
+
'gray',
|
|
62
|
+
];
|
|
63
|
+
</script>
|
|
64
|
+
<template>
|
|
65
|
+
<Tag v-for="color in colors" :key="color" :color="color">
|
|
66
|
+
{{ color }}
|
|
67
|
+
</Tag>
|
|
68
|
+
</template>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 尺寸
|
|
72
|
+
|
|
73
|
+
```vue
|
|
74
|
+
<script setup lang="ts">
|
|
75
|
+
import 'x-next/style.css';
|
|
76
|
+
import { Tag } from 'x-next';
|
|
77
|
+
|
|
78
|
+
</script>
|
|
79
|
+
<template>
|
|
80
|
+
<Tag size="small">小型标签</Tag>
|
|
81
|
+
<Tag>中型标签</Tag>
|
|
82
|
+
<Tag size="large">大型标签</Tag>
|
|
83
|
+
</template>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 带边框
|
|
87
|
+
|
|
88
|
+
```vue
|
|
89
|
+
<script setup lang="ts">
|
|
90
|
+
import 'x-next/style.css';
|
|
91
|
+
import { Tag } from 'x-next';
|
|
92
|
+
|
|
93
|
+
</script>
|
|
94
|
+
<template>
|
|
95
|
+
<Tag bordered>默认边框</Tag>
|
|
96
|
+
<Tag color="blue" bordered>蓝色边框</Tag>
|
|
97
|
+
<Tag color="green" bordered>绿色边框</Tag>
|
|
98
|
+
<Tag color="magenta" bordered>品红边框</Tag>
|
|
99
|
+
</template>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 可关闭
|
|
103
|
+
|
|
104
|
+
```vue
|
|
105
|
+
<script setup lang="ts">
|
|
106
|
+
import 'x-next/style.css';
|
|
107
|
+
import { Tag, Button } from 'x-next';
|
|
108
|
+
import { ref } from 'vue';
|
|
109
|
+
|
|
110
|
+
const visible = ref(true);
|
|
111
|
+
const closeCount = ref(0);
|
|
112
|
+
const handleClose = () => { closeCount.value += 1; };
|
|
113
|
+
</script>
|
|
114
|
+
<template>
|
|
115
|
+
<Tag closable>可关闭</Tag>
|
|
116
|
+
<Tag color="orange" closable @close="handleClose">关闭事件</Tag>
|
|
117
|
+
<Tag v-model:visible="visible" color="purple" closable>受控显示</Tag>
|
|
118
|
+
<Button size="mini" @click="visible = true">重置</Button>
|
|
119
|
+
<span aria-live="polite">关闭事件:{{ closeCount }}</span>
|
|
120
|
+
</template>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 可选择
|
|
124
|
+
|
|
125
|
+
```vue
|
|
126
|
+
<script setup lang="ts">
|
|
127
|
+
import 'x-next/style.css';
|
|
128
|
+
import { Tag } from 'x-next';
|
|
129
|
+
import { ref } from 'vue';
|
|
130
|
+
|
|
131
|
+
const checked = ref(true);
|
|
132
|
+
</script>
|
|
133
|
+
<template>
|
|
134
|
+
<Tag selectable>默认可选</Tag>
|
|
135
|
+
<Tag color="red" selectable :default-checked="false">未选中</Tag>
|
|
136
|
+
<Tag v-model:checked="checked" color="better-blue" selectable>受控选择</Tag>
|
|
137
|
+
<span>当前:{{ checked ? '已选' : '未选' }}</span>
|
|
138
|
+
</template>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 加载中
|
|
142
|
+
|
|
143
|
+
`loading` 展示加载图标,保持文字不透明;它不会阻止选择或关闭。
|
|
144
|
+
|
|
145
|
+
```vue
|
|
146
|
+
<script setup lang="ts">
|
|
147
|
+
import 'x-next/style.css';
|
|
148
|
+
import { Tag } from 'x-next';
|
|
149
|
+
|
|
150
|
+
</script>
|
|
151
|
+
<template>
|
|
152
|
+
<Tag loading>同步中</Tag>
|
|
153
|
+
<Tag color="blue" loading>发布中</Tag>
|
|
154
|
+
<Tag color="#0f766e" loading>自定义颜色</Tag>
|
|
155
|
+
</template>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 图标与自定义关闭图标
|
|
159
|
+
|
|
160
|
+
```vue
|
|
161
|
+
<script setup lang="ts">
|
|
162
|
+
import 'x-next/style.css';
|
|
163
|
+
import { Tag } from 'x-next';
|
|
164
|
+
|
|
165
|
+
</script>
|
|
166
|
+
<template>
|
|
167
|
+
<Tag color="green">
|
|
168
|
+
<template #icon>
|
|
169
|
+
<span aria-hidden="true">✓</span>
|
|
170
|
+
</template>
|
|
171
|
+
已完成
|
|
172
|
+
</Tag>
|
|
173
|
+
<Tag color="orange" closable>
|
|
174
|
+
<template #close-icon>
|
|
175
|
+
<span aria-hidden="true">x</span>
|
|
176
|
+
</template>
|
|
177
|
+
自定义关闭
|
|
178
|
+
</Tag>
|
|
179
|
+
</template>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 动态编辑
|
|
183
|
+
|
|
184
|
+
```vue
|
|
185
|
+
<script setup lang="ts">
|
|
186
|
+
import 'x-next/style.css';
|
|
187
|
+
import { Tag, Input } from 'x-next';
|
|
188
|
+
import { ref } from 'vue';
|
|
189
|
+
|
|
190
|
+
const dynamicTags = ref(['Vue', 'TypeScript', 'VitePress']);
|
|
191
|
+
const editing = ref(false);
|
|
192
|
+
const newTag = ref('');
|
|
193
|
+
|
|
194
|
+
const removeTag = (tag: string) => {
|
|
195
|
+
dynamicTags.value = dynamicTags.value.filter((item) => item !== tag);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const addTag = () => {
|
|
199
|
+
const value = newTag.value.trim();
|
|
200
|
+
if (value && !dynamicTags.value.includes(value)) {
|
|
201
|
+
dynamicTags.value.push(value);
|
|
202
|
+
}
|
|
203
|
+
newTag.value = '';
|
|
204
|
+
editing.value = false;
|
|
205
|
+
};
|
|
206
|
+
const nativeEvents = { click: () => { editing.value = true; } };
|
|
207
|
+
</script>
|
|
208
|
+
<template>
|
|
209
|
+
<Tag v-for="tag in dynamicTags" :key="tag" closable @close="removeTag(tag)">
|
|
210
|
+
{{ tag }}
|
|
211
|
+
</Tag>
|
|
212
|
+
<Input
|
|
213
|
+
v-if="editing"
|
|
214
|
+
v-model="newTag"
|
|
215
|
+
size="mini"
|
|
216
|
+
placeholder="新增标签"
|
|
217
|
+
style="width: 96px"
|
|
218
|
+
@press-enter="addTag"
|
|
219
|
+
@blur="addTag"
|
|
220
|
+
/>
|
|
221
|
+
<Tag v-else bordered v-on="nativeEvents">+ 新增</Tag>
|
|
222
|
+
</template>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 不换行
|
|
226
|
+
|
|
227
|
+
```vue
|
|
228
|
+
<script setup lang="ts">
|
|
229
|
+
import 'x-next/style.css';
|
|
230
|
+
import { Tag } from 'x-next';
|
|
231
|
+
|
|
232
|
+
</script>
|
|
233
|
+
<template>
|
|
234
|
+
<Tag nowrap style="max-width: 180px">
|
|
235
|
+
这是一段很长但不会换行的标签内容
|
|
236
|
+
</Tag>
|
|
237
|
+
</template>
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 亮暗颜色与选择反馈
|
|
241
|
+
|
|
242
|
+
内置色的文字色与背景分开定义。取消选择后恢复默认文字和透明背景,再次选中恢复对应颜色;悬浮仍有默认弱底反馈。下例可切换局部暗色,并通过页面计数确认 `check` 回调。
|
|
243
|
+
|
|
244
|
+
这里用 `visible=true` 展示受控关闭:按钮会触发 `close`,父层未更新 visible 时标签仍保留,关闭不会触发选择。自定义色默认用白字,亮色背景需显式覆盖 `--x-tag-custom-color-text`,组件不自动推导任意 CSS 背景的前景色。页面为暗色时,请先切回亮色观察局部对照;`dark=false` 不会重置暗色祖先。
|
|
245
|
+
|
|
246
|
+
`selectable` 当前支持鼠标切换,尚未提供键盘选择和独立 disabled 属性;关闭按钮可通过 Tab 聚焦后用 Enter 或 Space 激活。
|
|
247
|
+
|
|
248
|
+
```vue
|
|
249
|
+
<script setup lang="ts">
|
|
250
|
+
const visible = ref(true);
|
|
251
|
+
|
|
252
|
+
import { ref } from 'vue';
|
|
253
|
+
import { ConfigProvider as XConfigProvider, Switch as XSwitch, Tag as XTag } from 'x-next';
|
|
254
|
+
import 'x-next/style.css';
|
|
255
|
+
|
|
256
|
+
const dark = ref(false);
|
|
257
|
+
const checks = ref(0);
|
|
258
|
+
const closes = ref(0);
|
|
259
|
+
const colors = ['red', 'orangered', 'orange', 'gold', 'lime', 'green', 'cyan', 'blue', 'better-blue', 'purple', 'pink-purple', 'magenta', 'gray'];
|
|
260
|
+
</script>
|
|
261
|
+
<template>
|
|
262
|
+
<label><XSwitch v-model="dark" />切换标签暗色</label>
|
|
263
|
+
<XConfigProvider :dark="dark" class="color-scope">
|
|
264
|
+
<div class="color-row">
|
|
265
|
+
<XTag v-for="color in colors" :key="color" :color="color" selectable bordered closable :visible="true" @check="checks++" @close="closes++">{{ color }}</XTag>
|
|
266
|
+
<XTag color="gold" loading>加载颜色</XTag>
|
|
267
|
+
<XTag color="#ffb800" selectable style="--x-tag-custom-color-text: var(--x-color-constant-dark)">自定义亮色</XTag>
|
|
268
|
+
</div>
|
|
269
|
+
<p aria-live="polite">选择事件:{{ checks }};关闭事件:{{ closes }}</p>
|
|
270
|
+
</XConfigProvider>
|
|
271
|
+
</template>
|
|
272
|
+
<style scoped>
|
|
273
|
+
.color-row {
|
|
274
|
+
display: flex;
|
|
275
|
+
flex-wrap: wrap;
|
|
276
|
+
gap: 12px;
|
|
277
|
+
}
|
|
278
|
+
.color-scope {
|
|
279
|
+
padding: 16px;
|
|
280
|
+
color: var(--x-color-text-primary);
|
|
281
|
+
background: var(--x-color-bg-surface);
|
|
282
|
+
}
|
|
283
|
+
</style>
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### TagColor
|
|
287
|
+
|
|
288
|
+
`red`、`orangered`、`orange`、`gold`、`lime`、`green`、`cyan`、`blue`、`better-blue`、`purple`、`pink-purple`、`magenta`、`gray`
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
返回 [AI 索引](../index.md)。先查本页与 [本地 API](./tag-api.md);需要更深类型时查 [公开组件导航](../catalog.md),不默认上网查找本包用法。
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<!-- Generated by pnpm generate:ai-usage. Edit script/ai-usage/content.md and script/ai-usage/. -->
|
|
2
|
+
# Textarea 完整公开 API
|
|
3
|
+
|
|
4
|
+
适用版本:x-next@1.14.0;来源指纹:`014984639d816a2c7e25eb22690c586b0b2e8efba6846bec8a4e424db41a09e9`。
|
|
5
|
+
|
|
6
|
+
从同版本构建的公开声明、运行时 props/emits 和显式 expose 生成。运行时导入始终使用 `x-next`,声明路径仅作定位。插槽类型未细化时,具体槽名与作用域见本地用法示例。
|
|
7
|
+
|
|
8
|
+
## Textarea API
|
|
9
|
+
|
|
10
|
+
公开声明:`dist/components/form-textarea/index.d.ts`。 类型中的 undefined 表示可省略;原始 prop 默认值不等于继承配置或服务默认值。
|
|
11
|
+
|
|
12
|
+
### Props
|
|
13
|
+
|
|
14
|
+
| 名称 | 用途 | 公开类型 | 必填 | 声明默认值 |
|
|
15
|
+
| --- | --- | --- | --- | --- |
|
|
16
|
+
| modelValue | 绑定值 | undefined | string | 否 | 未声明 |
|
|
17
|
+
| defaultValue | 默认值,非受控模式 | undefined | string | 否 | "" |
|
|
18
|
+
| placeholder | 占位提示 | undefined | string | 否 | 未声明 |
|
|
19
|
+
| disabled | 是否禁用 | undefined | false | true | 否 | false |
|
|
20
|
+
| error | 是否为错误状态 | undefined | false | true | 否 | false |
|
|
21
|
+
| size | 组件尺寸 | undefined | "mini" | "small" | "medium" | "large" | 否 | 未声明 |
|
|
22
|
+
| maxLength | 最大长度;传入 errorOnly 时仅展示错误状态,不截断输入 | undefined | number | { length: number; errorOnly?: boolean; } | 否 | 0 |
|
|
23
|
+
| showWordLimit | 是否显示字数统计 | undefined | false | true | 否 | false |
|
|
24
|
+
| allowClear | 是否允许清空 | undefined | false | true | 否 | false |
|
|
25
|
+
| autoSize | 是否自适应高度,可配置最小和最大行数 | undefined | false | true | { minRows?: number; maxRows?: number; } | 否 | false |
|
|
26
|
+
| wordLength | 自定义字符长度计算方法 | undefined | (value: string) => number | 否 | 未声明 |
|
|
27
|
+
| wordSlice | 自定义超长截取方法,通常与 wordLength 一起使用 | undefined | (value: string, maxLength: number) => string | 否 | 未声明 |
|
|
28
|
+
| textareaAttrs | 透传给内部 textarea 的原生属性 | undefined | { [x: string]: any; } | 否 | 未声明 |
|
|
29
|
+
|
|
30
|
+
### Events
|
|
31
|
+
|
|
32
|
+
| 事件 | 用途 | 监听器签名(即事件参数) |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| update:modelValue | 值更新时触发 | undefined | (value: string) => any |
|
|
35
|
+
| input | 用户输入时触发 | undefined | (value: string, ev: Event) => any |
|
|
36
|
+
| change | 文本域失焦且值变化时触发 | undefined | (value: string, ev: Event) => any |
|
|
37
|
+
| clear | 点击清除按钮时触发 | undefined | (ev: MouseEvent) => any |
|
|
38
|
+
| focus | 获取焦点时触发 | undefined | (ev: FocusEvent) => any |
|
|
39
|
+
| blur | 失去焦点时触发 | undefined | (ev: FocusEvent) => any |
|
|
40
|
+
|
|
41
|
+
### Slots
|
|
42
|
+
|
|
43
|
+
| 名称 | 用途 | 公开类型 |
|
|
44
|
+
| --- | --- | --- |
|
|
45
|
+
| suffix | 后缀内容 | 文档列出的实际插槽;公开类型未细化,作用域见场景用法 |
|
|
46
|
+
|
|
47
|
+
### 实例方法 / 暴露值
|
|
48
|
+
|
|
49
|
+
| 名称 | 公开类型 |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| focus | () => void |
|
|
52
|
+
| blur | () => void |
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
返回 [Textarea 用法](./textarea.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
|
# Textarea AI 使用
|
|
3
3
|
|
|
4
|
-
适用版本:x-next@1.
|
|
4
|
+
适用版本:x-next@1.14.0;来源指纹:`014984639d816a2c7e25eb22690c586b0b2e8efba6846bec8a4e424db41a09e9`。
|
|
5
5
|
|
|
6
|
-
先读 [通用接入](../core.md)。公开导出:`Textarea
|
|
6
|
+
先读 [通用接入](../core.md)。公开导出:`Textarea`;主要模型:v-model。完整 Props、Events、Slots、实例方法与服务签名见 [本地 API](./textarea-api.md),包含本组件族全部子组件和别名。
|
|
7
7
|
|
|
8
8
|
按需样式:`x-next/style/form-textarea`(包含 base.css、form-textarea.css)。代码块未单独引样式时在应用入口加载全量样式,或按实际所有组件加载 JS 入口;不要仅因复制一个组件页就漏掉其中的 Button 等组合依赖。
|
|
9
9
|
|
|
10
|
+
## 已核验行为与示例
|
|
11
|
+
|
|
10
12
|
[组件文档与 live demo](https://x-next.yjmf.com/components/textarea)。`v-model` 为字符串,`input/change/clear` 与输入生命周期联动。原生 id、name、aria、rows、readonly 用 `textareaAttrs`,不支持组件层的 readonly prop;autoSize 控制自动高度。
|
|
11
13
|
|
|
12
14
|
```vue
|
|
@@ -28,4 +30,325 @@ const readonlyAttrs = { id: 'saved-summary', name: 'savedSummary', 'aria-label':
|
|
|
28
30
|
</template>
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
## 场景用法
|
|
34
|
+
|
|
35
|
+
以下示例从本地 `src/docs/components/textarea.md` 显式导入到独立 AI 源,补齐局部注册、状态和样式后进行严格模板检查。上方已核验行为优先;原始 prop 默认值、包装透传和示例业务适配分别查 [完整 API](./textarea-api.md) 与场景说明。类型通过不代表所有散文和交互已验证。
|
|
36
|
+
|
|
37
|
+
### 用途与选型
|
|
38
|
+
|
|
39
|
+
用于多行文本输入,适合备注、描述、评论等较长内容。
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### 何时使用
|
|
43
|
+
|
|
44
|
+
- 需要输入多行内容,例如备注、描述、审批意见、评论。
|
|
45
|
+
- 需要限制或提示字数,并在输入时展示统计。
|
|
46
|
+
- 需要根据内容自动调整高度。
|
|
47
|
+
- 需要在表单中展示禁用、只读、错误等状态。
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### 基础用法
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<script setup lang="ts">
|
|
54
|
+
import 'x-next/style.css';
|
|
55
|
+
import { Textarea } from 'x-next';
|
|
56
|
+
import { ref } from 'vue';
|
|
57
|
+
|
|
58
|
+
const value = ref('用于搭建业务系统的 Vue 3 组件库');
|
|
59
|
+
</script>
|
|
60
|
+
<template>
|
|
61
|
+
<Textarea v-model="value" placeholder="请输入描述" />
|
|
62
|
+
</template>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 可清除
|
|
66
|
+
|
|
67
|
+
```vue
|
|
68
|
+
<script setup lang="ts">
|
|
69
|
+
import 'x-next/style.css';
|
|
70
|
+
import { Textarea } from 'x-next';
|
|
71
|
+
import { ref } from 'vue';
|
|
72
|
+
|
|
73
|
+
const value = ref('这段内容可以一键清空');
|
|
74
|
+
</script>
|
|
75
|
+
<template>
|
|
76
|
+
<Textarea v-model="value" allow-clear placeholder="请输入内容" />
|
|
77
|
+
</template>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 字数统计
|
|
81
|
+
|
|
82
|
+
```vue
|
|
83
|
+
<script setup lang="ts">
|
|
84
|
+
import 'x-next/style.css';
|
|
85
|
+
import { Textarea } from 'x-next';
|
|
86
|
+
import { ref } from 'vue';
|
|
87
|
+
|
|
88
|
+
const value = ref('Textarea 支持字数统计和清除操作');
|
|
89
|
+
</script>
|
|
90
|
+
<template>
|
|
91
|
+
<Textarea
|
|
92
|
+
v-model="value"
|
|
93
|
+
:max-length="80"
|
|
94
|
+
show-word-limit
|
|
95
|
+
allow-clear
|
|
96
|
+
placeholder="请输入不超过 80 个字符"
|
|
97
|
+
/>
|
|
98
|
+
</template>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 仅提示错误
|
|
102
|
+
|
|
103
|
+
```vue
|
|
104
|
+
<script setup lang="ts">
|
|
105
|
+
import 'x-next/style.css';
|
|
106
|
+
import { Textarea } from 'x-next';
|
|
107
|
+
import { ref } from 'vue';
|
|
108
|
+
|
|
109
|
+
const value = ref('这段内容允许超出限制,但会进入错误状态');
|
|
110
|
+
</script>
|
|
111
|
+
<template>
|
|
112
|
+
<Textarea
|
|
113
|
+
v-model="value"
|
|
114
|
+
:max-length="{ length: 20, errorOnly: true }"
|
|
115
|
+
show-word-limit
|
|
116
|
+
allow-clear
|
|
117
|
+
/>
|
|
118
|
+
</template>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 自适应高度
|
|
122
|
+
|
|
123
|
+
```vue
|
|
124
|
+
<script setup lang="ts">
|
|
125
|
+
import 'x-next/style.css';
|
|
126
|
+
import { Textarea } from 'x-next';
|
|
127
|
+
import { ref } from 'vue';
|
|
128
|
+
|
|
129
|
+
const value = ref('自适应高度会随内容增长,并在达到 maxRows 后出现滚动条。');
|
|
130
|
+
</script>
|
|
131
|
+
<template>
|
|
132
|
+
<Textarea
|
|
133
|
+
v-model="value"
|
|
134
|
+
:auto-size="{ minRows: 2, maxRows: 5 }"
|
|
135
|
+
:max-length="160"
|
|
136
|
+
show-word-limit
|
|
137
|
+
allow-clear
|
|
138
|
+
/>
|
|
139
|
+
</template>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 动态切换自适应高度
|
|
143
|
+
|
|
144
|
+
开启后立即按内容计算高度;关闭后恢复手动纵向拉伸。修改 `minRows`、`maxRows` 或 `size` 时会重新计算。
|
|
145
|
+
|
|
146
|
+
```vue
|
|
147
|
+
<script setup lang="ts">
|
|
148
|
+
import 'x-next/style.css';
|
|
149
|
+
import { Checkbox, Textarea } from 'x-next';
|
|
150
|
+
import { ref } from 'vue';
|
|
151
|
+
const enabled = ref(false);
|
|
152
|
+
const value = ref('第一行\n第二行\n第三行\n第四行');
|
|
153
|
+
</script>
|
|
154
|
+
<template>
|
|
155
|
+
<Checkbox v-model="enabled">启用自动高度(2 至 4 行)</Checkbox>
|
|
156
|
+
<Textarea v-model="value" :auto-size="enabled ? { minRows: 2, maxRows: 4 } : false" allow-clear />
|
|
157
|
+
</template>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 尺寸
|
|
161
|
+
|
|
162
|
+
各尺寸档会同时调整最小高度、字号与内边距;`size` 变化后自适应高度会重新计算。
|
|
163
|
+
|
|
164
|
+
```vue
|
|
165
|
+
<script setup lang="ts">
|
|
166
|
+
import 'x-next/style.css';
|
|
167
|
+
import { Textarea } from 'x-next';
|
|
168
|
+
import { ref } from 'vue';
|
|
169
|
+
|
|
170
|
+
const value = ref('四种尺寸的文本域');
|
|
171
|
+
</script>
|
|
172
|
+
<template>
|
|
173
|
+
<Textarea v-model="value" size="mini" />
|
|
174
|
+
<Textarea v-model="value" size="small" />
|
|
175
|
+
<Textarea v-model="value" size="medium" />
|
|
176
|
+
<Textarea v-model="value" size="large" />
|
|
177
|
+
</template>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 禁用与状态
|
|
181
|
+
|
|
182
|
+
```vue
|
|
183
|
+
<script setup lang="ts">
|
|
184
|
+
import 'x-next/style.css';
|
|
185
|
+
import { Textarea } from 'x-next';
|
|
186
|
+
import { ref } from 'vue';
|
|
187
|
+
|
|
188
|
+
const disabledValue = ref('禁用状态不可编辑');
|
|
189
|
+
const readonlyValue = ref('只读状态通过 textareaAttrs 透传给原生 textarea');
|
|
190
|
+
const errorValue = ref('错误状态用于校验失败提示');
|
|
191
|
+
</script>
|
|
192
|
+
<template>
|
|
193
|
+
<Textarea v-model="disabledValue" disabled />
|
|
194
|
+
<Textarea v-model="readonlyValue" :textarea-attrs="{ readonly: true }" />
|
|
195
|
+
<Textarea v-model="errorValue" error show-word-limit :max-length="20" />
|
|
196
|
+
</template>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 后缀内容
|
|
200
|
+
|
|
201
|
+
```vue
|
|
202
|
+
<script setup lang="ts">
|
|
203
|
+
import 'x-next/style.css';
|
|
204
|
+
import { Textarea } from 'x-next';
|
|
205
|
+
import { ref } from 'vue';
|
|
206
|
+
|
|
207
|
+
const value = ref('审批备注需要更明确的填写状态');
|
|
208
|
+
</script>
|
|
209
|
+
<template>
|
|
210
|
+
<Textarea v-model="value" :max-length="80" show-word-limit>
|
|
211
|
+
<template #suffix>
|
|
212
|
+
<span>备注</span>
|
|
213
|
+
</template>
|
|
214
|
+
</Textarea>
|
|
215
|
+
</template>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 原生属性
|
|
219
|
+
|
|
220
|
+
```vue
|
|
221
|
+
<script setup lang="ts">
|
|
222
|
+
import 'x-next/style.css';
|
|
223
|
+
import { Textarea } from 'x-next';
|
|
224
|
+
import { ref } from 'vue';
|
|
225
|
+
|
|
226
|
+
const value = ref('内部 textarea 可以接收 rows、name、required 等原生属性');
|
|
227
|
+
</script>
|
|
228
|
+
<template>
|
|
229
|
+
<Textarea
|
|
230
|
+
v-model="value"
|
|
231
|
+
:textarea-attrs="{ rows: 4, name: 'description', required: true, autocomplete: 'off' }"
|
|
232
|
+
/>
|
|
233
|
+
</template>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### 自定义长度计算
|
|
237
|
+
|
|
238
|
+
```vue
|
|
239
|
+
<script setup lang="ts">
|
|
240
|
+
import 'x-next/style.css';
|
|
241
|
+
import { Textarea } from 'x-next';
|
|
242
|
+
import { ref } from 'vue';
|
|
243
|
+
|
|
244
|
+
const value = ref('中文算 2,English 算 1');
|
|
245
|
+
|
|
246
|
+
const getMixedLength = (value: string) =>
|
|
247
|
+
Array.from(value).reduce((total, char) => total + (char.charCodeAt(0) > 255 ? 2 : 1), 0);
|
|
248
|
+
|
|
249
|
+
const sliceMixedLength = (value: string, maxLength: number) => {
|
|
250
|
+
let total = 0;
|
|
251
|
+
let result = '';
|
|
252
|
+
|
|
253
|
+
for (const char of Array.from(value)) {
|
|
254
|
+
const next = total + (char.charCodeAt(0) > 255 ? 2 : 1);
|
|
255
|
+
if (next > maxLength) break;
|
|
256
|
+
total = next;
|
|
257
|
+
result += char;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return result;
|
|
261
|
+
};
|
|
262
|
+
</script>
|
|
263
|
+
<template>
|
|
264
|
+
<Textarea
|
|
265
|
+
v-model="value"
|
|
266
|
+
:max-length="20"
|
|
267
|
+
show-word-limit
|
|
268
|
+
:word-length="getMixedLength"
|
|
269
|
+
:word-slice="sliceMixedLength"
|
|
270
|
+
allow-clear
|
|
271
|
+
/>
|
|
272
|
+
</template>
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### 事件
|
|
276
|
+
|
|
277
|
+
```vue
|
|
278
|
+
<script setup lang="ts">
|
|
279
|
+
import 'x-next/style.css';
|
|
280
|
+
import { Textarea } from 'x-next';
|
|
281
|
+
import { ref } from 'vue';
|
|
282
|
+
|
|
283
|
+
const value = ref('修改内容后失焦会触发 change');
|
|
284
|
+
const logs = ref<string[]>([]);
|
|
285
|
+
|
|
286
|
+
const pushLog = (message: string) => {
|
|
287
|
+
logs.value = [message, ...logs.value].slice(0, 5);
|
|
288
|
+
};
|
|
289
|
+
</script>
|
|
290
|
+
<template>
|
|
291
|
+
<Textarea
|
|
292
|
+
v-model="value"
|
|
293
|
+
allow-clear
|
|
294
|
+
:max-length="80"
|
|
295
|
+
show-word-limit
|
|
296
|
+
@input="(value) => pushLog(`input: ${value.length}`)"
|
|
297
|
+
@change="(value) => pushLog(`change: ${value.length}`)"
|
|
298
|
+
@clear="() => pushLog('clear')"
|
|
299
|
+
@focus="() => pushLog('focus')"
|
|
300
|
+
@blur="() => pushLog('blur')"
|
|
301
|
+
/>
|
|
302
|
+
<div>
|
|
303
|
+
<div v-for="(log, index) in logs" :key="`${index}-${log}`">{{ log }}</div>
|
|
304
|
+
</div>
|
|
305
|
+
</template>
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### 在 Form 中校验
|
|
309
|
+
|
|
310
|
+
组件放进 `x-form-item` 后会自动继承 Form 的尺寸与禁用状态,并按 FormItem 的校验规则展示错误。默认 `validateTrigger` 为 `change`,即值变化时触发校验。
|
|
311
|
+
|
|
312
|
+
```vue
|
|
313
|
+
<script setup lang="ts">
|
|
314
|
+
import 'x-next/style.css';
|
|
315
|
+
import { Form, FormItem, Textarea, Space, Button } from 'x-next';
|
|
316
|
+
import { reactive, ref } from 'vue';
|
|
317
|
+
import type { FormInstance, FieldRule } from 'x-next';
|
|
318
|
+
|
|
319
|
+
const formState = reactive({ description: "" });
|
|
320
|
+
const formRules: Record<string, FieldRule[]> = {
|
|
321
|
+
description: [{ required: true, message: '请输入描述' }],
|
|
322
|
+
};
|
|
323
|
+
const formRef = ref<FormInstance>();
|
|
324
|
+
const validateResult = ref('');
|
|
325
|
+
|
|
326
|
+
const handleValidate = async () => {
|
|
327
|
+
const errors = await formRef.value!.validate();
|
|
328
|
+
validateResult.value = errors
|
|
329
|
+
? `校验失败:${Object.values(errors).map((error) => error.message).join(';')}`
|
|
330
|
+
: '校验通过';
|
|
331
|
+
};
|
|
332
|
+
const handleReset = () => {
|
|
333
|
+
formRef.value!.resetFields();
|
|
334
|
+
validateResult.value = '已重置';
|
|
335
|
+
};
|
|
336
|
+
</script>
|
|
337
|
+
<template>
|
|
338
|
+
<Form ref="formRef" :model="formState" :rules="formRules">
|
|
339
|
+
<FormItem field="description" label="描述">
|
|
340
|
+
<Textarea v-model="formState.description" placeholder="请输入描述" allow-clear />
|
|
341
|
+
</FormItem>
|
|
342
|
+
<FormItem>
|
|
343
|
+
<Space>
|
|
344
|
+
<Button type="primary" @click="handleValidate">校验</Button>
|
|
345
|
+
<Button @click="handleReset">重置</Button>
|
|
346
|
+
</Space>
|
|
347
|
+
</FormItem>
|
|
348
|
+
</Form>
|
|
349
|
+
<p role="status">{{ validateResult }}</p>
|
|
350
|
+
</template>
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
返回 [AI 索引](../index.md)。先查本页与 [本地 API](./textarea-api.md);需要更深类型时查 [公开组件导航](../catalog.md),不默认上网查找本包用法。
|