--- url: 'https://wot-ui.cn/guide/open-wot.md' --- # @wot-ui/cli 我们在 [Open Wot](https://github.com/wot-ui/open-wot) 中维护了Wot UI 的 AI 工具链仓库,其中对外发布的核心包为 [@wot-ui/cli](https://www.npmjs.com/package/@wot-ui/cli)。它提供命令行工具、MCP Server、离线组件知识库与数据提取脚本,用于把 wot-ui v2 的组件知识接入编辑器、AI Agent 和本地工程分析流程。 如果你想了解 `llms.txt`、CLI、MCP Server 和 AI Skills 的区别,可以先阅读 [AI 使用指南](/guide/ai)。 ## 亮点 * 完全离线:组件 Props、事件、CSS 变量、Demo、Changelog 等元数据随包安装,无需网络请求 * Agent 友好:多数命令支持 `--format json`,适合被工具/脚本消费 * 项目分析:提供 `doctor / usage / lint` 诊断与统计能力 * MCP 集成:通过 `wot mcp` 以 stdio 方式提供 tools,便于集成到支持 MCP 的客户端 ## 安装 ```bash npm install -g @wot-ui/cli ``` 安装完成后可直接使用 `wot` 命令。 ## 快速开始 ```bash wot list wot info Button wot demo Button basic wot doc Button wot token Button wot changelog ``` ## 命令速查 ### 组件知识 * `wot list`:列出可用的 wot-ui 组件 * `wot info `:查看组件 props、events、slots、CSS 变量 * `wot doc `:输出组件 Markdown 文档 * `wot demo [name]`:查看 demo 列表或输出指定 demo 源码 * `wot token [Component]`:查看组件 CSS 变量与默认值 * `wot changelog [version] [component]`:查看版本更新记录 ### 项目分析 * `wot doctor [dir]`:检查项目依赖、运行环境与基础集成情况 * `wot usage [dir]`:统计 `.vue` 文件中的 `` 使用情况 * `wot lint [dir]`:检查未知组件、空按钮等规则 ### MCP Server 启动 MCP Server: ```bash wot mcp ``` 在支持 MCP 的客户端中添加配置(示例): ```json { "mcpServers": { "wot-ui": { "command": "wot", "args": ["mcp"] } } } ``` 当前 MCP Server 提供的 tools 包括: * `wot_list` * `wot_info` * `wot_doc` * `wot_demo` * `wot_token` * `wot_changelog` * `wot_lint` ## 通用参数 多数查询命令支持以下参数: * `--format text|json` * `--version v2` --- --- url: 'https://wot-ui.cn/component/action-sheet.md' --- # ActionSheet 动作面板 从底部弹出的动作菜单面板。 ## 组件类型 ### 基本用法 通过 `v-model` 设置显示隐藏。 `actions` 类型为 `Array`,数组内部对象结构如下: | 参数 | 说明 | 类型 | | --- | --- | --- | | name | 选项名称 | string | | description | 描述信息 | string | | color | 颜色 | string | ```html 弹出菜单 ``` ```typescript const show = ref(false) const actions = ref([ { name: '选项1' }, { name: '选项2' }, { name: '选项3', description: '描述信息' } ]) function showActions() { show.value = true } function close() { show.value = false } const toast = useToast() function select({ item, index }) { toast.show(`当前选中项: ${item.name}, 下标: ${index}`) } ``` ### 自定义单行面板 自定义单行面板时,`panels` 类型为一维数组,数组内部对象结构如下: | 参数 | 说明 | 类型 | | --- | --- | --- | | icon | 图标名或图片地址 | string | | title | 标题 | string | ```html 弹出菜单 ``` ```typescript const show = ref(false) const panels = ref([ { icon: 'user', title: '微信好友' }, { icon: 'share-internal', title: '朋友圈' }, { icon: 'message', title: 'QQ 好友' }, { icon: 'star-fill', title: '收藏' }, { icon: 'share-internal', title: '更多分享' }, { icon: 'user-add', title: '邀请好友' } ]) function showActions() { show.value = true } function close() { show.value = false } const toast = useToast() function select({ item, index }) { toast.show(`当前选中项: ${item.title}, 下标: ${index}`) } ``` ### 自定义多行面板 自定义多行面板时,`panels` 类型为多维数组,每个数组内部对象结构如下: | 参数 | 说明 | 类型 | | --- | --- | --- | | icon | 图标名或图片地址 | string | | title | 标题 | string | ```html 弹出菜单 ``` ```typescript const show = ref(false) const panels = ref([ [ { icon: 'user', title: '微信好友' }, { icon: 'share-internal', title: '朋友圈' }, { icon: 'message', title: 'QQ 好友' }, { icon: 'star-fill', title: '收藏' }, { icon: 'user-add', title: '邀请' }, { icon: 'share-external', title: '外部分享' }, { icon: 'qrcode', title: '生成二维码' }, { icon: 'save', title: '保存图片' } ], [ { icon: 'file-image', title: '图片' }, { icon: 'download', title: '下载' }, { icon: 'copy', title: '复制链接' } ] ]) function showActions() { show.value = true } function close() { show.value = false } const toast = useToast() function select1({ item, rowIndex, colIndex }) { toast.show(`当前选中项: ${item.title}, 行下标: ${rowIndex}, 列下标: ${colIndex}`) } ``` ## 组件状态 ### 选项状态 可以设置颜色、禁用、加载等状态。 ```html 弹出菜单 ``` ```typescript const show = ref(false) const actions = ref([ { name: '颜色', color: '#0083ff' }, { name: '禁用', disabled: true }, { loading: true } ]) function showActions() { show.value = true } function close() { show.value = false } ``` ## 组件变体 ### 取消按钮 设置 `cancel-text` 取消按钮文案,展示取消按钮。 ```html ``` ### 标题 设置 `title` 展示标题。 ```html 内容 ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 设置菜单显示隐藏 | boolean | false | | actions | 菜单选项,详见下方 Action 数据结构 | `Action[]` | `[]` | | panels | 自定义宫格面板项,支持一维 `Panel[]` 与二维 `Panel[][]`(多行) | `Array` | `[]` | | title | 标题 | string | - | | cancel-text | 取消按钮文案 | string | - | | close-on-click-action | 点击选项后是否关闭菜单 | boolean | true | | close-on-click-modal | 点击遮罩是否关闭 | boolean | true | | duration | 动画持续时间(ms) | number | 200 | | z-index | 菜单层级 | number | 10 | | lazy-render | 弹层内容懒渲染,触发展示时才渲染内容 | boolean | true | | safe-area-inset-bottom | 弹出面板是否设置底部安全距离(iPhone X 类型机型) | boolean | true | | root-portal | 是否从页面中脱离出来(H5: teleport,App: renderjs,小程序: root-portal) | boolean | false | | custom-title-class | 标题区域自定义类名 | string | - | | custom-class | 根节点自定义类名 | string | - | | custom-style | 根节点自定义样式 | string | - | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | select | 点击选项时触发 | 菜单选项或自定义面板一维数组:`{ item, index }`;自定义面板二维数组:`{ item, rowIndex, colIndex }` | | enter | 打开动画开始时触发 | - | | after-enter | 打开动画结束时触发 | - | | leave | 关闭动画开始时触发 | - | | after-leave | 关闭动画结束时触发 | - | | close | 面板关闭时触发 | - | | click-modal | 点击遮罩时触发 | - | | cancel | 点击取消按钮时触发 | - | ## Action 数据结构 | 键名 | 说明 | 类型 | | --- | --- | --- | | name | 选项名称 | string | | description | 描述信息 | string | | color | 颜色 | string | | disabled | 禁用 | boolean | | loading | 加载中状态 | boolean | ## Panel 数据结构 | 键名 | 说明 | 类型 | | --- | --- | --- | | icon | 图标名或图片地址 | string | | title | 标题内容 | string | ## Slots | name | 说明 | 参数 | | --- | --- | --- | | default | 自定义内容区,传入后会覆盖默认 actions/panels 渲染 | - | | close | 自定义标题栏右侧关闭区域 | `{ close }` | --- --- url: 'https://wot-ui.cn/guide/ai.md' --- # AI 使用指南 Wot UI 提供了面向 AI 工具的文档索引、命令行查询、MCP Server 与 Agent Skills。你可以根据使用场景选择不同接入方式,让 AI 更准确地理解组件能力、示例代码、主题变量和常见实践。 ## 选择接入方式 | 场景 | 推荐能力 | 适合工具 | | --- | --- | --- | | 让 AI 读取完整文档 | [LLMs.txt](/guide/llms-txt) | Cursor、TRAE、支持 URL 文档摄取的工具 | | 查询组件 API、Demo 和 CSS 变量 | [@wot-ui/cli](/guide/open-wot) | 终端、脚本、Agent 工具调用 | | 在 AI 客户端中调用组件知识库 | [MCP Server](/guide/open-wot#mcp-server) | 支持 MCP 的编辑器和 Agent 客户端 | | 让 Agent 按 Wot UI 规范完成开发任务 | [AI Skills](/guide/skills) | Cursor、TRAE、Cline、Codex 等 Agent | ## 推荐使用路径 ### 只想让 AI 理解文档 把 `llms.txt` 加到 AI 工具的文档集或知识库中: ```text https://wot-ui.cn/llms.txt ``` 如果工具支持读取更长上下文,可以使用完整版本: ```text https://wot-ui.cn/llms-full.txt ``` ### 想让 AI 查询组件知识 安装 `@wot-ui/cli` 后,可以通过命令查询组件列表、API、Demo、CSS 变量和更新记录: ```bash npm install -g @wot-ui/cli wot list wot info Button wot demo Button basic wot token Button ``` ### 想接入 MCP 启动 MCP Server: ```bash wot mcp ``` 在支持 MCP 的客户端中添加配置: ```json { "mcpServers": { "wot-ui": { "command": "wot", "args": ["mcp"] } } } ``` ### 想让 Agent 按项目规范工作 安装 Wot UI 相关 Skills: ```bash pnpm dlx skills add wot-ui/open-wot ``` Skills 适合让 AI 执行更主动的任务,例如组件选型、API 查询、生成 Vue 3 + uni-app 页面代码、主题生成、UnoCSS Preset 接入和常见问题排查。 ## 能力地图 | 能力 | 提供内容 | | --- | --- | | `llms.txt` | 面向 AI 的文档入口、组件索引和结构化链接 | | `llms-full.txt` | 更完整的文档内容、示例和实现细节 | | `@wot-ui/cli` | 离线组件元数据、API 查询、Demo 查询、CSS 变量查询 | | `wot mcp` | 通过 MCP tools 暴露组件知识库 | | AI Skills | 面向 Agent 的任务说明、约束和最佳实践 | ## 延伸阅读 * [LLMs.txt](/guide/llms-txt) * [@wot-ui/cli](/guide/open-wot) * [AI Skills](/guide/skills) --- --- url: 'https://wot-ui.cn/component/avatar.md' --- # Avatar 头像 用来代表用户或事物,支持图片、文本或图标展示。 ## 组件类型 ### 基础用法 头像支持三种类型:图片、文本、图标。 ```typescript const avatarURL = 'https://wot-ui.cn/assets/panda.jpg' ``` ```html ``` ### 头像组基础用法 使用 `wd-avatar-group` 组件可以展示一组头像。 ```html ``` ## 组件状态 ### 可点击 通过监听 `click` 事件实现点击功能。 ```html ``` ```typescript import { useToast } from '@/uni_modules/wot-ui' const toast = useToast() const handleClick = () => { toast.show('点击头像') } ``` ## 组件样式 ### 头像形状 使用 `shape` 属性设置头像形状,支持 `round`(圆形)和 `square`(方形),默认为 `round`。 ```html ``` ### 头像尺寸 支持预设尺寸:`large`、`medium`、`normal`、`small`,默认为 `normal`。也可以传入数字或带单位的字符串(如 `40px`、`100rpx`)自定义尺寸。 ```html ``` ### 自定义颜色 使用 `bg-color` 和 `color` 属性自定义背景色和文字颜色。 ```html ``` ## 特殊样式 ### 带徽记的头像 结合 Badge 组件展示徽记。 ```html ``` ## 内容形态 ### 自定义内容 使用默认插槽自定义头像内容。 ```html VIP ``` ## 布局能力 ### 头像组最大数量 使用 `max-count` 属性限制显示的头像数量,超出部分会以 `+N` 形式展示。 ```html ``` ### 头像组叠层方向 使用 `cascading` 属性设置叠层方向,支持 `left-up`(左侧叠在上层)和 `right-up`(右侧叠在上层)。 ```html ``` ### 头像组垂直堆叠 使用 `vertical` 属性开启垂直方向堆叠展示。 ```html ``` ## Avatar Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | src | 图片地址 | string | `''` | | text | 文本内容 | string | `''` | | icon | 图标名称,使用 wd-icon 组件 | string | `''` | | size | 头像尺寸,支持 `large / medium / normal / small` 或自定义数值/单位字符串 | string | number | normal | | shape | 头像形状,支持 `round / square` | string | round | | bg-color | 背景颜色 | string | `''` | | color | 文字颜色 | string | `''` | | alt | 图片加载失败时的占位文本 | string | `''` | | mode | 图片填充模式,同 uni-app image 组件的 mode | string | aspectFill | | custom-class | 根节点自定义类名 | string | - | | custom-style | 根节点自定义样式 | string | - | ## Avatar Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 点击头像时触发 | - | | error | 图片加载失败时触发 | `event` | ## Avatar Slots | 名称 | 说明 | | --- | --- | | default | 自定义头像内容 | ## AvatarGroup Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | max-count | 最大显示数量,超出后显示折叠头像 | number | - | | cascading | 叠层方向,可选值为 `left-up`、`right-up` | string | left-up | | shape | 统一设置组内头像形状,可选值为 `round`、`square` | string | round | | size | 统一设置组内头像尺寸,支持预设尺寸或自定义数值/单位字符串 | string | number | normal | | collapse-avatar | 超出最大数量时折叠头像显示文本 | string | `''` | | vertical | 是否垂直展示 | boolean | false | | custom-class | 根节点自定义类名 | string | - | | custom-style | 根节点自定义样式 | string | - | ## AvatarGroup Slots | 名称 | 说明 | | --- | --- | | default | 头像列表,放置 wd-avatar 组件 | --- --- url: 'https://wot-ui.cn/component/backtop.md' --- # Backtop 回到顶部 用于返回页面顶部的操作按钮。 ## 组件类型 ### 基本用法 由于回到顶部需要实时监听页面滚动位置,通常需要在页面的 `onPageScroll` 生命周期中获取滚动距离,再通过 `scroll-top` 传递给组件。 ::: code-group ```html [vue] ``` ```ts [ts] import { onPageScroll } from '@dcloudio/uni-app' import { ref } from 'vue' const scrollTop = ref(0) onPageScroll((event) => { scrollTop.value = event.scrollTop }) ``` ::: ## 组件变体 ### 形状与文字 通过 `shape` 切换圆形或方形按钮,通过 `text` 显示按钮文字。 ```html ``` ### 自定义图标 默认插槽可以替换按钮内部内容。 ```html TOP ``` ## 组件样式 ### 自定义显示距离 通过 `top` 设置滚动距离超过多少时显示按钮。 ```html ``` ### 自定义样式 通过 `custom-style` 和 `icon-style` 调整按钮与图标样式。 ```html ``` ### 自定义滚动时间 通过 `duration` 设置返回顶部滚动时长,单位为毫秒。 ```html ``` ## Backtop Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | scroll-top | 页面滚动距离 | `number` | - | | text | 按钮文字 | `string` | - | | top | 滚动距离超过该值时显示按钮,单位为 `px` | `number` | `300` | | duration | 返回顶部滚动时间,单位为 `ms` | `number` | `100` | | z-index | 组件层级 | `number` | `10` | | icon-style | 自定义图标样式 | `string` | `''` | | shape | 按钮形状,可选值为 `circle`、`square` | string | `circle` | | bottom | 距离屏幕底部的距离,单位为 `px` | `number` | `100` | | right | 距离屏幕右侧的距离,单位为 `px` | `number` | `20` | | custom-style | 自定义根节点样式 | `string` | `''` | | custom-class | 自定义根节点样式类 | `string` | `''` | ## Backtop Slots | 名称 | 说明 | | --- | --- | | default | 自定义按钮内容 | --- --- url: 'https://wot-ui.cn/component/badge.md' --- # Badge 徽标 出现在按钮、图标旁的数字或状态标记。 ## 组件类型 ### 展示消息数量 通过 `value` 展示消息数量,支持数字或文本。 ```html 评论 回复 评论 回复 评论 回复 ``` ## 组件状态 ### 点状类型 设置 `is-dot` 以红点形式标注。 ```html 数据查询 回复 ``` ### 展示 0 值 通过 `show-zero` 控制 `value=0` 时是否显示。`is-dot` 优先级高于 `show-zero`。 ```html 评论 回复 回复 ``` ## 组件变体 ### 徽标形状 设置 `shape` 切换徽标形状。 ```html 方形 气泡 ``` ## 组件样式 ### 可定义消息最大值 通过 `max` 设置最大显示值。仅当 `value` 为数字时生效。 ```html 评论 回复 ``` ## 特殊样式 ### 描边徽标 设置 `border` 可展示描边徽标。 ```html 描边 描边 描边 ``` ## 内容形态 ### 自定义内容 设置字符串 `value` 显示数字以外的文本内容。 ```html 评论 回复 ``` ```scss :deep(.badge) { margin: 0 30px 20px 0; display: inline-block; } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | value | 显示值 | string | number | - | | max | 最大值,超过后显示 `{max}+`,仅当 `value` 为 number 时生效 | number | - | | top | 为正时,角标向下偏移对应像素 | string | number | - | | right | 为正时,角标向左偏移对应像素 | string | number | - | | is-dot | 红色点状标注 | boolean | false | | hidden | 隐藏 badge | boolean | false | | type | 类型,支持 `primary / success / warning / danger / info` | string | - | | bg-color | 背景色 | string | - | | show-zero | 是否显示 0 | boolean | false | | shape | 徽标形状,支持 `circle / square / bubble` | string | circle | | border | 是否显示白色描边 | boolean | false | | custom-class | 根节点自定义类名 | string | - | | custom-style | 根节点自定义样式 | string | - | ## Slots | 名称 | 说明 | | --- | --- | | default | 徽标包裹的内容 | --- --- url: 'https://wot-ui.cn/component/button.md' --- # Button 按钮 按钮用于触发一个操作,如提交表单或打开链接。 ## 组件类型 ### 类型 ```html 主要按钮 成功按钮 信息按钮 警告按钮 危险按钮 ``` ## 组件状态 ### 禁用 设置 `disabled` 属性。 ```html 默认按钮 ``` ### 加载 设置 `loading` 属性,让按钮处于加载中状态。加载中的按钮是禁止点击的。 ```html 加载中 ``` ## 组件变体 ### 镂空 设置 `variant="plain"`。 ```html 主要按钮 ``` ### 虚线 设置 `variant="dashed"`。 ```html 主要按钮 ``` ### 柔和 设置 `variant="soft"`。 ```html 主要按钮 ``` ### 柔和描边 设置 `variant="subtle"`。 ```html 主要按钮 ``` ### 文字 设置 `variant="text"`。 ```html 文字按钮 ``` ## 组件样式 ### 尺寸 设置 `size` ,支持 'mini'、'small'、'medium'、'large',默认为 'medium'。 ```html 迷你按钮 小号按钮 中号按钮 大号按钮 ``` ### 细边框与圆角 设置 `hairline` 与 `round` 属性。 ```html 细边框 圆角按钮 ``` ## 特殊样式 ### custom-class 阴影 通过 `custom-class` 和 `custom-style` 属性可以自定义按钮样式,这里使用 `custom-class` 添加 `Material Design 3` 风格 `box-shadow`。 ```html 主要按钮 成功按钮 信息按钮 警告按钮 危险按钮 ``` ```scss .page-class { :deep() { .custom-shadow { box-shadow: 0 3px 1px -2px rgb(0 0 0 / 20%), 0 2px 2px 0 rgb(0 0 0 / 14%), 0 1px 5px 0 rgb(0 0 0 / 12%); } } } ``` ## 内容形态 ### 纯图标按钮 设置 `icon` 属性可展示图标按钮。 ```html ``` ### 图文按钮 结合 `icon` 与内容展示图文按钮;结合 `class-prefix` 可使用自定义图标,参见 [Icon 自定义图标](/component/icon#自定义图标)。 ```html 下载 可回收 ``` ## 布局能力 ### 块状按钮 设置 `block` 属性。 ```html 主要按钮 ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | type | 按钮类型,可选值为 `primary`、`success`、`info`、`warning`、`danger` | string | primary | | variant | 按钮变体,可选值为 `base`、`plain`、`dashed`、`soft`、`subtle`、`text` | string | base | | size | 按钮尺寸,可选值为 `mini`、`small`、`medium`、`large` | string | medium | | round | 圆角按钮 | boolean | false | | disabled | 禁用按钮 | boolean | false | | hairline | 细边框 | boolean | false | | block | 块状按钮 | boolean | false | | loading | 加载中按钮 | boolean | false | | text | 按钮文本 | string | - | | icon | 图标类名 | string | - | | class-prefix | 类名前缀,用于使用自定义图标,用法参考 Icon 组件 | string | wd-icon | | css-icon | CSS 图标,用法参考 Icon 组件 | `boolean \| string` | false | | loading-props | 加载配置项 | `Partial` | - | | open-type | 开放能力类型,详见下方 `ButtonOpenType` | string | - | | hover-stop-propagation | 阻止祖先节点点击态 | boolean | false | | hover-start-time | 按下后多久出现点击态(ms) | number | 20 | | hover-stay-time | 松开后多久移除点击态(ms) | number | 70 | | lang | 用户信息语言,可选值为 `zh_CN`、`zh_TW`、`en` | string | - | | session-from | 会话来源(`open-type=contact` 时有效) | string | - | | send-message-title | 会话消息卡片标题(`open-type=contact` 时有效) | string | 当前标题 | | send-message-path | 会话消息卡片路径(`open-type=contact` 时有效) | string | 当前分享路径 | | send-message-img | 会话消息卡片图片(`open-type=contact` 时有效) | string | 截图 | | app-parameter | 打开 APP 传参(`open-type=launchApp` 时有效) | string | - | | show-message-card | 显示会话消息卡片(`open-type=contact` 时有效) | boolean | false | | button-id | 按钮唯一标识 | string | - | | scope | 支付宝授权范围,可选值为 `phoneNumber`、`userInfo`(open-type=getAuthorize 时有效) | string | - | | loading-color | 加载图标颜色 | string | - | | custom-class | 根节点自定义类名 | string | - | | custom-style | 根节点自定义样式 | string | - | ### ButtonOpenType 开放能力 | 属性 | 说明 | | --- | --- | | feedback | 打开“意见反馈”页 | | share | 触发用户转发 | | getUserInfo | 获取用户信息 | | contact | 打开客服会话 | | getPhoneNumber | 获取手机号 | | getRealtimePhoneNumber | 实时获取手机号(仅微信) | | launchApp | 在小程序中打开 APP | | openSetting | 打开授权设置页 | | chooseAvatar | 获取用户头像 | | getAuthorize | 支持支付宝授权(配合 `scope`) | | lifestyle | 关注生活号(支付宝) | | contactShare | 分享到通讯录(支付宝) | | openGroupProfile | 打开群资料卡(微信) | | openGuildProfile | 打开频道资料卡(微信) | | openPublicProfile | 打开公众号资料卡(微信) | | shareMessageToFriend | 分享消息给朋友(微信) | | addFriend | 添加好友(微信) | | addColorSign | 添加彩签(微信) | | addGroupApp | 添加群应用(微信) | | addToFavorites | 收藏(微信) | | chooseAddress | 选择收货地址(微信) | | chooseInvoiceTitle | 选择发票抬头(微信) | | login | 授权登录(平台能力) | | subscribe | 订阅(平台能力) | | favorite | 收藏(平台能力) | | watchLater | 稍后再看(平台能力) | | openProfile | 打开个人主页(平台能力) | | agreePrivacyAuthorization | 用户同意隐私协议 | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 点击事件 | `event` | | getuserinfo | 获取用户信息回调 | `event` | | contact | 客服消息回调(`open-type=contact`) | `event` | | getphonenumber | 获取手机号回调(`open-type=getPhoneNumber`) | `event` | | getrealtimephonenumber | 实时获取手机号回调(`open-type=getRealtimePhoneNumber`) | `event` | | error | 开放能力错误回调(`open-type=launchApp`) | `event` | | launchapp | 打开 APP 成功回调(`open-type=launchApp`) | `event` | | opensetting | 打开授权设置页回调(`open-type=openSetting`) | `event` | | chooseavatar | 获取用户头像回调(`open-type=chooseAvatar`) | `event` | | agreeprivacyauthorization | 同意隐私协议回调(`open-type=agreePrivacyAuthorization`) | `event` | ## Slots | name | 说明 | | --- | --- | | default | 按钮内容 | --- --- url: 'https://wot-ui.cn/component/calendar.md' --- # Calendar 日历选择器 提供单选、多选、范围、周/月、日期时间等日历选择能力。 ::: tip 性能提示 `min-date` 与 `max-date` 不建议设置差距过大,避免大量日期计算影响性能。若业务需要较大时间跨度,建议配合 `switch-mode`(如 `month` / `year-month`)减少一次性渲染压力。 ::: ## 组件类型 ### 单个日期选择 ```html ``` ### 多个日期选择 ```html ``` ### 范围选择 ```html ``` ### 日期时间类型 ```html ``` ```html ``` ### 周与月类型 ```html ``` ```html ``` ### 周范围与月范围选择 ```html ``` ```html ``` ## 组件状态 ### 快捷操作 设置 `show-confirm="false"` 后,选中即确认。 ```html ``` ### before-confirm 设置 `before-confirm` 在确认前拦截,返回 `false` 或 `Promise` 可阻止确认。 ```html ``` ## 组件变体 ### 切换模式 设置 `switch-mode` 控制面板切换行为: * `none`:平铺,不展示切换按钮 * `month`:按月切换 * `year-month`:支持按年与按月切换 ```html none month year-month ``` ### 日周月切换 设置 `show-type-switch` 开启日/周/月切换。 ```html ``` ## 组件样式 ### 日期格式化 设置 `formatter` 可定制日期单元格文案与状态展示。 ```html ``` ### 自定义展示 设置 `inner-display-format` 自定义范围选择面板中的起止文案。 ```html ``` ## 特殊样式 ### 快捷选项 设置 `shortcuts` 与 `on-shortcuts-click` 实现快捷日期区间。 ```html ``` ### 拓展确定区域 通过 `confirm-left` / `confirm-right` 插槽拓展确定区按钮。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 选中值,13 位时间戳或时间戳数组 | `number \| number[] \| null` | - | | v-model:visible | 是否显示弹层 | boolean | false | | type | 日期类型,支持 `date / dates / datetime / week / month / daterange / datetimerange / weekrange / monthrange` | string | date | | min-date | 最小日期时间戳 | number | 当前日期往前 6 个月 | | max-date | 最大日期时间戳 | number | 当前日期往后 6 个月 | | first-day-of-week | 周起始日(0 表示周日) | number | 0 | | formatter | 日期格式化函数 | `CalendarFormatter` | - | | max-range | 范围类型的最大可选范围 | number | - | | range-prompt | 超出最大范围提示文案 | string | - | | allow-same-day | 范围类型是否允许同一天/同一周/同一月 | boolean | false | | default-time | 日期默认时分秒 | `string \| string[]` | - | | time-filter | 时间选项过滤函数(datetime / datetimerange) | `CalendarTimeFilter` | - | | hide-second | 是否隐藏秒选择(datetime / datetimerange) | boolean | false | | title | 弹层标题 | string | 选择日期(内置文案) | | close-on-click-modal | 点击遮罩是否关闭 | boolean | true | | z-index | 弹层层级 | number | 15 | | show-confirm | 是否显示确认按钮 | boolean | true | | confirm-text | 确认按钮文案 | string | 确定(内置文案) | | inner-display-format | 自定义范围面板内部回显 | `CalendarInnerDisplayFormat` | - | | ellipsis | 范围文案是否省略显示 | boolean | false | | show-type-switch | 是否显示日周月切换 | boolean | false | | shortcuts | 快捷选项列表(项需包含 `text`) | `Record[]` | `[]` | | on-shortcuts-click | 快捷选项点击回调 | `CalendarOnShortcutsClick` | - | | safe-area-inset-bottom | 是否开启底部安全区 | boolean | true | | before-confirm | 确认前校验函数 | `CalendarBeforeConfirm` | - | | custom-view-class | 面板内部视图类名 | string | `''` | | immediate-change | 是否手指松开即触发时间选择 change 事件 | boolean | false | | root-portal | 是否脱离页面渲染 | boolean | false | | panel-height | 可滚动面板高度 | number | 316 | | show-panel-title | 是否展示滚动面板标题 | boolean | true | | switch-mode | 切换模式,可选值为`none`、`month`、`year-month`,`none` 平铺展示所有月份/年份且不展示切换按钮;`month` 支持按月切换并展示上个月/下个月按钮;`year-month` 支持按年与按月切换并展示上一年/下一年、上个月/下个月按钮。大跨度日期场景建议使用 `month` 或 `year-month` 以降低渲染压力 | string | none | | duration | 弹层动画时长 | number | 200 | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | confirm | 点击确认后触发 | `{ value, type }` | | change | 面板日期变化时触发 | `{ value }` | | cancel | 关闭且未确认时触发 | - | | open | 日历打开时触发 | - | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | open | 打开日历弹层 | - | | close | 关闭日历弹层 | - | ## Slots | name | 说明 | | --- | --- | | confirm-left | 确认区域左侧插槽 | | confirm-right | 确认区域右侧插槽 | ## CalendarDayItem 数据结构 | 属性 | 说明 | 类型 | | --- | --- | --- | | type | 日期状态类型 | CalendarDayType | | date | 13 位时间戳 | number | | text | 日期文本内容 | string | | topInfo | 上方提示信息 | string | | bottomInfo | 下方提示信息 | string | | disabled | 是否禁用 | boolean | ### CalendarDayType | 类型 | 说明 | | --- | --- | | selected | 单日期选中 | | start | 范围开始日期 | | end | 范围结束日期 | | middle | 范围开始与结束之间的日期 | | same | 范围开始与结束日期同一天 | | current | 当前日期 | | multiple-middle | 多日期范围选择,开始与结束之间的日期 | | multiple-selected | 多日期范围选择,选中的日期 | --- --- url: 'https://wot-ui.cn/component/calendar-view.md' --- # CalendarView 日历面板组件 提供单选、多选、范围、周/月、日期时间等日历选择能力,可作为业务日历选择器的底层面板组件。 ::: tip 性能提示 `min-date` 与 `max-date` 不建议设置差距过大。若业务需要较大时间跨度,建议配合 `switch-mode`(`month` / `year-month`)降低一次性渲染压力。 ::: ## 组件类型 ### 单个日期选择 ```html ``` ### 多个日期选择 ```html ``` ### 日期范围选择 ```html ``` ### 日期时间类型 ```html ``` ### 周与月类型 ```html ``` ## 组件状态 ### 范围选择允许同一天 ```html ``` ## 组件变体 ### 切换模式 设置 `switch-mode` 控制面板切换行为: * `none`:平铺展示所有月份/年份,不展示切换按钮 * `month`:支持按月切换,展示上个月/下个月按钮 * `year-month`:支持按年与按月切换,展示上一年/下一年、上个月/下个月按钮 ```html ``` ## 组件样式 ### 格式化日期 设置 `formatter` 可定制日期单元格文案与状态。 ```html ``` ### 设置周起始日 ```html ``` ### 展示面板标题 ```html ``` ## 特殊样式 ### 最大范围限制 ```html ``` ### 时间选项过滤 设置 `hide-second` 与 `time-filter` 过滤时分秒选项。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 选中值,13 位时间戳或时间戳数组 | `number \| number[] \| null` | - | | type | 日期类型,支持 `date / dates / datetime / week / month / daterange / datetimerange / weekrange / monthrange` | string | date | | min-date | 最小日期时间戳 | number | 当前日期往前 6 个月 | | max-date | 最大日期时间戳 | number | 当前日期往后 6 个月 | | first-day-of-week | 周起始日(0 表示周日) | number | 0 | | formatter | 日期格式化函数 | `CalendarFormatter` | - | | max-range | 范围类型的最大可选范围 | number | - | | range-prompt | 超出最大范围提示文案 | string | - | | allow-same-day | 范围类型是否允许同一天/同一周/同一月 | boolean | false | | show-panel-title | 是否展示面板标题 | boolean | true | | default-time | 日期默认时分秒 | `string \| string[]` | `00:00:00` | | panel-height | 可滚动面板高度 | number | 316 | | time-filter | 时间选项过滤函数(datetime / datetimerange) | `CalendarTimeFilter` | - | | time-item-height | 时间选项高度 | number | 44 | | time-visible-item-count | 时间可见项数量 | number | 3 | | hide-second | 是否隐藏秒选择(datetime / datetimerange) | boolean | false | | immediate-change | 是否手指松开即触发时间选择 change 事件 | boolean | false | | switch-mode | 切换模式,可选值为`none`、`month`、`year-month`,`none` 平铺展示所有月份/年份且不展示切换按钮;`month` 支持按月切换并展示上个月/下个月按钮;`year-month` 支持按年与按月切换并展示上一年/下一年、上个月/下个月按钮。大跨度日期场景建议使用 `month` 或 `year-month` 以降低渲染压力 | string | none | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 面板值变化时触发 | `{ value }` | | pickstart | 时间选择滚动开始时触发 | - | | pickend | 时间选择滚动结束时触发 | - | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | scrollIntoView | 使当前日期或选中日期滚动到可视区域(面板隐藏到显示时建议调用) | - | ## CalendarDayItem 数据结构 | 属性 | 说明 | 类型 | | --- | --- | --- | | type | 日期状态类型 | CalendarDayType | | date | 13 位时间戳 | number | | text | 日期文本内容 | string | | topInfo | 上方提示信息 | string | | bottomInfo | 下方提示信息 | string | | disabled | 是否禁用 | boolean | ### CalendarDayType | 类型 | 说明 | | --- | --- | | selected | 单日期选中 | | start | 范围开始日期 | | end | 范围结束日期 | | middle | 范围开始与结束之间的日期 | | same | 范围开始与结束日期同一天 | | current | 当前日期 | | multiple-middle | 多日期范围选择,开始与结束之间的日期 | | multiple-selected | 多日期范围选择,选中的日期 | --- --- url: 'https://wot-ui.cn/component/card.md' --- # Card 卡片 用于展示商品的图片、价格等信息。 ## 组件类型 ### 基本使用 通过 `title` 设置标题,默认插槽传入内容,`footer` 插槽用于底部操作区。 ```html 至若春和景明,波澜不惊,上下天光,一碧万顷,沙鸥翔集,锦鳞游泳,岸芷汀兰,郁郁青青。 ``` ### 矩形卡片 设置 `type="rectangle"` 使用矩形卡片样式。 ```html 今天天气真好 2026年2月11日 晴天 22℃ ``` ## 组件样式 ### 复杂卡片 结合图片、标签、属性区块可构建信息密度更高的卡片内容。 ```html ... ``` ## 内容形态 ### 自定义标题 使用 `title` 插槽自定义标题区域内容。 ```html ... ``` ## 特殊样式 ### 去除 Footer 不传 `footer` 插槽时,底部区域不会渲染。 ```html ... ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | title | 卡片标题 | string | - | | type | 卡片类型,支持 `rectangle` | string | - | | custom-title-class | 标题区域自定义类名 | string | `''` | | custom-content-class | 内容区域自定义类名 | string | `''` | | custom-footer-class | 底部区域自定义类名 | string | `''` | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Slots | name | 说明 | | --- | --- | | default | 卡片内容 | | title | 卡片标题 | | footer | 底部操作内容 | --- --- url: 'https://wot-ui.cn/component/cascader.md' --- # Cascader 级联选择器 用于处理树形结构数据的分级选择,支持静态数据与异步加载两种模式。 ::: tip 提示 省市区场景可直接使用 `@vant/area-data` 的 `useCascaderAreaData` 作为数据源。 ::: ## 组件类型 ### 基础用法 ```html ``` ### 初始选项 ```html ``` ### 自定义字段 ```html ``` ## 组件状态 ### 禁用选项 ```html ``` ### 选项提示信息 ```html ``` ### 确定前校验 `before-confirm` 支持返回 `boolean` 或 `Promise`。 ```html ``` ```ts const beforeConfirm = async (value, selectedOptions) => { if (String(value) === '120000') return false return true } ``` ## 组件样式 ### 展示格式化 ```ts const handleConfirm = ({ selectedOptions }) => { displayValue.value = `${selectedOptions[selectedOptions.length - 2].text}-${selectedOptions[selectedOptions.length - 1].text}` } ``` ### 设置标题 ```html ``` ## 特殊样式 ### 异步加载 传入 `lazy-load` 后进入异步模式:`option = null` 时加载根节点,`resolve([])` 表示当前节点为叶子节点。 ```html ``` ```ts const lazyLoad = (option, tabIndex, resolve) => { fetchChildren(option ? String(option.value) : null).then(resolve) } ``` ### 异步加载(无初始值) ```html ``` ### 任意级可选 开启 `check-strictly` 后,点击节点仅更新当前路径,通过右上角确认按钮提交。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 选中项。静态模式为叶子节点值;异步模式可传路径数组用于回显 | `string \| number \| (string \| number)[]` | - | | visible / v-model:visible | 是否显示弹窗 | boolean | false | | options | 层级选项数据(树形结构) | `CascaderOption[]` | `[]` | | title | 弹出层标题 | string | - | | before-confirm | 确定前校验函数,参数为 `(value, selectedOptions)`,返回 `boolean` 或 `Promise` | `CascaderBeforeConfirm` | - | | check-strictly | 是否开启任意级可选 | boolean | false | | confirm-text | 严格模式下确认按钮文案 | string | `''` | | value-key | 选项值字段名 | string | value | | text-key | 选项文本字段名 | string | text | | children-key | 子节点字段名 | string | children | | tip-key | 提示文案字段名 | string | tip | | is-leaf-key | 叶子节点标识字段名,值为 `true` 时点击即确认 | string | isLeaf | | lazy-load | 异步加载回调,参数为 `(option, tabIndex, resolve)` | `CascaderLazyLoad` | - | | close-on-click-modal | 点击遮罩是否关闭 | boolean | true | | z-index | 弹窗层级 | number | 15 | | safe-area-inset-bottom | 弹出面板是否设置底部安全距离(iPhone X 类型机型) | boolean | true | | line-width | 底部条宽度,支持 number 或带单位字符串 | `number \| string` | - | | line-height | 底部条高度,支持 number 或带单位字符串 | `number \| string` | - | | line-theme | 底部条位置样式,支持 `normal / text / underline / dot` | string | normal | | root-portal | 是否脱离文档流渲染(H5: teleport,App: renderjs,小程序: root-portal) | boolean | false | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## CascaderOption 数据结构 | 键名 | 说明 | 类型 | | --- | --- | --- | | value | 选项值 | `string \| number` | | text | 选项文本 | string | | children | 子选项 | `CascaderOption[]` | | disabled | 是否禁用 | boolean | | tip | 提示文案 | string | | isLeaf | 是否为叶子节点(异步模式) | boolean | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | confirm | 确认选择时触发 | 静态模式:`{ value, selectedOptions }`,`value` 为叶子值;异步模式:`{ value, selectedOptions }`,`value` 为路径数组 | | close | 弹窗关闭时触发 | - | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | open | 打开级联弹窗 | - | | close | 关闭级联弹窗 | - | --- --- url: 'https://wot-ui.cn/component/cell.md' --- # Cell 单元格 单元格用于信息展示与轻交互,可独立使用,也可通过 `wd-cell-group` 统一管理布局与样式。 ## 组件类型 ### 基本用法 ```html ``` ### 分组标题 ```html ``` ## 组件状态 ### 点击反馈 ```html ``` ## 组件变体 ### Placeholder ```html ``` ### 页面跳转 ```html ``` ### 箭头方向 ```html ``` ## 组件样式 ### 图标设置 设置 `prefix-icon` 使用内置图标,或使用 `prefix` 插槽自定义前置图标。 ```html ``` ### 大尺寸 ```html ``` ### 垂直居中 ```html ``` ### 圆角卡片风格 ```html ``` ## 特殊样式 ### 展示边框线 ```html ``` ### 表单属性 ```html ``` ### 设置左侧宽度 ```html ``` ### 内容省略 ```html ``` ### 自定义内容 ```html 按钮 订购 ``` ## CellGroup Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | title | 分组标题 | string | - | | value | 分组右侧内容 | string | - | | border | 是否展示外边框 | boolean | false | | insert | 是否展示为圆角卡片风格 | boolean | false | | center | 是否使内容垂直居中 | boolean | false | | size | 单元格大小,支持 `large` | string | - | | title-width | 左侧标题宽度 | `string \| number` | - | | layout | 单元格布局方式,支持 `horizontal / vertical` | string | - | | value-align | 右侧内容对齐方式,支持 `left / right / center` | string | - | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Cell Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | title | 左侧标题 | string | - | | value | 右侧内容 | `string \| number` | `''` | | placeholder | 占位符,仅在 value 为空时显示 | string | - | | label | 标题下方描述信息 | string | - | | prefix-icon | 前置图标名 | string | - | | suffix-icon | 后置图标名 | string | - | | icon-size | 图标大小 | `string \| number` | - | | icon-prefix | 图标类名前缀 | string | - | | to | 跳转地址 | string | - | | replace | 跳转时是否替换当前页面历史 | boolean | false | | clickable | 是否开启点击反馈 | boolean | false | | is-link | 是否展示右侧箭头并开启点击反馈 | boolean | false | | arrow-direction | 箭头方向(仅在 is-link 为 true 时生效),支持 `left / up / down / right` | string | right | | size | 单元格大小,支持 `large` | string | - | | border | 是否显示内边框,优先级高于 cell-group 同名属性 | boolean | 继承自 CellGroup | | title-width | 左侧标题宽度 | `string \| number` | 继承自 CellGroup | | center | 是否垂直居中 | boolean | 继承自 CellGroup | | layout | 单元格布局方式,支持 `horizontal / vertical` | string | 继承自 CellGroup | | value-align | 右侧内容对齐方式,支持 `left / right / center` | string | 继承自 CellGroup | | required | 是否显示必填星号 | boolean | false | | asterisk-position | 必填星号位置,支持 `start / end` | string | start | | hide-asterisk | 是否隐藏必填星号 | boolean | false | | ellipsis | 内容是否超出隐藏显示省略号 | boolean | false | | use-title-slot | 是否启用 title 插槽 | boolean | true | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | | custom-prefix-class | 前置图标自定义样式类 | string | `''` | | custom-suffix-class | 后置图标自定义样式类 | string | `''` | | custom-label-class | label 区域自定义样式类 | string | `''` | | custom-value-class | value 区域自定义样式类 | string | `''` | | custom-title-class | title 区域自定义样式类 | string | `''` | ## Cell Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 当 clickable 或 is-link 为 true 时,点击单元格触发 | - | ## CellGroup Slots | name | 说明 | 参数 | | --- | --- | --- | | title | 分组标题 | - | | value | 分组右侧内容 | - | ## Cell Slots | name | 说明 | 参数 | | --- | --- | --- | | prefix | 前置图标区域 | - | | title | 标题区域 | - | | label | 描述信息区域 | - | | default | 右侧内容区域 | - | | suffix | 后置图标区域(is-link 为 false 时生效) | - | --- --- url: 'https://wot-ui.cn/component/checkbox.md' --- # Checkbox 复选框 用于在一组备选项中进行多选,支持普通样式、按钮样式、自定义图标及全选控制。 ## 组件类型 ### 基本用法 ```html 多选 1 多选 2 多选 3 多选 4 ``` ### 单独使用 `wd-checkbox` 可以不依赖 `wd-checkbox-group` 单独使用,通过 `v-model` 绑定选中状态(默认 `true-value` 为 `true`,`false-value` 为 `false`),也可通过 `true-value` / `false-value` 自定义选中与非选中时的值。 ```html 同意协议 ``` ```ts const checked = ref(false) ``` **自定义选中/非选中值** ```html 同意协议 ``` ```ts const agree = ref('no') ``` ## 组件状态 ### 禁用状态 ```html 多选 1 多选 2 多选 1 多选 2 ``` ### 半选状态 ```html 半选状态 ``` ### 只读状态 ```html 多选 1 多选 2 ``` ## 组件变体 ### 勾选在右侧 ```html 多选 1 多选 2 ``` ### 按钮样式 ```html 多选 1 多选 2 ``` ### 同行展示 ```html 多选 1 多选 2 ``` ### 最小与最大可选数量 ```html 多选 1 多选 2 多选 3 多选 4 ``` ## 组件样式 ### 修改选中颜色 ```html 多选 1 多选 2 ``` ### 修改未选中颜色 ```html 多选 1 多选 2 ``` ### 自定义图标 ```html 自定义图标 ``` ### 尺寸 ```html 多选 1 多选 2 ``` ## 特殊样式 ### 结合 Cell 使用 ```html ``` ### 全选切换 ```html 全部切换 全选 全不选 全部切换(跳过禁用) 全选(跳过禁用) 多选 1 多选 2 多选 3 多选 4 ``` ## Checkbox Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 单独使用时的绑定值 | `string \| number \| boolean` | false | | name | 在 CheckboxGroup 中的唯一标识值 | `string \| number \| boolean` | `''` | | type | 形状类型,支持 `circle / square / button / dot` | string | 继承自 CheckboxGroup | | checked-color | 选中颜色 | string | 继承自 CheckboxGroup | | unchecked-color | 未选中颜色 | string | 继承自 CheckboxGroup | | disabled | 是否禁用 | `boolean \| null` | 继承自 CheckboxGroup | | readonly | 是否只读 | `boolean \| null` | 继承自 CheckboxGroup | | indeterminate | 是否半选状态(样式优先级最高) | boolean | false | | true-value | 单独使用时的选中值 | `string \| number \| boolean` | true | | false-value | 单独使用时的非选中值 | `string \| number \| boolean` | false | | size | 尺寸,支持 `large` | string | 继承自 CheckboxGroup | | placement | 勾选图标位置,支持 `left / right` | string | 继承自 CheckboxGroup | | direction | 布局方向,支持 `horizontal / vertical` | string | 继承自 CheckboxGroup | | max-width | 文本最大宽度 | string | - | | custom-label-class | label 文本自定义类名 | string | - | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## CheckboxGroup Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 绑定值数组 | `Array` | `[]` | | type | 形状类型,支持 `circle / square / button / dot` | string | circle | | checked-color | 选中颜色 | string | - | | unchecked-color | 未选中颜色 | string | - | | disabled | 是否禁用全部选项 | boolean | false | | readonly | 是否只读全部选项 | boolean | false | | min | 最小可选数量 | number | 0 | | max | 最大可选数量,`0` 表示不限制 | number | 0 | | size | 尺寸,支持 `large` | string | - | | placement | 勾选图标位置,支持 `left / right` | string | left | | direction | 布局方向,支持 `horizontal / vertical` | string | vertical | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Checkbox Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 单独使用时,绑定值变化后触发 | `{ value }` | ## CheckboxGroup Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 组选中值变化后触发 | `{ value }` | ## Checkbox Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | toggle | 切换当前选中状态 | - | ## CheckboxGroup Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | toggleAll | 批量切换全部选项状态 | `boolean \| { checked?: boolean; skipDisabled?: boolean }` | ## Checkbox Slots | name | 说明 | 参数 | | --- | --- | --- | | default | 自定义文本内容 | - | | icon | 自定义图标 | `{ isChecked }` | ## CheckboxGroup Slots | name | 说明 | 参数 | | --- | --- | --- | | default | 复选框列表内容 | - | --- --- url: 'https://wot-ui.cn/component/circle.md' --- # Circle 环形进度条 圆环形进度条组件,支持颜色定制、渐变色、方向控制和插槽内容。 ## 组件类型 ### 基础用法 通过 `v-model` 绑定当前进度,`text` 控制中间文本。 ```html ``` ## 组件样式 ### 宽度控制 通过 `stroke-width` 控制进度条宽度。 ```html ``` ### 颜色定制 通过 `color` 控制进度条颜色,`layer-color` 控制轨道颜色。 ```html ``` ### 渐变色 `color` 支持对象格式定义渐变色。 ```html ``` ```ts const gradientColor = { '0': 'red', '100': 'white' } ``` ### 逆时针方向 设置 `clockwise` 为 `false`,进度从逆时针方向展开。 ```html ``` ### 大小定制 通过 `size` 控制圆环直径。 ```html ``` ## 内容形态 ### 使用默认插槽 不传 `text` 时可使用默认插槽自定义中心内容。 ```html {{ current }}% ``` ## 特殊样式 ### 进度控制 ```html 增加 减少 ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前进度 | number | 0 | | size | 圆环直径,单位 px | number | 120 | | color | 进度条颜色,支持字符串或渐变对象 | `string \| Record` | `#1C64FD` | | layer-color | 轨道颜色 | string | `#F2F3F5` | | fill | 填充颜色 | string | - | | speed | 动画速度,单位 rate/s | number | 50 | | text | 圆环中间文字 | string | - | | stroke-width | 进度条宽度,单位 px | number | 18 | | stroke-linecap | 端点形状,可选值为 `butt`、`round`、`square` | string | round | | clockwise | 是否顺时针增加 | boolean | true | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Slots | name | 说明 | 参数 | | --- | --- | --- | | default | 自定义圆环中心内容(仅在 `text` 为空时显示) | - | --- --- url: 'https://wot-ui.cn/component/collapse.md' --- # Collapse 折叠面板 将一组内容放置在多个折叠面板中,点击面板标题可展开或收起内容。 ## 组件类型 ### 基本使用 `v-model` 绑定值可为: * 普通折叠:`string[]` * 手风琴模式:`string` * 查看更多模式:`boolean` ```html 这是一条简单的示例文字。 这是一条简单的示例文字。 ``` ## 组件状态 ### 禁用 设置 `wd-collapse-item` 的 `disabled` 属性禁用单个面板。 ```html 这是一条简单的示例文字。 这是一条简单的示例文字。 ``` ### 异步更新 通过 `before-expend` 在面板打开前执行拦截,返回 `boolean` 或 `Promise`。 ```html {{ item.body }} ``` ```ts const beforeExpend = (name: string) => { return new Promise((resolve) => { setTimeout(() => resolve(true), 500) }) } ``` ## 组件变体 ### 手风琴 设置 `accordion` 后同一时刻仅展开一项。 ```html 这是一条简单的示例文字。 这是一条简单的示例文字。 这是一条简单的示例文字。 ``` ### 查看更多 设置 `viewmore` 后可折叠长文本,`line-num` 控制收起行数。 ```html 这是一条简单的示例文字。这是一条简单的示例文字。这是一条简单的示例文字。这是一条简单的示例文字。 ``` ## 组件样式 ### 自定义标题 使用 `wd-collapse-item` 的 `title` 具名插槽,可获取 `expanded / disabled / isFirst`。 ```html 这是一条简单的示例文字。 ``` ### 查看更多插槽 查看更多模式下可通过 `use-more-slot` 启用 `more` 插槽,自定义“展开/收起”区域。 ```html 这是一条简单的示例文字。这是一条简单的示例文字。这是一条简单的示例文字。 ``` ## 特殊样式 ### 嵌套使用 `collapse` 支持嵌套。由于 `collapse-item` 内容容器存在默认 `padding`,嵌套时建议用 `custom-body-style` 或 `custom-body-class` 覆盖。 ```html {{ child.body }} ``` ### toggleAll 通过 `Collapse` 实例方法 `toggleAll` 批量切换展开状态。 ```html ... ``` ```ts collapseRef.value?.toggleAll() collapseRef.value?.toggleAll(true) collapseRef.value?.toggleAll(false) collapseRef.value?.toggleAll({ skipDisabled: true }) collapseRef.value?.toggleAll({ expanded: true, skipDisabled: true }) ``` ## CollapseItem Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | name | 折叠栏唯一标识符 | string | - | | title | 折叠栏标题,支持 `title` 插槽覆盖 | string | `''` | | disabled | 是否禁用该折叠栏 | boolean | false | | before-expend | 打开前拦截函数,接收 `name` 参数,返回 `boolean` 或 `Promise` | `CollapseItemBeforeExpand` | - | | border | 是否显示边框 | boolean | true | | custom-body-class | 折叠栏内容容器自定义类名 | string | `''` | | custom-body-style | 折叠栏内容容器自定义样式 | string | `''` | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ### CollapseItemBeforeExpand 参数 | 参数名 | 说明 | 类型 | | --- | --- | --- | | name | 当前折叠栏唯一标识符 | string | ## Collapse Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 绑定值。普通模式为 `string[]`,手风琴模式为 `string`,查看更多模式为 `boolean` | `string \| string[] \| boolean` | - | | accordion | 是否开启手风琴模式 | boolean | false | | viewmore | 是否开启查看更多模式 | boolean | false | | use-more-slot | 查看更多模式下是否启用 `more` 插槽 | boolean | false | | line-num | 查看更多模式下收起显示行数 | number | 2 | | custom-more-slot-class | 查看更多模式下 `more` 插槽外部自定义类名 | string | `''` | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 绑定值变化时触发 | `{ value }` | ## Methods | 方法名 | 说明 | 参数 | | --- | --- | --- | | toggleAll | 切换所有面板展开状态。传 `true` 全部展开,`false` 全部收起,不传为全部切换 | `options?: CollapseToggleAllOptions` | ### CollapseToggleAllOptions | 参数名 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | expanded | 是否展开,`true` 展开,`false` 收起 | boolean | - | | skipDisabled | 是否跳过禁用项 | boolean | false | ## Collapse Slots | name | 说明 | 参数 | | --- | --- | --- | | default | 面板内容或面板项列表 | - | | more | 查看更多模式下自定义展开收起区域 | - | ## CollapseItem Slots | name | 说明 | 参数 | | --- | --- | --- | | title | 自定义标题区域 | `{ expanded, disabled, isFirst }` | | default | 折叠栏内容 | - | --- --- url: 'https://wot-ui.cn/component/config-provider.md' --- # ConfigProvider 全局配置 用于为 `Wot` 组件提供主题模式和主题变量配置,支持深色模式、主题定制和跨组件树共享配置。 ## 组件类型 ### 深色模式 将 `theme` 设置为 `dark` 后,可以让当前 `ConfigProvider` 包裹范围内的 `Wot` 组件切换为深色风格。 ::: warning 注意 使用深色模式前,需要在入口文件(如 `App.vue`)中引入主题变量文件: * npm 安装:`@use '@wot-ui/ui/styles/theme/index.scss' as *;` * uni\_modules 安装:`@use '@/uni_modules/wot-ui/styles/theme/index.scss' as *;` ::: ::: tip 提示 `ConfigProvider` 只影响 `Wot` 组件自身的主题表现,不会自动修改页面全局文本色或背景色。你可以结合全局样式自行处理页面背景和文本颜色。 ::: ::: code-group ```vue [vue] 深色模式按钮 ``` ```scss [App.vue - npm] /* App.vue */ @use '@wot-ui/ui/styles/theme/index.scss' as *; ``` ```scss [App.vue - uni_modules] /* App.vue */ @use '@/uni_modules/wot-ui/styles/theme/index.scss' as *; ``` ::: ## 切换主题 通过响应式地更新 `theme`,可以在浅色和深色模式之间切换。 ::: code-group ```vue [vue] 当前模式:{{ theme }} ``` ```ts [ts] import { ref } from 'vue' const theme = ref<'light' | 'dark'>('light') setTimeout(() => { theme.value = 'dark' }, 1000) ``` ```scss [App.vue - npm] /* App.vue */ @use '@wot-ui/ui/styles/theme/index.scss' as *; ``` ```scss [App.vue - uni_modules] /* App.vue */ @use '@/uni_modules/wot-ui/styles/theme/index.scss' as *; ``` ::: ## 主题定制 ### 通过 CSS 变量覆盖 `Wot UI` 组件通过 CSS 变量组织样式。你可以直接覆盖这些变量来调整组件外观。 ```css :root, page { --wot-button-primary-bg: green; } ``` ### 通过 ConfigProvider 覆盖 `ConfigProvider` 支持通过 `theme-vars` 覆盖主题变量,仅影响当前包裹范围内的组件。 ::: tip 提示 `ConfigProvider` 仅影响它的子组件样式,不会直接修改全局 `root` 节点样式。 ::: ::: code-group ```html [vue] 提交 ``` ```ts [ts] import { reactive } from 'vue' const themeVars = reactive({ buttonPrimaryBg: '#07c160', buttonPrimaryColor: '#ffffff' }) ``` ::: ### 在 TypeScript 中使用 在 TypeScript 中定义 `themeVars` 时,建议使用组件库提供的 `ConfigProviderThemeVars` 类型,以获得完整的类型提示。 ::: code-group ```ts [ts] import type { ConfigProviderThemeVars } from '@wot-ui/ui' const themeVars: ConfigProviderThemeVars = { buttonPrimaryBgColor: '#07c160', buttonPrimaryColor: '#ffffff' } ``` ```ts [ts] import type { ConfigProviderThemeVars } from '@/uni_modules/wot-ui/components/wd-config-provider/types' const localThemeVars: ConfigProviderThemeVars = { cellTitleColor: '#4d80f0' } ``` ::: ## 特殊样式 ### 全局共享 如需在应用层共享主题配置,可以结合虚拟根组件 [uni-ku-root](https://github.com/uni-ku/root) 使用。 #### 安装 ::: code-group ```bash [npm] npm i -D @uni-ku/root ``` ```bash [yarn] yarn add -D @uni-ku/root ``` ```bash [pnpm] pnpm add -D @uni-ku/root ``` ::: #### 引入 * CLI 项目:直接编辑根目录下的 vite.config.(js|ts) * HBuilderX 项目:需要在根目录下创建 vite.config.(js|ts) ```ts import { defineConfig } from 'vite' import UniKuRoot from '@uni-ku/root' import Uni from '@dcloudio/vite-plugin-uni' export default defineConfig({ plugins: [UniKuRoot(), Uni()] }) ``` ::: tip 若存在会修改 pages.json 的插件,需要将 `UniKuRoot` 放置在这些插件之后。 ::: #### 使用 1. 创建根组件并处理全局配置组件。 ```vue ``` 2. 编写控制主题的组合式函数。 ```ts import type { ConfigProviderThemeVars } from '@wot-ui/ui' import { ref } from 'vue' const theme = ref<'light' | 'dark'>('light') const themeVars = ref() export function useTheme(vars?: ConfigProviderThemeVars) { if (vars) themeVars.value = vars function toggleTheme(mode?: 'light' | 'dark') { theme.value = mode || (theme.value === 'light' ? 'dark' : 'light') } return { theme, themeVars, toggleTheme } } ``` 3. 在任意页面中使用切换主题模式。 ```vue ``` ## 组合式函数 ### useConfigProvider 详细文档请查看 [useConfigProvider](/component/use-config-provider)。 在微信小程序等环境中,由于组件渲染机制限制,被渲染在插槽中的组件或通过 `root-portal` 移动到根节点的组件,可能无法继承外层 `ConfigProvider` 的 provide 上下文。为了解决这个问题,组件库提供了 `useConfigProvider`,允许你在逻辑层显式注入配置。 #### 引入 ```ts import { useConfigProvider } from '@wot-ui/ui' ``` #### 使用 `useConfigProvider` 接受一个包含 `themeVars` 的对象,`themeVars` 支持普通对象、`reactive` 对象或 `Ref` 对象。 ```vue ``` ## 全局组件配置 `ConfigProvider` 支持为子组件统一设置默认值,减少重复配置。 ### 作用范围一览 不同配置项实际影响的组件不同,请按需配置。 | 配置项 | 作用范围(当前生效的组件) | | --- | --- | | `button.size` | `wd-button` | | `button.variant` | `wd-button` | | `button.type` | `wd-button` | | `button.round` | `wd-button` | | `tag.size` | `wd-tag` | | `tag.variant` | `wd-tag` | | `tag.round` | `wd-tag` | ::: tip 提示 未在上表中列出的组件(如 `wd-input`、`wd-avatar` 等)当前**不受**全局配置影响,需要继续在组件上直接传 prop。后续版本会逐步扩大接入范围。 ::: ### 组件专属配置 通过 `button` / `tag` 等属性为特定组件设置全局默认值。 * **`button`**:`{ size, variant, type, round }` —— 影响 `wd-button` 的默认尺寸、变体、类型、圆角 * **`tag`**:`{ size, variant, round }` —— 影响 `wd-tag` 的默认尺寸、变体、圆角 ::: code-group ```vue [vue] 大号朴素圆角按钮 小号浅色标签 ``` ::: ::: tip 关于命令式 API `useToast()` / `useDialog()` 等命令式 API 是通过函数式调用使用的,**不读取** `ConfigProvider` 配置,需要在调用时直接传入 `options`(如 `useToast().show({ msg, duration })`)。这是 wot-ui 当前的设计取舍,目的是避免模块单例在 Vite 预构建 / 多实例场景下带来的同步问题。 ::: ### 配置优先级 ```text 组件 prop > 组件专属配置(如 button.size) > 组件内置默认值 ``` ### 生效边界 1. **嵌套合并**:`ConfigProvider` 可以嵌套,内层配置会与外层做深度合并,同名键以内层为准;未指定的键继承外层。 2. **Portal / 小程序插槽兜底**:通过 `root-portal` 移出文档流或在小程序原生插槽中渲染的组件无法通过 inject 拿到 provider 上下文,此时可使用 `useConfigProvider` 组合式函数在逻辑层显式注入主题(详见 [useConfigProvider](/component/use-config-provider))。 ## ConfigProvider Attributes | 参数 | 说明 | 类型 | 默认值 | 作用范围 | | --- | --- | --- | --- | --- | | theme | 主题风格,可选值为 `light`、`dark` | string | `light` | 所有 Wot 组件 | | theme-vars | 自定义主题变量 | `ConfigProviderThemeVars` | `{}` | 所有 Wot 组件 | | button | Button 组件全局配置,支持 `size` / `variant` / `type` / `round` | `{ size?: string; variant?: string; type?: string; round?: boolean }` | `{}` | `wd-button` | | tag | Tag 组件全局配置,支持 `size` / `variant` / `round` | `{ size?: string; variant?: string; round?: boolean }` | `{}` | `wd-tag` | | custom-class | 根节点自定义样式类 | string | `''` | 根节点 | | custom-style | 根节点自定义样式 | string | `''` | 根节点 | ## ConfigProvider Slots | 名称 | 说明 | | --- | --- | | default | 默认插槽,用于包裹需要应用主题的子组件 | --- --- url: 'https://wot-ui.cn/component/count-down.md' --- # CountDown 倒计时 用于实时展示倒计时数值,支持毫秒级渲染与手动控制。 ## 组件类型 ### 基础用法 `time` 表示倒计时总时长,单位毫秒。 ```html ``` ```ts const time = ref(30 * 60 * 60 * 1000) ``` ## 组件变体 ### 自定义格式 通过 `format` 自定义展示格式。 ```html ``` ### 毫秒级渲染 设置 `millisecond` 开启毫秒级渲染。 ```html ``` ## 组件样式 ### 自定义样式 使用默认插槽自定义倒计时内容,插槽参数见下方 `TimeData`。 ```html ``` ## 特殊样式 ### 手动控制 通过实例方法控制开始、暂停、重置。 ```html ``` ```ts const countDown = ref() const start = () => countDown.value?.start() const pause = () => countDown.value?.pause() const reset = () => countDown.value?.reset() ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | time | 倒计时时长,单位毫秒 | number | - | | millisecond | 是否开启毫秒级渲染 | boolean | false | | format | 倒计时格式化字符串 | string | `HH:mm:ss` | | auto-start | 是否在初始化和重置后自动开始倒计时 | boolean | true | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 倒计时变化时触发 | `current: TimeData` | | finish | 倒计时结束时触发 | - | ## Methods | 方法名 | 说明 | 参数 | | --- | --- | --- | | start | 开始倒计时 | - | | pause | 暂停倒计时 | - | | reset | 重置倒计时;若 `auto-start` 为 `true`,重置后自动开始 | - | ## Slots | name | 说明 | 参数 | | --- | --- | --- | | default | 自定义倒计时展示内容 | `{ current: TimeData }` | ### format 格式 | 格式 | 说明 | | --- | --- | | DD | 天数 | | HH | 小时 | | mm | 分钟 | | ss | 秒数 | | S | 毫秒(1 位) | | SS | 毫秒(2 位) | | SSS | 毫秒(3 位) | ### TimeData 对象 | 属性 | 说明 | 类型 | | --- | --- | --- | | total | 剩余总毫秒数 | number | | days | 天 | number | | hours | 小时 | number | | minutes | 分钟 | number | | seconds | 秒 | number | | milliseconds | 毫秒 | number | --- --- url: 'https://wot-ui.cn/component/count-to.md' --- # CountTo 数字滚动 用于数字滚动展示,支持主题、前后缀、小数精度与手动控制。 ## 组件类型 ### 基本用法 设置 `end-val` 指定最终值,`start-val` 指定起始值,`duration` 指定滚动时长(ms)。 ```html ``` ## 组件样式 ### 设置主题 通过 `type` 设置文本主题,可选值为 `default`、`primary`、`success`、`warning`、`error`。 ```html ``` ## 特殊样式 ### 手动控制 设置 `auto-start="false"` 后,可通过实例方法手动开始、暂停、重置。 ```html ``` ```ts import type { CountToInstance } from '@/uni_modules/wot-ui/components/wd-count-to/types' const countTo = ref() const start = () => countTo.value?.start() const pause = () => countTo.value?.pause() const reset = () => countTo.value?.reset() ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | color | 文本颜色 | string | `''` | | type | 主题类型,可选值为 `default`、`primary`、`success`、`warning`、`error` | string | default | | start-val | 起始值 | number | 0 | | end-val | 最终值 | number | 2024 | | duration | 从起始值到结束值数字变动的时间(毫秒) | number | 3000 | | auto-start | 是否自动开始 | boolean | true | | decimals | 保留的小数位数,需大于等于 0 | number | 0 | | decimal | 小数点符号 | string | `.` | | separator | 千分位分隔符 | string | `,` | | prefix | 前缀文本 | string | `''` | | suffix | 后缀文本 | string | `''` | | use-easing | 是否使用缓动动画 | boolean | true | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | mounted | 组件加载完成时触发 | - | | finish | 动画完成时触发 | - | ## Methods | 方法名 | 说明 | 参数 | | --- | --- | --- | | start | 开始动画 | - | | pause | 暂停动画 | - | | reset | 重置动画;若 `auto-start` 为 `true`,重置后自动开始 | - | ## Slots | 名称 | 说明 | 参数 | | --- | --- | --- | | default | 主体数字内容 | - | | prefix | 前缀内容 | - | | suffix | 后缀内容 | - | --- --- url: 'https://wot-ui.cn/component/curtain.md' --- # Curtain 幕帘 一般用于公告类图片弹窗展示。 ## 组件类型 ### 基本用法 通过 `v-model` 控制显示与隐藏;`src` 为幕帘图片地址;`to` 为点击图片后的跳转链接;`width` 为图片宽度(高度按原图比例自动计算)。 ```html 展示幕帘 ``` ## 组件样式 ### 修改关闭按钮位置 `close-position` 可选值为 `inset`、`top`、`bottom`、`top-left`、`top-right`、`bottom-left`、`bottom-right`。 ```html ``` ## 组件状态 ### 点击遮罩可关闭 设置 `close-on-click-modal` 后,点击遮罩会关闭幕帘。 ```html ``` ## 特殊样式 ### 自定义关闭按钮 通过 `close` 插槽自定义关闭按钮内容和交互。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model / modelValue | 绑定值,控制幕帘显示与关闭 | boolean | false | | value | 绑定值(已废弃,请使用 `modelValue`) | boolean | false | | src | 幕帘图片地址,必须使用网络地址 | string | - | | width | 幕帘图片宽度,默认单位 px | number | - | | to | 幕帘图片点击链接 | string | - | | close-position | 关闭按钮位置,可选值为 `inset`、`top`、`bottom`、`top-left`、`top-right`、`bottom-left`、`bottom-right` | string | `inset` | | close-on-click-modal | 点击遮罩是否关闭 | boolean | false | | hide-when-close | 关闭时是否隐藏弹出层(`display: none`) | boolean | true | | z-index | 设置层级 | number | 10 | | custom-close-class | 关闭按钮自定义类名 | string | `''` | | custom-close-style | 关闭按钮自定义样式 | string | `''` | | root-portal | 是否从页面中脱离,用于解决 fixed 失效问题(H5: teleport,App: renderjs,小程序: root-portal) | boolean | false | | show-menu-by-longpress | 开启长按图片显示识别小程序码菜单,仅微信小程序支持 | boolean | false | | close-on-click | 点击图片时是否关闭幕帘 | boolean | true | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 点击幕帘图片时触发 | - | | close | 弹出层关闭时触发 | - | | closed | 弹出层关闭动画结束后触发 | - | | click-modal | 点击遮罩时触发 | - | | beforeenter | 进入前触发 | - | | enter | 进入时触发 | - | | afterenter | 进入后触发 | - | | beforeleave | 离开前触发 | - | | leave | 离开时触发 | - | | afterleave | 离开后触发 | - | | load | 图片加载完成时触发 | `event` | | error | 图片加载失败时触发。图片加载失败后,即使 `modelValue` 为 `true` 也不会展示幕帘 | - | ## Slots | name | 说明 | 参数 | | --- | --- | --- | | close | 自定义关闭按钮 | - | --- --- url: 'https://wot-ui.cn/component/datetime-picker.md' --- # DatetimePicker 日期时间选择器 对 `DatetimePickerView` 的封装组件,内置日期时间列构建与弹窗交互。 ## 组件类型 ### 基本用法 `v-model` 绑定当前值,点击确认后通过 `confirm` 返回结果。 ```html ``` ```ts const value = ref(Date.now()) const show = ref(false) const handleConfirm = ({ value }: { value: number | string | Array }) => { console.log(value) } ``` ### 限制可选时间范围 使用 `min-date` 和 `max-date` 约束日期范围。 ```html ``` ```ts const value = ref(Date.now()) const show = ref(false) const minDate = new Date(new Date().getFullYear(), 0, 1).getTime() const maxDate = new Date(new Date().getFullYear() + 1, 11, 31, 23, 59, 59).getTime() ``` ## 组件状态 ### 确定前校验 设置 `before-confirm`,在点击确定时执行拦截校验,支持返回 `boolean` 或 `Promise`。 ```html ``` ```ts const value = ref(Date.now()) const show = ref(false) const beforeConfirm = (value: number | string | Array) => { if (Array.isArray(value)) return true if (typeof value === 'number') return value <= Date.now() return true } ``` ## 组件变体 ### 类型切换 支持 `datetime`、`date`、`year-month`、`year`、`time` 五种类型。 ::: code-group ```html [模板] ``` ```ts [脚本] const dateValue = ref(Date.now()) const yearMonthValue = ref(Date.now()) const yearValue = ref(Date.now()) const timeValue = ref('09:20') const datetimeValue = ref(Date.now()) ``` ::: ### 开启秒选择 在 `time` 和 `datetime` 类型下可通过 `use-second` 显示秒。 ```html ``` ```ts const timeValue = ref('09:20:30') const value = ref(Date.now()) ``` ### 区间选择 当 `v-model` 为数组时开启区间选择模式。 ```html ``` ```ts const rangeValue = ref<(string | number)[]>(['', Date.now()]) const show = ref(false) ``` ## 组件样式 ### 自定义列项格式 通过 `formatter` 自定义滚筒内选项文案。 ```html ``` ```ts const formatter = (type: string, value: number) => { switch (type) { case 'year': return `${value}年` case 'month': return `${value}月` case 'date': return `${value}日` case 'hour': return `${value}时` case 'minute': return `${value}分` case 'second': return `${value}秒` default: return `${value}` } } ``` ### 过滤列选项 通过 `filter` 过滤可选项列表。 ```html ``` ```ts const filter = ({ type, values }: { type: string; values: number[] }) => { if (type === 'minute') { return values.filter((value) => value % 5 === 0) } return values } ``` ### 自定义区间 Tab 文案 区间选择模式下通过 `display-format-tab-label` 格式化开始/结束标签显示。 ```html ``` ```ts const displayFormatTabLabel = (items: Array<{ label: string | number }>) => { return `${items[0].label}年${items[1].label}月${items[2].label}日 ${items[3].label}:${items[4].label}` } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model / modelValue | 绑定值。`time` 类型为字符串;区间模式为数组;其余类型为时间戳 | `string \| number \| Array` | - | | visible / v-model:visible | 是否显示弹窗 | boolean | false | | type | 选择器类型,可选值为 `datetime`、`date`、`year-month`、`time`、`year` | string | datetime | | title | 弹出层标题 | string | - | | cancel-button-text | 取消按钮文案 | string | - | | confirm-button-text | 确认按钮文案 | string | - | | close-on-click-modal | 点击遮罩是否关闭 | boolean | true | | safe-area-inset-bottom | 弹出面板是否设置底部安全距离 | boolean | true | | item-height | 单项高度 | number | 44 | | visible-item-count | 可见项数量 | number | 6 | | value-key | 选项值字段名 | string | value | | label-key | 选项文案字段名 | string | label | | min-date | 最小日期(时间戳) | number | 当前年份前 10 年 1 月 1 日 | | max-date | 最大日期(时间戳) | number | 当前年份后 10 年 12 月 31 日 23:59:59 | | min-hour | 最小小时(`time` 类型生效) | number | 0 | | max-hour | 最大小时(`time` 类型生效) | number | 23 | | min-minute | 最小分钟(`time` 类型生效) | number | 0 | | max-minute | 最大分钟(`time` 类型生效) | number | 59 | | use-second | 是否显示秒选择,仅 `time` 和 `datetime` 生效 | boolean | false | | min-second | 最小秒数,仅 `time` 和 `datetime` 生效 | number | 0 | | max-second | 最大秒数,仅 `time` 和 `datetime` 生效 | number | 59 | | formatter | 自定义滚筒选项格式化函数 | DatetimePickerViewFormatter | - | | filter | 自定义过滤函数 | DatetimePickerViewFilter | - | | before-confirm | 确定前校验函数,接收 `(value)`,返回 `boolean` 或 `Promise` | DatetimePickerBeforeConfirm | - | | display-format-tab-label | 区间模式下自定义 Tab 标签格式化函数 | DatetimePickerDisplayFormatTabLabel | - | | z-index | 弹窗层级 | number | 15 | | immediate-change | 是否在手指松开时立即触发 change(仅微信/支付宝小程序) | boolean | false | | root-portal | 是否脱离文档流渲染(H5: teleport,App: renderjs,小程序: root-portal) | boolean | false | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | | custom-view-class | pickerView 外部自定义样式类 | string | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | open | 打开弹窗时触发 | - | | cancel | 点击取消或关闭弹窗时触发 | - | | confirm | 点击确认按钮触发 | `{ value }` | | change | 选中值变化时触发 | `{ value }` | | toggle | 区间模式切换开始/结束 Tab 时触发 | 当前激活 Tab 对应的值 | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | open | 打开 picker 弹框 | - | | close | 关闭 picker 弹框 | - | --- --- url: 'https://wot-ui.cn/component/datetime-picker-view.md' --- # DatetimePickerView 日期时间选择器视图 用于构建日期时间滚筒选项的基础视图组件。 ## 组件类型 ### 基本用法 `v-model` 绑定选中值;默认 `datetime` 类型,值为时间戳。 ```html ``` ```ts const value = ref(Date.now()) const handleChange = ({ value }: { value: number | string }) => { console.log(value) } ``` ## 组件变体 ### 日期类型 支持 `datetime`、`date`、`year-month`、`year`、`time` 五种类型。 ::: code-group ```html [模板] ``` ```ts [脚本] const dateValue = ref(Date.now()) const yearMonthValue = ref(Date.now()) const yearValue = ref(Date.now()) const timeValue = ref('11:12') const datetimeValue = ref(Date.now()) ``` ::: ### 开启秒选择 在 `time` 和 `datetime` 类型下可通过 `use-second` 展示秒列。 ```html ``` ```ts const timeValue = ref('11:12:30') const value = ref(Date.now()) ``` ## 组件样式 ### 修改内部格式 通过 `formatter` 自定义滚筒文案格式。 ```html ``` ```ts const formatter = (type: string, value: number) => { switch (type) { case 'year': return `${value}年` case 'month': return `${value}月` case 'date': return `${value}日` case 'hour': return `${value}时` case 'minute': return `${value}分` case 'second': return `${value}秒` default: return `${value}` } } ``` ### 过滤选项 通过 `filter` 按列过滤可选值。 ```html ``` ```ts const filter = ({ type, values }: { type: string; values: number[] }) => { if (type === 'minute') { return values.filter((value) => value % 5 === 0) } return values } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model / modelValue | 选中项,`time` 类型为字符串,其余类型为时间戳 | `string \| number` | - | | type | 选择器类型,可选值为 `datetime`、`date`、`year-month`、`time`、`year` | DateTimeType | datetime | | item-height | 单项高度 | number | 44 | | visible-item-count | 可见项数量 | number | 6 | | value-key | 选项值字段名 | string | value | | label-key | 选项文案字段名 | string | label | | formatter | 自定义选项文案格式化函数 | DatetimePickerViewFormatter | - | | filter | 自定义过滤函数 | DatetimePickerViewFilter | - | | column-formatter | 自定义列格式化函数 | DatetimePickerViewColumnFormatter | - | | min-date | 最小日期(时间戳) | number | 当前年份前 10 年 1 月 1 日 | | max-date | 最大日期(时间戳) | number | 当前年份后 10 年 12 月 31 日 | | min-hour | 最小小时(`time` 类型生效) | number | 0 | | max-hour | 最大小时(`time` 类型生效) | number | 23 | | min-minute | 最小分钟(`time` 类型生效) | number | 0 | | max-minute | 最大分钟(`time` 类型生效) | number | 59 | | use-second | 是否显示秒选择,仅 `time` 和 `datetime` 生效 | boolean | false | | min-second | 最小秒数,仅 `time` 和 `datetime` 生效 | number | 0 | | max-second | 最大秒数,仅 `time` 和 `datetime` 生效 | number | 59 | | immediate-change | 是否在手指松开时立即触发 change(仅微信/支付宝小程序) | boolean | false | | boundary-min-date | 区间模式开始时间最小边界(用于联动) | number | - | | boundary-max-date | 区间模式结束时间最大边界(用于联动) | number | - | | custom-class | 根节点自定义类名 | string | `''` | | custom-style | 根节点自定义样式 | string | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 选中项变化时触发 | `{ value, columns }` | | pickstart | 滚动开始时触发 | - | | pickend | 滚动结束时触发 | - | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | getSelectedOptions | 获取当前选中项对象数组 | - | | correctValue | 纠正并返回合法值 | `value: string \| number` | | getOriginColumns | 获取原始列定义 | - | ## Types ### DatetimePickerViewColumn | 键名 | 说明 | 类型 | | --- | --- | --- | | type | 列类型 | `year \| month \| date \| hour \| minute \| second` | | values | 当前列可选值数组 | number\[] | ### DatetimePickerViewOption | 键名 | 说明 | 类型 | | --- | --- | --- | | value | 选项值 | number | | label | 选项展示文本 | string | | disabled | 是否禁用 | boolean | --- --- url: 'https://wot-ui.cn/component/dialog.md' --- # Dialog 弹框 弹出对话框,常用于消息提示、操作确认和输入收集,支持函数式调用。 :::tip 提示 全局调用方案见 [wot-starter](https://starter.wot-ui.cn/guide/feedback.html),可用于路由守卫、请求拦截器等场景。 ::: ## 组件类型 ### Alert 弹框 Alert 仅展示确认按钮,常用于消息通知。 ```html 打开 Alert ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openAlert = () => { dialog.alert({ title: '提示', msg: '操作成功' }) } ``` ### Confirm 弹框 Confirm 通过 `Promise` 返回用户操作结果,`then` 对应确认,`catch` 对应取消。 ```html 打开 Confirm ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openConfirm = () => { dialog .confirm({ title: '提示', msg: '确认执行此操作吗?' }) .then(() => { console.log('点击了确认') }) .catch(() => { console.log('点击了取消') }) } ``` ### Prompt 弹框 Prompt 会展示输入框,可用于采集文本并进行校验。 ```html 打开 Prompt ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openPrompt = () => { dialog .prompt({ title: '请输入邮箱', inputPattern: /.+@.+\..+/i, inputError: '邮箱格式不正确' }) .then((res) => { console.log(res.value) }) } ``` ## 组件状态 ### 确认前校验 `beforeConfirm` 接收当前输入值,支持返回 `boolean` 或 `Promise`,返回 `false` 时会拦截关闭。 ```html 确认前校验 ``` ```ts import { useDialog, useToast } from '@/uni_modules/wot-ui' const dialog = useDialog() const toast = useToast() const openBeforeConfirm = () => { dialog.confirm({ title: '删除确认', msg: '确定删除该记录吗?', beforeConfirm: () => { toast.loading('删除中...') return new Promise((resolve) => { setTimeout(() => { toast.close() resolve(true) }, 1500) }) } }) } ``` ### 输入校验 Prompt 同时支持正则校验 `input-pattern` 与函数校验 `input-validate`。 ```html 输入校验 ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openPromptValidate = () => { dialog.prompt({ title: '请输入手机号', inputProps: { type: 'tel', placeholder: '请输入 11 位手机号' }, inputValidate: (value) => /^1[3-9]\d{9}$/.test(String(value)), inputError: '手机号格式不正确' }) } ``` ## 组件变体 ### 风格与布局 通过 `theme` 与 `action-layout` 控制弹框按钮风格和排列方式。 ```html Text 风格 + 纵向布局 ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openTextTheme = () => { dialog.confirm({ title: '版本更新', msg: '发现新版本,是否立即更新?', theme: 'text', actionLayout: 'vertical' }) } ``` ### 自定义操作按钮 通过 `actions` 可以定义多个按钮。`actions` 与 `confirm-button-props` / `cancel-button-props` 同时配置时优先使用 `actions`。 ```html 自定义操作按钮 ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openActions = () => { dialog.show({ title: '选择支付方式', actionLayout: 'vertical', actions: [ { text: '微信支付', type: 'success', block: true }, { text: '支付宝', type: 'primary', block: true }, { text: '取消', block: true } ] }) } ``` ## 组件样式 ### 图标与头图 可通过 `icon`、`icon-color`、`icon-props`、`header-image` 配置视觉样式。 ```html 图标和头图 ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openStyledDialog = () => { dialog.alert({ title: '活动通知', msg: '恭喜您获得专属权益', icon: 'success', headerImage: 'https://example.com/banner.png' }) } ``` ### 自定义按钮样式 可通过 `confirm-button-props`、`cancel-button-props` 透传按钮属性。 ```html 自定义按钮样式 ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openCustomButtons = () => { dialog.confirm({ title: '提示', msg: '是否继续?', confirmButtonProps: { type: 'success', customClass: 'custom-shadow' }, cancelButtonProps: { type: 'danger', customClass: 'custom-shadow' } }) } ``` ## 特殊样式 ### 插槽 通过 `selector` 区分多个实例,并使用 `useDialog(selector)` 调用指定弹框。 ```html 打开插槽弹框 ``` ```ts import { ref } from 'vue' import { useDialog } from '@/uni_modules/wot-ui' const rate = ref(1) const slotDialog = useDialog('wd-dialog-slot') const openSlotDialog = () => { slotDialog.confirm({ title: '请为我们评分' }) } ``` ### OpenType `confirm-button-props`、`cancel-button-props` 与 `actions` 支持透传按钮开放能力属性(如 `openType`)及对应事件回调。 ```html 获取手机号 ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const dialog = useDialog() const openOpenTypeDialog = () => { dialog.confirm({ title: '获取手机号', confirmButtonProps: { text: '授权获取', openType: 'getPhoneNumber', onGetphonenumber: (detail) => { console.log(detail) } } }) } ``` ## Methods `useDialog()` 返回如下方法: | 方法名称 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | show | 打开弹框 | `string \| DialogOptions` | `Promise` | | alert | 打开 Alert 弹框 | `string \| DialogOptions` | `Promise` | | confirm | 打开 Confirm 弹框 | `string \| DialogOptions` | `Promise` | | prompt | 打开 Prompt 弹框 | `string \| DialogOptions` | `Promise` | | close | 关闭当前弹框 | - | `void` | ## Options | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | title | 标题 | `string` | `''` | | msg | 消息内容 | `string` | `''` | | type | 弹框类型,可选值为 `alert`、`confirm`、`prompt` | `DialogType` | `'alert'` | | theme | 按钮风格,可选值为 `button`、`text` | `DialogTheme` | `'button'` | | zIndex | 弹窗层级 | `number` | `99` | | lazyRender | 弹层内容懒渲染 | `boolean` | `true` | | headerImage | 顶部通栏图片地址 | `string` | - | | icon | 图标名称。可选值为 `success`、`info`、`warning`、`danger`,也可传自定义图标名 | `string` | - | | iconColor | 图标颜色 | `string` | - | | iconProps | 透传 `wd-icon` 的属性 | `Partial` | - | | inputValue | Prompt 输入框初始值 | `string \| number` | - | | inputProps | Prompt 模式下 `wd-input` 属性 | `Partial` | - | | textareaProps | Prompt 模式下 `wd-textarea` 属性 | `Partial` | - | | inputPattern | Prompt 输入正则校验规则 | `RegExp` | - | | inputValidate | Prompt 输入函数校验规则,返回 `boolean` 或错误信息字符串 | `(inputValue: string \| number) => boolean \| string` | - | | inputError | Prompt 校验失败提示文案 | `string` | - | | showErr | 是否展示错误信息 | `boolean` | `false` | | actionLayout | 操作按钮排列方式,可选值为 `horizontal`、`vertical` | `DialogActionLayout` | `'horizontal'` | | showCancelButton | 是否显示取消按钮 | `boolean` | `alert` 为 false,`confirm/prompt` 为 true | | confirmButtonText | 确认按钮文案 | `string` | - | | cancelButtonText | 取消按钮文案 | `string` | - | | confirmButtonProps | 确认按钮高级配置,支持传字符串、对象或 `null` | `DialogBoxButtonOption` | `{}` | | cancelButtonProps | 取消按钮高级配置,支持传字符串、对象或 `null` | `DialogBoxButtonOption` | 由 `showCancelButton` 推导 | | actions | 自定义操作按钮数组,配置后优先级高于确认/取消按钮 | `DialogAction[]` | - | | closeOnClickModal | 是否支持点击遮罩关闭,触发 `fail` 回调,返回 `action` 为 `'modal'` | `boolean` | `false` | | showClose | 是否显示右上角关闭按钮,点击后触发 `fail` 回调,返回 `action` 为 `'close'` | `boolean` | `false` | | beforeConfirm | 确认前拦截函数,返回 `boolean` 或 `Promise` | `DialogBeforeConfirm` | - | ## Attributes `wd-dialog` 组件实例支持以下属性: | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | selector | 指定唯一标识,用于区分页面中的多个实例 | `string` | `''` | | root-portal | 是否脱离页面文档流渲染,用于解决 fixed 失效问题 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Slots | 名称 | 说明 | 参数 | | --- | --- | --- | | header | 自定义头部区域 | - | | image | 自定义图片区域 | - | | title | 自定义标题区域 | `{ icon, title, iconProps }` | | default | 自定义内容区域 | `{ msg, type, inputValue, showErr, inputError }` | | actions | 自定义操作区 | `{ confirm, cancel, close }` | --- --- url: 'https://wot-ui.cn/component/divider.md' --- # Divider 分割线 用于将内容分隔为多个区域。 ## 组件类型 ### 基本使用 默认渲染一条水平分割线。 ```html ``` ### 展示文本 使用默认插槽在分割线中间插入内容。 ```html 展示文本 ``` ## 组件变体 ### 内容位置 通过 `content-position` 指定内容所在位置。 ```html 中间 左侧 右侧 ``` ### 虚线 添加 `dashed` 使分割线渲染为虚线。 ```html 虚线分割 ``` ## 组件样式 ### 自定义渲染内容 使用默认插槽渲染自定义内容。 ```html ``` ### 自定义颜色 设置 `color` 自定义分割线颜色。 ```html 自定义颜色 ``` ## 特殊样式 ### 垂直分割线 添加 `vertical` 使分割线渲染为垂直方向,垂直模式下默认插槽不生效。 ```html 文本 文本 文本 文本 文本 ``` ```css .content { padding: 12rpx 15px; } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | color | 自定义颜色,支持所有合法颜色值 | `string` | - | | content-position | 内容位置,可选值为 `left`、`center`、`right` | `DividerPosition` | `'center'` | | dashed | 是否显示为虚线 | `boolean` | `false` | | vertical | 是否显示为垂直分割线 | `boolean` | `false` | | hairline | 是否显示为 0.5px 细线 | `boolean` | `true` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Slots | 名称 | 说明 | 参数 | | --- | --- | --- | | default | 分割线内容,仅在 `vertical` 为 `false` 时生效 | - | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式类 | --- --- url: 'https://wot-ui.cn/component/drop-menu.md' --- # DropMenu 下拉菜单 向下或向上弹出的菜单列表。 ## 组件类型 ### 基础用法 基础用法需要绑定 `v-model` 和 `options`。 `options` 为对象数组,默认结构为 `{ label, value, tip }`。 因为 `uni-app` 组件无法直接监听组件外部点击,为了在点击页面其他区域时自动关闭下拉菜单,建议结合 `useQueue` 在页面根节点监听点击冒泡并调用 `closeOutside`。 :::warning 提示 如果存在点击外部按钮手动打开 `drop-menu` 的场景,需要在该按钮上添加 `@click.stop`,避免触发 `closeOutside` 后立即关闭。 ::: ```html ``` ```ts import { ref } from 'vue' import { useQueue } from '@/uni_modules/wot-ui' const { closeOutside } = useQueue() const value1 = ref(0) const value2 = ref(0) const option1 = ref([ { label: '全部商品', value: 0 }, { label: '新款商品', value: 1 }, { label: '活动商品', value: 2 } ]) const option2 = ref([ { label: '综合', value: 0 }, { label: '销量', value: 1 }, { label: '上架时间', value: 2 } ]) const handleChange1 = ({ value }: { value: string | number }) => { console.log(value) } const handleChange2 = ({ value }: { value: string | number }) => { console.log(value) } ``` ## 组件状态 ### 禁用菜单 通过 `disabled` 禁用菜单项。 ```html ``` ## 组件变体 ### 向上展开 将 `direction` 设为 `up` 可使菜单向上展开。 ```html ``` ### 异步打开/关闭 `before-toggle` 在菜单打开/关闭前触发,接收 `{ status }`,支持返回 `boolean` 或 `Promise`。 :::warning 提示 `before-toggle` 仅作用于当前 `wd-drop-menu-item`,不能阻止其他菜单项的开关行为。 ::: ```html ``` ```ts import { ref } from 'vue' import { useDialog } from '@/uni_modules/wot-ui' import type { DropMenuItemBeforeToggle } from '@/uni_modules/wot-ui/components/wd-drop-menu-item/types' const dialog = useDialog() const value = ref(0) const option = ref([ { label: '全部商品', value: 0 }, { label: '新款商品', value: 1, tip: '这是补充信息' }, { label: '长筛选项', value: 2 } ]) const handleBeforeToggle: DropMenuItemBeforeToggle = ({ status }) => { return new Promise((resolve) => { dialog .confirm({ title: status ? '异步打开' : '异步关闭', msg: status ? '确定要打开下拉菜单吗' : '确定要关闭下拉菜单吗' }) .then(() => resolve(true)) .catch(() => resolve(false)) }) } ``` ## 组件样式 ### 自定义菜单选项 可以结合布局组件实现筛选栏联动展示。 ```html ``` ### 自定义菜单图标 可通过 `icon` 设置右侧图标,通过 `icon-size` 设置图标尺寸。 ```html ``` ## 特殊样式 ### 自定义菜单内容 通过默认插槽自定义菜单内容;自定义内容场景下,通常通过实例方法 `close` 手动关闭菜单。 ```html 主要按钮 ``` ```ts import { ref } from 'vue' import type { SliderInstance } from '@/uni_modules/wot-ui/components/wd-slider/types' import type { DropMenuItemInstance } from '@/uni_modules/wot-ui/components/wd-drop-menu-item/types' const dropMenu = ref() const slider = ref() const sliderValue = ref(30) const confirm = () => { dropMenu.value?.close() } const handleOpened = () => { slider.value?.initSlider() } ``` ## DropMenu Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | z-index | 弹层层级 | `number` | `12` | | direction | 菜单展开方向,可选值为 `up`、`down` | `DropDirection` | `'down'` | | modal | 是否展示蒙层 | `boolean` | `true` | | close-on-click-modal | 是否点击蒙层时关闭 | `boolean` | `true` | | duration | 菜单展开/收起动画时长,单位 ms | `number` | `200` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## DropMenuItem Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model / modelValue | 当前选中值 | `string \| number` | - | | disabled | 是否禁用菜单 | `boolean` | `false` | | options | 菜单选项列表,默认结构为 `{ label, value, tip }` | `Array>` | `[]` | | icon-name | 选中项图标名称 | `string` | `'check'` | | title | 菜单标题,设置后优先展示标题文案 | `string` | - | | icon | 菜单右侧图标 | `string` | `'caret-down'` | | icon-size | 菜单图标尺寸 | `string \| number` | - | | before-toggle | 菜单开关前拦截函数,接收 `{ status }`,返回 `boolean` 或 `Promise` | `DropMenuItemBeforeToggle` | - | | value-key | 选项值字段名 | `string` | `'value'` | | label-key | 选项文本字段名 | `string` | `'label'` | | tip-key | 选项说明字段名 | `string` | `'tip'` | | custom-popup-class | 自定义下拉 popup 样式类 | `string` | `''` | | custom-popup-style | 自定义下拉 popup 样式 | `string` | `''` | | popup-height | popup 高度,未设置时默认最大高度为 80% | `string` | `''` | | root-portal | 是否脱离页面文档流渲染,用于解决 fixed 失效问题 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## DropMenuItem Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 选中值变化时触发 | `{ value, selectedItem }` | | open | 菜单开始展开时触发 | - | | opened | 菜单展开完成时触发 | - | | close | 菜单开始关闭时触发 | - | | closed | 菜单关闭完成时触发 | - | ## DropMenuItem Methods 通过 `ref` 可获取实例并调用以下方法: | 方法名称 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | getShowPop | 获取当前菜单是否展开 | - | boolean | | open | 打开菜单 | - | void | | close | 关闭菜单 | - | void | | toggle | 切换菜单开关 | - | void | ## DropMenu Slots | 名称 | 说明 | 参数 | | --- | --- | --- | | default | 菜单项容器插槽 | - | ## DropMenuItem Slots | 名称 | 说明 | 参数 | | --- | --- | --- | | default | 自定义菜单内容 | - | --- --- url: 'https://wot-ui.cn/component/empty.md' --- # Empty 缺省提示 一般用于兜底占位展示。 ## 内容形态 设置 `icon` 修改展示缺省图标或图片,默认为 `empty`。支持内置的常见图标名如 `no-result`、`no-wifi`、`no-content`、`no-collection`、`no-comment`、`failpayment`、`no-message`。可设置 `tip` 来控制展示提示文案。 ```html ``` ## 组件样式 ### 自定义大小 通过 `icon-size` 属性自定义图标或图片的大小,默认单位为 `px`。 ```html ``` ## 特殊样式 ### 自定义图片 需要自定义外部图片时,可以直接在 `icon` 属性中传入完整的图片 URL。 ```html ``` ### 自定义图片内容 使用 `image` 插槽可以完全自定义图标或图片位置的渲染内容。 ```html ``` ### 自定义底部内容 使用 `bottom` 插槽可以在提示文本底部渲染自定义内容(如操作交互按钮)。建议在插槽内部包裹一层容器以便于控制与上方内容的间距。 ```html ``` 建议样式(可在页面或全局样式中添加): ```css .bottom-actions { margin-top: 20px; display: flex; justify-content: center; width: 100%; } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | icon | 缺省图标名称或图片 URL | string | `empty` | | icon-size | 图标或图片大小,默认单位为 px | string / number | - | | tip | 提示文案 | string | - | ## Slots | name | 说明 | | --- | --- | | image | 自定义图片区域内容 | | bottom | 自定义底部内容 | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | | custom-style | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/fab.md' --- # Fab 悬浮按钮 悬浮动作按钮组件,按下可显示一组动作按钮。 :::warning 因为 `uni-app` 组件无法监听点击自己以外的地方,为了在点击页面其他地方时,可以自动关闭 `fab` ,建议使用组件库的 `useQueue` hook(会关闭所有 dropmenu、popover、toast、swipeAction、fab),在页面的根元素上监听点击事件的冒泡。 如果存在用户手动点击 `fab` 以外某个地方如按钮滑出 `fab` 的场景,则需要在点击的元素(在这里是按钮)加上 `@click.stop=""` 阻止事件冒泡到根元素上,避免触发 `closeOutside` 把要手动打开的 `fab` 关闭了。 ::: ## 组件类型 ### 基本用法 通过 `type` 设置悬浮按钮触发器的类型,`disabled` 设置悬浮按钮是否禁用。 ::: code-group ```html [vue/html] ``` ```ts [typescript] import { ref } from 'vue' import { useToast } from '@/uni_modules/wot-ui' import type { FabType } from '@/uni_modules/wot-ui/components/wd-fab/types' const { show: showToast } = useToast() const type = ref('primary') ``` ```scss [scss] :deep(.custom-button) { min-width: auto !important; box-sizing: border-box; width: 32px !important; height: 32px !important; border-radius: 16px !important; margin: 8rpx; } ``` ::: ## 组件变体 ### 位置与方向 通过 `position` 设置悬浮按钮触发器的位置,`direction` 设置动作按钮的打开方向。 ::: code-group ```html [vue/html] ``` ```ts [typescript] import { ref } from 'vue' import { useToast } from '@/uni_modules/wot-ui' import type { FabPosition, FabDirection } from '@/uni_modules/wot-ui/components/wd-fab/types' const { show: showToast } = useToast() const position = ref('left-bottom') const direction = ref('top') ``` ::: ## 组件状态 ### 动作菜单展开/收起 通过 `v-model:active` 控制动作按钮菜单的展开/收起。 ::: code-group ```html [vue/html] 切换展示 ``` ```ts [typescript] import { ref } from 'vue' const active = ref(false) ``` ::: ### 可拖动按钮 设置 `draggable` 属性为 `true` 开启按钮拖动能力。 ::: code-group ```html [vue/html] ``` ::: :::warning 开启拖动后 `direction` 属性将失效,会根据拖动后的位置自动计算弹出方向。拖动完成后按钮将会自动吸边。 ::: ## 特殊样式 ### 自定义触发器 通过 `trigger` 插槽自定义触发器,`expandable` 控制点击触发器是否触发默认内部的展开/收起能力。 ::: code-group ```html [vue/html] ``` ```ts [typescript] import { useToast } from '@/uni_modules/wot-ui' const { show: showToast } = useToast() const handleClick = () => { showToast('分享给朋友') } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model:active | 是否激活 | `boolean` | `false` | | type | 悬浮按钮类型,可选值为 `primary`、`success`、`info`、`warning`、`danger` | `FabType` | `'primary'` | | position | 悬浮按钮位置,可选值为 `left-top`、`right-top`、`left-bottom`、`right-bottom`、`left-center`、`right-center`、`top-center`、`bottom-center` | `FabPosition` | `'right-bottom'` | | draggable | 按钮能否拖动 | `boolean` | `false` | | direction | 悬浮按钮菜单弹出方向,可选值为 `top`、`right`、`bottom`、`left` | `FabDirection` | `'top'` | | disabled | 是否禁用 | `boolean` | `false` | | inactive-icon | 悬浮按钮未展开时的图标 | `string` | `'plus'` | | active-icon | 悬浮按钮展开时的图标 | `string` | `'close'` | | z-index | 自定义悬浮按钮层级 | `number` | `99` | | gap | 自定义悬浮按钮与可视区域边缘的间距 | `FabGap` | `{ top: 16, right: 16, bottom: 16, left: 16 }` | | expandable | 用于控制点击时是否展开菜单,设置为 `false` 时触发 `click` 事件 | `boolean` | `true` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ### FabGap | 参数 | 说明 | 类型 | | --- | --- | --- | | top | 距离顶部间距 | number | | bottom | 距离底部间距 | number | | left | 距离左边间距 | number | | right | 距离右边间距 | number | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | `expandable` 设置为 `false` 时,点击悬浮组件内部但不触发内部逻辑时则抛出版事件 | - | ## Methods | 方法名 | 说明 | 参数 | | --- | --- | --- | | open | 展开菜单 | - | | close | 收起菜单 | - | ## Slots | name | 说明 | | --- | --- | | default | 动作按钮区域内容 | | trigger | 触发器插槽,用于完全自定义点击触发锚点区域 | --- --- url: 'https://wot-ui.cn/component/floating-panel.md' --- # FloatingPanel 浮动面板 浮动在页面底部的面板,用户可以通过上下拖动秒板来浏览内容,从而在不离开当前视图的情况下访问更多信息,常用于地图导航。 ## 组件类型 ### 基础用法 FloatingPanel 的初始高度会取 `anchors[0]` 的值,也就是 `100px`,用户可以拖动来展开面板,使高度达到 `60%` 的屏幕高度。 ::: code-group ```html [vue/html] ``` ```ts [typescript] import { ref } from 'vue' const data = ref(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']) ``` ::: ## 组件变体 ### 自定义锚点 你可以通过 `anchors` 属性来设置 FloatingPanel 的锚点位置,并通过 `v-model:height` 来控制当前面板的显示高度。 比如,使面板的高度在 `100px`、`40%` 屏幕高度和 `70%` 屏幕高度三个位置停靠: ::: code-group ```html [vue/html] 自定义锚点 {{ anchors }} - {{ height.toFixed(0) }} ``` ```ts [typescript] import { ref } from 'vue' import { onLoad } from '@dcloudio/uni-app' const height = ref(0) const windowHeight = ref(0) const anchors = ref([]) const handleHeightChange = ({ height }: { height: number }) => { console.log(height) } onLoad(() => { windowHeight.value = uni.getSystemInfoSync().windowHeight anchors.value = [100, Math.round(0.4 * windowHeight.value), Math.round(0.7 * windowHeight.value)] height.value = anchors.value[1] }) ``` ```css [css] .inner-content { padding: 1rem; text-align: center; font-size: 16px; font-weight: bold; } ``` ::: ## 组件状态 ### 仅头部拖拽 默认情况下,FloatingPanel 的头部区域和内容区域都可以被拖拽,你可以通过 `contentDraggable` 属性来禁用内容区域的拖拽。 ::: code-group ```html [vue/html] 内容区不可以拖拽 ``` ```css [css] .inner-content { padding: 1rem; text-align: center; font-size: 16px; font-weight: bold; } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model:height | 当前面板的显示高度 | `number` | `0` | | anchors | 设置自定义锚点, 单位 `px` | `number[]` | `[100, windowHeight * 0.6]` | | duration | 动画时长,单位 `ms`,设置为 `0` 可以禁用动画 | `number` | `300` | | content-draggable | 允许拖拽内容容器 | `boolean` | `true` | | safe-area-inset-bottom | 是否开启底部安全区适配 | `boolean` | `false` | | show-scrollbar | 是否开启滚动条 | `boolean` | `true` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Slots | 名称 | 说明 | | ---- | -------- | | default | 默认内容区域插槽 | ## Events | 方法名 | 说明 | 参数 | | --- | --- | --- | | heightChange | 面板显示高度改变且结束拖动后触发 | `{ height: number }` | --- --- url: 'https://wot-ui.cn/component/form.md' --- # Form 表单 用于数据录入、校验,支持输入框、单选框、复选框、文件上传等类型。 表单采用 `wd-form` 和 `wd-form-item` 的结构。`wd-form-item` 内部继承了 `wd-cell` 的布局能力,负责展示标题描述和承载校验提示。各种输入组件(如 `Input`、`Textarea`、`Picker`、`Switch`、`Upload` 等)只需直接放入 `wd-form-item` 的默认插槽中即可。 结合 `wd-form` 组件,可以实现对内部组件的规则校验。如果需要让表单项之间有清晰的边框线分隔,你可以直接在 `wd-form` 上开启 `border` 属性。 :::tip 温馨提示 `wd-form-item` 与 `input` 和 `textarea` 结合使用时,会自动开启 `input` 和 `textarea` 的 `compact` 属性 ::: ## 校验引擎说明 表单组件默认采用接口式校验方案,你可以根据 `FormSchema` 的结构自己编写校验逻辑,详见后文的[自定义校验引擎](#自定义校验引擎)。 同时,我们推荐使用 [Zod](https://zod.dev/) 作为表单校验引擎。Zod 是一个以 TypeScript 为首的模式声明和验证库,你可以非常方便地通过 `z.object()` 等声明组合来构建你的表单验证规则。 ### Zod 安装 \~~内置了嫌组件库大,不内置又说安装麻烦,真想吊起来这种人来打。~~ 出于组件库体积的考虑,我们不内置 Zod,所以在使用 Zod 前,你需要先将其安装到你的项目中: ::: code-group ```bash [npm] npm install zod ``` ```bash [yarn] yarn add zod ``` ```bash [pnpm] pnpm add zod ``` ::: ### 结合 zodAdapter 使用 组件库内置了 `zodAdapter` 适配器,你可以直接通过它将 `Zod` 的 schema 转化为组件能够识别的校验规则: ```ts import { z } from 'zod' import { zodAdapter } from '@/uni_modules/wot-ui' // 通过 zodAdapter 转换 zod 的模式对象 const schema = zodAdapter( z.object({ username: z.string().min(1, '请填写用户名'), password: z.string().min(6, '密码至少为6位') }) ) ``` ## 自定义校验引擎 如果你不想使用 Zod,你也可以直接编写一个符合 `FormSchema` 结构的校验对象,实现自定义的表单校验引擎。 自定义校验引擎需要提供 `validate` 函数,其接收整个表单数据 `model`,并返回(或异步返回)包含 `path` 和 `message` 字段的错误问题数组。 如果需要控制必填星号(`*`)的显示,你还可以提供 `isRequired` 方法: ```ts import type { FormSchema } from '@/uni_modules/wot-ui/components/wd-form/types' const customSchema: FormSchema = { // 校验逻辑 validate(formModel) { const issues = [] if (!formModel.username) { issues.push({ path: ['username'], message: '请填写用户名' }) } if (!formModel.password || formModel.password.length < 6) { issues.push({ path: ['password'], message: '密码至少为6位' }) } return issues }, // 用于推导必填星号 isRequired(path: string) { return path === 'username' || path === 'password' } } ``` ## 组件类型 ### 基础用法 在表单中,使用 `model` 指定表单数据对象,每个 `表单项组件` 代表一个表单项,使用 `prop` 指定表单项字段,使用 `schema` 属性定义校验规则。 ::: details 查看基础用法示例 ::: code-group ```html [vue] 提交 ``` ```typescript [typescript] ``` ```css [css] .footer { padding: 16px; } ``` ::: ## 组件配置 ### 校验错误提示方式 1. `message`:默认为输入框下方用文字进行提示 2. `toast`:以"toast"提示的方式弹出错误信息,每次只弹出最前面的那个表单域的错误信息 3. `none`:不会进行任何提示 ::: details 错误提示方式 ::: code-group ```html [vue] toast message none 提交 ``` ```typescript [typescript] ``` ```css [css] .footer { padding: 16px; } :deep(.group) { &:not(:first-child) { margin-top: 12px; } } ``` ::: ### 隐藏字段校验 当表单项通过 `v-if` 隐藏时,对应的 `wd-form-item` 会被卸载。表单校验会根据当前已挂载的 `wd-form-item` 过滤校验结果,因此隐藏字段即使仍然存在于 `schema` 中,也不会影响 `validate()` 返回的 `valid` 和 `errors`。 如果字段重新显示,它会重新参与表单校验。对于仅使用样式隐藏但组件仍然挂载的表单项,校验行为不会被跳过。 ::: details 隐藏字段校验 ::: code-group ```html [vue] 提交 ``` ```typescript [typescript] ``` ```css [css] .footer { padding: 16px; } ``` ::: ### 动态表单 表单项动态增减。 ::: details 查看动态表单示例 ::: code-group ```html [vue] 添加 删除 重置 提交 ``` ```typescript [typescript] ``` ```css [css] .footer { text-align: left; :deep(.wd-button) { &:not(:last-child) { margin-right: 12px; } } } ``` ::: #### 校验触发时机 通过配置 `validate-trigger` 可以指定校验触发时机,可选值为 `change`、`blur`、`submit`。可以在 `wd-form` 上配置全局触发时机,也可以在 `wd-form-item` 上配置覆盖全局设置。 ::: details 校验触发时机 ::: code-group ```html [vue] 表单级 change,字段覆盖:blur/change/submit 提交并校验 ``` ```typescript [typescript] ``` ```css [css] .footer { padding: 16px; } .tip-text { color: #666; font-size: 14px; } :deep(.group) { &:not(:first-child) { margin-top: 12px; } } ``` ::: ## 指定字段校验 `validate` 方法可以传入一个 `prop` 参数,指定校验的字段,可以实现在表单组件的`blur`、`change`等事件触发时对该字段的校验。`prop` 参数也可以是一个字段数组,指定多个字段进行校验。 ::: details 查看指定字段校验示例 ::: code-group ```html [vue] 提交 校验用户名和密码 ``` ```typescript [typescript] ``` ```css [css] .footer { padding: 12px; } ``` ::: ### 复杂表单 结合`Input 输入框`、`Textarea 输入框`、`Picker 选择器`、 `Calendar 日历选择器`、 `Cascader 级联选择器`、`SelectPicker 单复选选择器`、`Cell 单元格` 和 `DatetimePicker 日期时间选择器`实现一个复杂表单。 ::: details 查看复杂表单示例 ::: code-group ```html [vue/html] {{ isVerticalLayout ? '上下布局' : '左右布局' }} 新品 爆款 清仓 已阅读并同意 《巴拉巴拉吧啦协议》 提交 ``` ```ts [typescript] ``` ```css [css] .inline-txt { display: inline-block; font-size: 14px; margin: 0 8px; color: rgba(0, 0, 0, 0.45); vertical-align: middle; } :deep(.group) { &:not(:first-child) { margin-top: 12px; } } .tip { margin: 12px 0 12px; color: #999; font-size: 12px; } .footer { padding: 0 24px 20px; } .layout-tip { margin-left: 8px; color: #666; font-size: 14px; } :deep(.label-class) { color: #999 !important; font-size: 12px !important; } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | ------------- | ----------------------------------------------------------------------------------- | --------------------- | --------- | | model | 表单数据对象 | `Record` | - | | schema | 表单校验对象 | `FormSchema` | - | | validate-trigger | 校验触发时机,可选值为 `change`、`blur`、`submit` | `string \| string[]` | `submit` | | reset-on-change | 表单数据变化时是否重置表单提示信息(设置为 `false` 时需要开发者单独对变更项进行校验) | `boolean` | `true` | | error-type | 校验错误提示方式,可选值为 `toast`、`message`、`none` | `string` | `message` | | border | 是否展示边框线 | `boolean` | `false` | | center | 是否使内容垂直居中 | `boolean` | `false` | | size | 单元格大小,可选值为 `large` | `string` | - | | title-width | 左侧标题宽度 | `string \| number` | - | | layout | 单元格布局方式,可选值为 `horizontal`、`vertical` | `string` | - | | value-align | 右侧内容对齐方式,可选值为 `left`、`right`、`center` | `string` | - | | asterisk-position | 必填星号位置,可选值为 `start`、`end` | `string` | - | | hide-asterisk | 是否隐藏必填星号 | `boolean` | `false` | | ellipsis | 是否超出隐藏显示省略号 | `boolean` | `false` | ## Methods | 方法名称 | 说明 | 参数 | 返回值 | | -------- | ------------------------------------------------------------------------------ | --------------- | --------------- | | validate | 验证表单,支持传入一个 prop 来验证单个表单项,不传入 prop 时,会验证所有表单项,1.6.0 版本起支持传入数组 | `prop?: string \| string[]` | `Promise<{ valid: boolean, errors: ErrorMessage[] }>` | | reset | 重置表单项的验证提示 | - | - | ### FormItem Attributes 该组件的所有属性除了支持特定表单项配置外,同时也继承自 `Form` 组件的公共配置(如 `border`、`center`、`size`、`title-width` 等)。 | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | prop | 表单域 model 字段名 | `string` | - | | title | 标题 | `string` | - | | value | 右侧展示值,用于配合 placeholder 判断是否显示占位文字 | `string \| number` | - | | placeholder | 值为空时显示的占位文字,需与 value 配合使用 | `string` | - | | prefix-icon | 前置图标类名 | `string` | - | | icon-size | 图标大小 | `string \| number` | - | | icon-prefix | 类名前缀,用于使用自定义图标 | `string` | - | | label | 描述信息 | `string` | - | | clickable | 是否开启点击反馈 | `boolean` | `false` | | is-link | 是否展示右侧箭头并开启点击反馈 | `boolean` | `false` | | size | 单元格大小,可选值为 `large`,优先使用自身配置,未设置时继承 Form | `string` | - | | border | 是否展示边框线,优先使用自身配置,未设置时继承 Form | `boolean` | - | | title-width | 左侧标题宽度,优先使用自身配置,未设置时继承 Form | `string \| number` | `98px` | | center | 是否使内容垂直居中,优先使用自身配置,未设置时继承 Form | `boolean` | - | | required | 是否必填 | `boolean` | - | | validate-trigger | 校验触发时机,可选值为 `change`、`blur`、`submit` | `string \| string[]` | - | | layout | 单元格布局方式,可选值为 `horizontal`、`vertical`,优先使用自身配置,未设置时继承 Form | `string` | `horizontal` | | value-align | 右侧内容对齐方式,可选值为 `left`、`right`、`center`,优先使用自身配置,未设置时继承 Form | `string` | `left` | | ellipsis | 是否超出隐藏显示省略号,优先使用自身配置,未设置时继承 Form | `boolean` | - | | asterisk-position | 必填星号位置,可选值为 `start`、`end`,优先使用自身配置,未设置时继承 Form | `string` | `start` | | hide-asterisk | 是否隐藏必填星号,优先使用自身配置,未设置时继承 Form | `boolean` | - | ### FormSchema 数据结构 | 键名 | 说明 | 类型 | | ---------- | ------------------------------ | ------------------------------------------------------------- | | validate | 校验函数,返回问题数组 | `(model) => FormSchemaIssue[] \| Promise` | | isRequired | 可选,用于推导必填星号 | `(path: string) => boolean \| undefined` | ## FormItem Events | 事件名称 | 说明 | 参数 | | -------- | ------------------------------------------------------------------------------ | --------------- | | click | 点击表单项时触发 | - | ## 外部样式类 ### FormItem 外部样式类 | 类名 | 说明 | | ------------ | ---------- | | custom-class | 根节点样式 | | custom-prefix-class | 前置图标自定义样式类 | | custom-label-class | label 使用 slot 时的自定义样式 | | custom-value-class | value 使用 slot 时的自定义样式 | | custom-title-class | title 使用 slot 时的自定义样式 | --- --- url: 'https://wot-ui.cn/component/gap.md' --- # Gap 间隔槽 用于页面布局中的间距占位,可替代 `margin` 或 `padding`,也可作为底部占位元素。 ## 组件类型 ### 基本使用 默认渲染一个高度为 `14px`、背景为透明色的间隔槽。 ```html ``` ## 组件变体 ### 自定义背景色 通过 `bg-color` 设置背景颜色。 ```html ``` ### 自定义高度 通过 `height` 设置高度,支持数字和带单位字符串。 ```html ``` ## 组件样式 ### 自定义类名 通过 `custom-class` 扩展样式。 ```html ``` ```css .custom-gap { padding-bottom: 120rpx; background: #34d19d !important; } ``` ## 特殊样式 ### 底部安全区 开启 `safe-area-bottom` 后会自动追加底部安全区内边距,适合底部固定占位场景。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | height | 间隔槽高度,支持数字(单位 `px`)或字符串(如 `20rpx`) | `string \| number` | `14` | | bg-color | 背景颜色 | `string` | `'transparent'` | | safe-area-bottom | 是否开启底部安全区适配 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | --- --- url: 'https://wot-ui.cn/component/grid.md' --- # Grid 宫格 宫格可以在水平方向上把页面分隔成等宽度的区块,用于展示内容或进行页面导航。 ## 组件类型 ### 基础用法 基础用法需要通过 `icon` 指定图标名称以及 `text` 属性指定文字。默认显示为一行。 ```html ``` ### 内容插槽 通过 `wd-grid-item` 的默认插槽可以自定义宫格内容。 ```html ``` ```scss .img { width: 100%; height: 90px; } ``` ## 组件变体 ### 自定义列数 通过 `column` 属性可以自定义宫格列数。未定义该属性时,默认显示为一行。 ```html ``` ### 正方形格子 通过 `square` 属性开启正方形格属性。此时每一个 `GridItem` 宽高相等。 > 注意:开启 `square` 后,不建议再通过样式自定义 `GridItem` 的高度。 ```html ``` ## 组件样式 ### 自定义背景颜色 通过 `bg-color` 属性可以自定义宫格背景颜色。 ```html ``` ### 开启边框 通过 `border` 属性可以开启边框线展示。 ```html ``` ### 设定格间隙 通过 `gutter` 属性设置格子之间的距离。 ```html ``` ### 提示信息 设置 `is-dot` 属性后,会在图标右上角展示一个小红点。也可通过 `value`、`max` 设置徽标显示内容。 ```html ``` ## 布局能力 ### 横向布局 通过 `direction` 属性可以设置内容的排列方向,默认为 `vertical`(纵向),可设置为 `horizontal`(横向)。配合 `reverse` 属性可以调换图标和文本的位置。 ```html ``` ## 特殊样式 ### 图标插槽 通过具名插槽 `icon` 可以自定义图标位的内容。 ```html ``` ### 文字插槽 通过具名插槽 `text` 可以自定义文字位的内容。 ```html ``` ### 自定义样式 通过 `custom-class` 或外部样式类可以深度定制样式。如果文字过长想单行显示并使用省略号,可以设置 `ellipsis` 为 `true`。 ```html ``` ```scss :deep(.custom-item) { color: #e2231a; text-align: left !important; } ``` ### 页面导航 通过 `clickable` 属性开启可点击状态,并通过 `url` 和 `link-type` 属性设置页面跳转。 ```html ``` ## Grid Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | column | 列数 | `number` | - | | border | 是否显示边框 | `boolean` | `false` | | gutter | 格子之间的间距,默认单位为 `px` | `number` | - | | square | 是否将格子固定为正方形 | `boolean` | `false` | | clickable | 是否开启格子点击反馈 | `boolean` | `false` | | bg-color | 背景颜色设置 | `string` | - | | hover-class | 指定 grid-item 按下去的样式类 | `string` | `'wd-grid-item__content--hover'` | | center | 是否将格子内容居中显示 | `boolean` | `true` | | direction | 格子内容排列的方向,可选值为 `horizontal`、`vertical` | `string` | `'vertical'` | | reverse | 是否调换图标和文本的位置 | `boolean` | `false` | | icon-size | 图标大小,默认单位为 `px` | `string` | `'28px'` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## GridItem Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | text | 文字内容 | `string` | - | | ellipsis | 是否超出隐藏显示省略号 | `boolean` | `false` | | icon | 图标名称,可选值见 `wd-icon` 组件 | `string` | - | | icon-color | 图标颜色 | `string` | - | | icon-prefix | 图标类名前缀 | `string` | - | | is-dot | 是否显示图标右上角小红点 | `boolean` | `false` | | value | 图标右上角徽标显示值 | `string \| number` | - | | max | 图标右上角徽标最大值,超过最大值会显示 `{max}+` | `number` | `99` | | badge-props | 自定义徽标属性,透传给 [Badge 组件](/component/badge#attributes) | `BadgeProps` | - | | url | 点击后跳转的链接地址 | `string` | - | | link-type | 页面跳转方式,可选值为 `navigateTo`、`switchTab`、`reLaunch`、`redirectTo` | `string` | `'navigateTo'` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## GridItem Events | 方法名 | 说明 | 参数 | | --- | --- | --- | | click | 点击(跳转)事件 | - | ## Grid Slot | name | 说明 | | --- | --- | | default | 宫格内容 | ## GridItem Slot | name | 说明 | | --- | --- | | default | 宫格项默认内容(自定义全部内容) | | icon | 图标位内容 | | text | 文本位内容 | ## Grid 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | ## GridItem 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | | custom-text | 文字样式 | | custom-icon | 图标样式 | --- --- url: 'https://wot-ui.cn/component/icon.md' --- # Icon 图标 基于字体的图标集。 ## 组件类型 ### 基础用法 通过 `name` 属性设置使用哪个图标。 ```html ``` ## 组件样式 ### 图标颜色 设置 `color` 属性。 ```html ``` ### 图标大小 设置 `size` 属性。 ```html ``` ## 特殊样式 ### 自定义图标 如果需要在现有 Icon 的基础上使用更多图标,可以引入第三方 iconfont 对应的字体文件和 CSS 文件,之后就可以在 Icon 组件中直接使用。 ```css /* 路径 src/iconfont/index.css */ @font-face { font-family: "fish"; src: url('//at.alicdn.com/t/c/font_4626013_vwpx4thmin.woff2?t=1721314121733') format('woff2'), url('//at.alicdn.com/t/c/font_4626013_vwpx4thmin.woff?t=1721314121733') format('woff'), url('//at.alicdn.com/t/c/font_4626013_vwpx4thmin.ttf?t=1721314121733') format('truetype'); } .fish { font-family: "fish" !important; font-size: 16px; font-style: normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .fish-kehuishouwu:before { content: "\e627"; } ``` ```html ``` ```html ``` ### CSS 类名图标 (UnoCSS) 如果项目中使用了 [UnoCSS](https://unocss.dev/) 等 CSS 引擎,你可以通过设置 `css-icon` 为 `true`,此时传入的 `name` 会直接被作为 CSS 类名使用,而不会拼接任何前缀。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | name | 图标名称或图片链接 | `string` | - | | color | 图标的颜色 | `string` | `inherit` | | size | 图标的字体大小 | `string \| number` | `inherit` | | class-prefix | 类名前缀,用于使用自定义图标 | `string` | `wd-icon` | | css-icon | CSS 图标,为 `true` 时 `name` 直接作为 CSS class 而不会拼接 `class-prefix` 前缀,也可以直接传图标类名 | `boolean \| string` | `false` | | custom-style | 根节点样式 | `string` | - | | custom-class | 根节点样式 | `string` | - | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 点击图标时触发 | `event` | --- --- url: 'https://wot-ui.cn/component/image-preview.md' --- # ImagePreview 图片预览 图片预览组件,支持多图预览、滑动切换和函数式调用。 ## 组件类型 ### useImagePreview `useImagePreview` 用于函数式调用 `wd-image-preview`。调用前需要先在页面中声明一个 `wd-image-preview` 实例。 ### 基本用法 通过 `useImagePreview` 函数式调用打开图片预览。 ```html 预览图片 ``` ```typescript import { useImagePreview } from '@wot-ui/ui' const { previewImage } = useImagePreview() function handlePreview() { previewImage({ images: [ 'https://example.com/image1.jpg', 'https://example.com/image2.jpg', 'https://example.com/image3.jpg' ] }) } ``` ### 传入图片数组 可以直接传入图片 URL 数组,简化调用方式。 ```typescript previewImage([ 'https://example.com/image1.jpg', 'https://example.com/image2.jpg' ]) ``` ## 组件变体 ### 指定起始位置 通过 `startPosition` 指定预览时的起始位置(从 0 开始)。 ```typescript previewImage({ images: ['url1', 'url2', 'url3'], startPosition: 1 // 从第二张图片开始预览 }) ``` ## 组件配置 ### 隐藏页码 通过 `showIndex` 属性控制是否显示页码。 ```typescript previewImage({ images: ['url1', 'url2'], showIndex: false }) ``` ### 隐藏关闭按钮 通过 `closeable` 控制是否显示关闭按钮。 ```typescript previewImage({ images: ['url1', 'url2'], closeable: false }) ``` ### 关闭按钮位置 通过 `closeIconPosition` 控制按钮位置。 ```typescript previewImage({ images: ['url1', 'url2'], closeIconPosition: 'top-left' // 或 'top-right' }) ``` ### 禁用点击关闭 通过 `closeOnClick` 控制是否点击图片或遮罩时关闭。 ```typescript previewImage({ images: ['url1', 'url2'], closeOnClick: false }) ``` ### 禁用循环 通过 `loop` 属性禁用循环播放。 ```typescript previewImage({ images: ['url1', 'url2'], loop: false }) ``` ## 特殊用法 ### 监听事件 通过回调函数监听预览事件。 ```typescript import { useImagePreview } from '@wot-ui/ui' const { previewImage, closeImagePreview } = useImagePreview() previewImage({ images: ['url1', 'url2'], onOpen: () => { console.log('预览已打开') }, onClose: () => { console.log('预览已关闭') }, onChange: (index) => { console.log('当前图片索引:', index) } }) function handleClose() { closeImagePreview() } ``` ### 使用插槽 可以通过具名插槽自定义指示器或底部内容。若页面中存在多个实例,需要通过 `selector` 区分,并在 `useImagePreview(selector)` 中传入相同标识。 ```html 自定义插槽 ``` ```typescript import { useImagePreview } from '@wot-ui/ui' const { previewImage } = useImagePreview('slot-preview') const images = [ 'https://wot-ui.cn/assets/redpanda.jpg', 'https://wot-ui.cn/assets/capybara.jpg' ] const imageDescriptions = ['小熊猫', '水豚'] function handleSlotPreview() { previewImage({ images, showIndex: false // 隐藏默认指示器 }) } ``` ### 组件式调用 也可以通过组件的方式使用,并通过 ref 控制。 ```html 预览 ``` ```typescript import { ref } from 'vue' import type { ImagePreviewInstance } from '@wot-ui/ui' const imagePreviewRef = ref() const images = ref([ 'https://example.com/image1.jpg', 'https://example.com/image2.jpg' ]) function openPreview() { imagePreviewRef.value?.open() } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | selector | 选择器 | `string` | - | | images | 图片 URL 数组 | `string[]` | `[]` | | start-position | 起始位置索引 | `number` | `0` | | show-index | 是否显示页码 | `boolean` | `true` | | loop | 是否循环播放 | `boolean` | `true` | | closeable | 是否显示关闭按钮 | `boolean` | `true` | | close-icon | 关闭图标名称 | `string` | `close` | | close-icon-position | 关闭图标位置,可选值为 `top-left`、`top-right` | `string` | `top-right` | | close-on-click | 是否点击图片或遮罩时关闭 | `boolean` | `true` | | show-menu-by-longpress | 开启长按图片显示识别小程序码菜单 | `boolean` | `true` | | z-index | 层级 | `number` | `1000` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | open | 打开预览时触发 | - | | close | 关闭预览时触发 | - | | change | 切换图片时触发 | `{ index: number }` | | long-press | 长按图片时触发 | `{ image: string }` | ## Methods 通过 ref 调用组件实例方法。 | 方法名 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | open | 打开图片预览 | `options?: ImagePreviewOptions \| string[]` | - | | close | 关闭图片预览 | - | - | | setActive | 切换到指定图片 | `index: number` | - | ## Slots | name | 说明 | | --- | --- | | default | 底部自定义内容,参数为 `{ current: number }` | | indicator | 自定义指示器,参数为 `{ current: number, total: number }` | ## 外部样式类 | 类名 | 说明 | 最低版本 | |------|------|----------| | custom-class | 根节点样式类 | - | ## CSS 变量 | 变量名 | 说明 | 默认值 | |--------|------|--------| | --wot-image-preview-bg | 背景颜色 | `rgba(0, 0, 0, 0.9)` | | --wot-image-preview-index-color | 页码颜色 | `#fff` | | --wot-image-preview-index-font-size | 页码字号 | `15px` | | --wot-image-preview-close-size | 关闭按钮尺寸 | `44px` | | --wot-image-preview-close-margin | 关闭按钮边距 | `12px` | --- --- url: 'https://wot-ui.cn/component/img.md' --- # Img 图片 增强版图片组件,支持填充模式、懒加载、加载态/失败态插槽,以及点击预览。 ## 组件类型 ### 基本用法 基础用法与原生 `image` 标签一致,可以设置 `src`、`width`、`height` 等属性。 使用本地资源时,建议通过文件导入方式传入 `src`。在微信小程序中,`image` 标签支持二进制数据和 base64 编码,单独使用导入路径时需要结合构建配置处理。 ```html ``` ```typescript import blackMao from './black_mao.png' const imgURL = blackMao ``` :::tip 提示 可以配置 `transformAssetUrls`,让 `wd-img` 的 `src` 属性获得与原生 `image` 一致的资源转换体验。 ```typescript import uni from '@dcloudio/vite-plugin-uni' import { defineConfig } from 'vite' export default defineConfig({ plugins: [ uni({ vueOptions: { template: { transformAssetUrls: { tags: { 'wd-img': ['src'] } } } } }) ] }) ``` 修改完成后重启开发服务即可生效,更多背景可参考 [uni-app issue#4997](https://github.com/dcloudio/uni-app/issues/4997#issuecomment-2456851123)。 ::: ## 组件状态 ### 加载中提示 图片加载时会显示默认占位内容,也可以通过 `loading` 插槽自定义加载态。若不希望显示默认加载态,可将 `show-loading` 设为 `false`。 ```html ``` ### 加载失败提示 图片加载失败时会显示默认占位内容,也可以通过 `error` 插槽自定义失败态。若不希望显示默认失败态,可将 `show-error` 设为 `false`。 ```html ``` ```css .error-wrap { width: 100%; height: 100%; background-color: red; color: white; line-height: 100px; text-align: center; } ``` ## 组件样式 ### 填充模式 通过 `mode` 设置图片填充模式。可选值为 `top left`、`top right`、`bottom left`、`bottom right`、`right`、`left`、`center`、`bottom`、`top`、`heightFix`、`widthFix`、`scaleToFill`、`aspectFit`、`aspectFill`。 ```html ``` ### 圆形 通过 `round` 将图片显示为圆形。 ```html ``` ### 圆角 通过 `radius` 设置图片圆角,默认单位为 `px`。 ```html ``` ## 特殊用法 ### 可预览 通过 `enable-preview` 开启点击预览,内部调用 `uni.previewImage` 实现。组件仅在图片加载成功后才会触发预览。 ```html ``` ### 指定预览图片 通过 `preview-src` 指定预览时展示的图片,可与组件当前显示的图片不同。 ```html ``` ```typescript import blackMao from './black_mao.png' import blackMaoPreview from './black_mao_1.png' const imgURL = blackMao const previewURL = blackMaoPreview ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | src | 图片链接 | `string` | - | | preview-src | 预览图片链接 | `string` | - | | width | 宽度,支持数字(单位 `px`)或字符串 | `string \| number` | - | | height | 高度,支持数字(单位 `px`)或字符串 | `string \| number` | - | | mode | 填充模式,可选值为 `top left`、`top right`、`bottom left`、`bottom right`、`right`、`left`、`center`、`bottom`、`top`、`heightFix`、`widthFix`、`scaleToFill`、`aspectFit`、`aspectFill` | `ImageMode` | `scaleToFill` | | round | 是否显示为圆形 | `boolean` | `false` | | radius | 圆角大小,默认单位为 `px` | `string \| number` | - | | lazy-load | 是否开启图片懒加载 | `boolean` | `false` | | enable-preview | 是否支持点击预览 | `boolean` | `false` | | show-menu-by-longpress | 是否开启长按图片显示识别小程序码菜单,仅微信小程序平台有效 | `boolean` | `false` | | show-loading | 是否展示默认加载态 | `boolean` | `true` | | show-error | 是否展示默认失败态 | `boolean` | `true` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | | custom-image | 内部 `image` 节点自定义类名 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 点击图片时触发 | `event: MouseEvent` | | load | 图片加载完成时触发,返回图片加载事件对象 | `event: Event` | | error | 图片加载失败时触发,返回图片错误事件对象 | `event: Event` | ## Slots | 名称 | 说明 | | --- | --- | | loading | 自定义图片加载中的展示内容 | | error | 自定义图片加载失败后的展示内容 | --- --- url: 'https://wot-ui.cn/component/img-cropper.md' --- # ImgCropper 图片裁剪 图片剪裁组件,用于图片裁剪,支持拖拽、缩放、旋转等操作。 ## 组件类型 ### 基本用法 图片裁剪组件需要绑定 `v-model` 来控制组件的显示与隐藏,通过属性 `img-src` 控制展示的图片资源。进入组件后,可以对图片进行拖拽、双指缩放、旋转等操作,监听 `confirm` 事件获取裁剪结果。 > *注意:建议在新页面中使用图片裁剪组件,保持 `show` 为 true,完成裁剪后返回上一页。* ```html 点击上传头像 ``` ```typescript const src = ref('') const imgSrc = ref('') const show = ref(false) function upload() { uni.chooseImage({ count: 1, success: (res) => { const tempFilePaths = res.tempFilePaths[0] src.value = tempFilePaths show.value = true } }) } function handleConfirm(event) { const { tempFilePath } = event imgSrc.value = tempFilePath } function imgLoaderror(res) { console.log('加载失败', res) } function imgLoaded(res) { console.log('加载成功', res) } function handleCancel(event) { console.log('取消', event) } ``` ## 组件配置 ### 自定义裁剪比例 通过 `aspect-ratio` 属性可以设置裁剪框的宽高比,格式为 `width:height`。 #### 3:2 适合拍照 ```html ``` #### 16:9 影视比例 ```html ``` #### 16:10 这么阔 很有型 16:10 的显示比例非常适合展示风景照片或者电影海报等宽屏内容。 ```html ``` ## 特殊用法 ### 裁剪后上传 结合 `useUpload` 可以实现裁剪完成后自动上传图片的功能。 ```html ``` ```typescript import { ref } from 'vue' import { useUpload, useToast } from '@/uni_modules/wot-ui' import { type UploadFileItem } from '@/uni_modules/wot-ui/components/wd-upload/types' const { startUpload, UPLOAD_STATUS } = useUpload() const { show: showToast } = useToast() const show = ref(false) const src = ref('') const imgSrc = ref('') async function handleConfirmUpload(event) { const { tempFilePath } = event // 构建上传文件对象 const file: UploadFileItem = { url: tempFilePath, status: UPLOAD_STATUS.PENDING, percent: 0, uid: new Date().getTime() } try { // 开始上传 await startUpload(file, { action: 'https://your-upload-url', onSuccess() { imgSrc.value = tempFilePath showToast({ msg: '上传成功' }) }, onError() { showToast({ msg: '上传失败' }) }, onProgress(res) { console.log('上传进度:', res.progress) } }) } catch (error) { console.error('上传失败:', error) } } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 打开图片裁剪组件 | `boolean` | `false` | | img-src | 图片资源链接 | `string` | - | | img-width | 截屏预览图片的初始宽度; `1、设置宽度不设置高度,按照宽度等比缩放;2、如果都不设置,预览时图片大小会根据裁剪框大小进行等比缩放,进行锁边处理;`; `string` 类型只支持 `%` 单位,`number` 类型时单位为 `px` | `number \| string` | - | | img-height | 截屏预览图片的初始高度; `1、设置高度不设置宽度,按照高度等比缩放;2、如果都不设置,预览时图片大小会根据裁剪框大小进行等比缩放,进行锁边处理;`; `string` 类型只支持 `%` 单位,`number` 类型时单位为 `px` | `number \| string` | - | | disabled-rotate | 禁止图片旋转 | `boolean` | `false` | | export-scale | 设置导出图片尺寸 | `number` | `2` | | max-scale | 最大缩放倍数 | `number` | `3` | | cancel-button-text | 取消按钮文案 | `string` | `取消` | | confirm-button-text | 确认按钮文案 | `string` | `完成` | | quality | 生成的图片质量 [wx.canvasToTempFilePath属性介绍](https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html#%E5%8F%82%E6%95%B0) | `number` | `1` | | file-type | 目标文件的类型,[wx.canvasToTempFilePath属性介绍](https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html#%E5%8F%82%E6%95%B0) | `string` | `png` | | aspect-ratio | 裁剪框宽高比,格式为 `width:height` | `string` | `1:1` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | confirm | 完成截图时触发 | `{tempFilePath, width, height}` 分别为生成文件的临时路径 (本地路径)、生成图片宽、生成图片高 | | cancel | 当取消截图时触发 | - | | imgloaderror | 当图片加载错误时触发 | `{err}` | | imgloaded | 当图片加载完成时触发 | `{res}` | ## Methods 通过 `ref` 对外暴露组件内部函数: | 方法名称 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | setRotate | 设置图片旋转角度 | `deg` (设置的旋转角度) | - | | resetImg | 重置图片的角度、缩放、位置 | - | - | | revertIsAnimation | 切换图片过渡动画效果 | `animation` (是否启用动画) | - | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/index-bar.md' --- # IndexBar 索引栏 用于列表的索引分类显示和快速定位。 ## 组件类型 ### 基础用法 使用一个固定高度的元素包裹 `wd-index-bar` 组件,组件的宽高会和包裹元素相同。 将 `wd-index-anchor` 作为子组件使用,会根据 anchor 组件的 `index` 属性生成锚点以及侧边栏。 ```vue ``` ## 特殊用法 ### 更新列表数据 当前示例页仅提供基础用法演示。如果你的列表数据需要动态更新,可以参考下面这个扩展示例,配合 `wd-search` 组件使用: ::: details 查看更新列表数据示例 ::: code-group ```html [vue/html] ``` ```typescript [typescript] ``` ```css [css] .wraper { height: calc(100vh - var(--window-top) - 54px); height: calc(100vh - var(--window-top) - constant(safe-area-inset-bottom) - 54px); height: calc(100vh - var(--window-top) - env(safe-area-inset-bottom) - 54px); } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | sticky | 索引是否吸顶 | `boolean` | `false` | ## Slots | name | 说明 | | --- | --- | | default | 自定义索引列表内容 | ## IndexAnchor Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | index | 索引字符 | `string \| number` | - | | custom-style | 根节点自定义样式 | `string` | - | | custom-class | 根节点自定义类名 | `string` | - | ## IndexAnchor Slots | name | 说明 | | --- | --- | | default | 自定义内容 | --- --- url: 'https://wot-ui.cn/component/input.md' --- # Input 输入框 用户可以在文本框中输入内容。 ## 组件类型 ### 基本用法 通过 `v-model` 绑定输入值,通过 `placeholder` 设置占位提示。 ```html ``` ```typescript import { ref } from 'vue' const value = ref('') function handleInput(event) { console.log(event) } ``` ### 数字类型 将 `type` 设置为 `number` 后,仅允许输入数字。 ```html ``` ## 组件状态 ### 禁用 设置 `disabled` 后不可输入。 ```html ``` ### 只读 设置 `readonly` 后不可编辑,但仍会保留展示样式。 ```html ``` ### 错误状态 设置 `error` 后,输入内容会展示为错误态。 ```html ``` ## 组件变体 ### 清空按钮 设置 `clearable` 后,在可清空条件满足时显示清空按钮。 ```html ``` ### 聚焦时显示清空按钮 通过 `clear-trigger="focus"` 控制仅在输入框聚焦且有值时展示清空按钮。 :::warning 注意 支付宝小程序暂不支持 `clear-trigger`,且某些场景下清空按钮无法点击,可参考 [issue](https://github.com/ant-design/ant-design-mini/issues/1255)。 ::: ```html ``` ### 清空后不自动聚焦 通过 `focus-when-clear` 控制点击清空按钮后是否重新聚焦。 ```html ``` ### 密码输入框 设置 `show-password` 后,可切换密码显隐状态。 ```html ``` ## 内容形态 ### 前后图标 通过 `prefix-icon` 和 `suffix-icon` 设置前后图标,图标名称可参考 [Icon](/component/icon)。 ```html ``` ### 后缀插槽 通过 `suffix` 插槽自定义后缀内容。 ```html ``` ## 组件样式 ### 字数限制 设置 `maxlength` 后,可以通过 `show-word-limit` 展示当前字数统计。 ```html ``` ### 紧凑布局 设置 `compact` 后会移除输入框的默认内边距和背景,适合配合 `wd-cell` 或 `wd-form-item` 使用。 ```html ``` ## 特殊用法 ### 结合表单使用 当前表单场景推荐使用 `wd-form` 与 `wd-form-item` 承载标题、必填态与校验提示,`wd-input` 仅负责输入能力。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 输入框绑定值 | `string \| number` | `''` | | type | 输入框类型,可选值为 `text`、`number`、`digit`、`idcard`、`safe-password`、`nickname`、`tel` | `InputType` | `text` | | placeholder | 占位文本 | `string` | `请输入...` | | placeholder-style | placeholder 样式,目前支持 `color`、`font-size`、`font-weight` | `string` | - | | placeholder-class | placeholder 样式类 | `string` | `''` | | maxlength | 最大输入长度 | `number` | 支付宝小程序无默认值,其余平台为 `-1` | | disabled | 是否禁用 | `boolean` | `false` | | readonly | 是否只读 | `boolean` | `false` | | clearable | 是否显示清空按钮 | `boolean` | `false` | | clear-trigger | 清空按钮显示时机,可选值为 `focus`、`always` | `InputClearTrigger` | `always` | | focus-when-clear | 点击清空按钮后是否自动聚焦 | `boolean` | `true` | | show-password | 是否显示密码切换按钮 | `boolean` | `false` | | prefix-icon | 前置图标名称 | `string` | - | | suffix-icon | 后置图标名称 | `string` | - | | show-word-limit | 是否显示字数统计,需要同时设置 `maxlength` | `boolean` | `false` | | error | 是否展示错误状态 | `boolean` | `false` | | align-right | 输入内容是否右对齐 | `boolean` | `false` | | compact | 是否开启紧凑模式;未显式设置时,在 `wd-form-item` 中会自动启用 | `boolean` | - | | focus | 是否获取焦点 | `boolean` | `false` | | cursor-spacing | 光标与键盘的距离 | `number` | `0` | | cursor | 获取焦点时的光标位置 | `number` | `-1` | | selection-start | 光标起始位置,需与 `selection-end` 搭配使用 | `number` | `-1` | | selection-end | 光标结束位置,需与 `selection-start` 搭配使用 | `number` | `-1` | | adjust-position | 键盘弹起时是否自动上推页面 | `boolean` | `true` | | hold-keyboard | 聚焦时点击页面是否保持键盘不收起 | `boolean` | `false` | | confirm-type | 键盘右下角按钮文字,可选值为 `done`、`go`、`next`、`search`、`send` | `InputConfirmType` | `done` | | confirm-hold | 点击键盘右下角按钮时是否保持键盘不收起 | `boolean` | `false` | | always-embed | 是否强制 input 处于同层状态,仅微信小程序 iOS 生效 | `boolean` | `false` | | ignore-composition-event | 是否忽略文本合成系统事件处理;为 `false` 时会触发 composition 相关事件,且合成期间会触发 `input` | `boolean` | `true` | | inputmode | 输入模式提示,可选值为 `none`、`text`、`decimal`、`numeric`、`tel`、`search`、`email`、`url` | `InputMode` | `text` | | enable-native | 支付宝小程序下是否启用原生输入框,设为 `false` 可避免弹起键盘后内容上移 | `boolean` | `true` | | custom-input-class | 输入框自定义类名 | `string` | `''` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ### InputMode 可选值 `inputmode` 为 HTML 规范后期扩展能力,在符合条件的高版本 WebView 中可用于 uni-app 的 Web 与 App-Vue 平台,详见 [inputmode](https://uniapp.dcloud.net.cn/component/input.html#inputmode)。 | 值 | 说明 | | --- | --- | | none | 不弹出虚拟键盘 | | text | 标准文本输入键盘 | | decimal | 小数输入键盘 | | numeric | 纯数字输入键盘 | | tel | 电话输入键盘 | | search | 搜索输入优化键盘 | | email | 邮箱输入优化键盘 | | url | URL 输入优化键盘 | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | input | 输入时触发 | `{ value, cursor, keyCode }` | | focus | 聚焦时触发 | `{ value, height }` | | blur | 失焦时触发 | `{ value }` | | clear | 点击清空按钮时触发 | - | | confirm | 点击键盘完成按钮时触发 | `{ value }` | | keyboardheightchange | 键盘高度变化时触发 | `{ height, duration }` | | clickprefixicon | 点击前置图标时触发 | - | | clicksuffixicon | 点击后置图标时触发 | - | | click | 点击组件根节点时触发 | `event: MouseEvent` | ## Slots | 名称 | 说明 | | --- | --- | | prefix | 自定义前置内容 | | suffix | 自定义后置内容 | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式类 | | custom-input-class | 输入框样式类 | --- --- url: 'https://wot-ui.cn/component/input-number.md' --- # InputNumber 计数器 由增加按钮、减少按钮和输入框组成,用于在一定范围内输入或调整数字。 ## 组件类型 ### 基本用法 通过 `v-model` 绑定输入值,通过 `change` 事件监听数值变化。 ```html ``` ```typescript import { ref } from 'vue' const value = ref(1) function handleChange({ value }) { console.log(value) } ``` ## 组件状态 ### 禁用 设置 `disabled` 后,按钮和输入框都不可操作。 ```html ``` ### 禁用输入框 设置 `disable-input` 后,仅允许通过按钮调整数值。 ```html ``` ### 禁用减号按钮 可以单独禁用减号按钮。 ```html ``` ### 禁用加号按钮 可以单独禁用加号按钮。 ```html ``` ## 组件变体 ### 主题样式 通过 `theme` 切换不同视觉风格,可选值为 `default`、`primary`、`outline-split`、`outline`。 ```html ``` ### 圆角样式 设置 `round` 后,可将按钮显示为圆角样式。 ```html ``` ## 组件样式 ### 设置步长 设置 `step` 后,每次增减都会按对应步长变化。 ```html ``` ### 设置最小值与最大值 通过 `min` 和 `max` 控制可输入范围。 ```html ``` ### 设置小数精度 通过 `precision` 控制结果精度。 ```html ``` ### 严格步进 设置 `step-strictly` 后,输入值会在变更完成时修正为 `step` 的倍数。 ```html ``` ### 严格步进与边界限制 在同时设置 `step-strictly`、`min`、`max` 时,组件会自动修正到合法区间内最接近的步进值。 ```html ``` ### 修改输入框宽度 通过 `input-width` 设置输入框宽度,支持数字和带单位字符串。 ```html ``` ## 特殊用法 ### 无输入框 设置 `without-input` 后,仅展示加减按钮。 ```html ``` ### 允许空值 设置 `allow-null` 后,输入框允许为空,可配合 `placeholder` 使用。 ```html ``` ```typescript const value = ref('') ``` ### 非允许空值但可临时删除 当 `allow-null` 为 `false` 时,输入框可以被临时清空,但在失焦后会自动修正回合法值。 ```html ``` ### 键盘弹起不上推页面 设置 `adjust-position="false"` 后,键盘弹起时不自动上推页面。 ```html ``` ### 非立即更新模式 设置 `immediate-change="false"` 后,输入框内容变化时不会立即触发 `change`,仅在失焦或点击按钮时触发。 ```html ``` ### 初始化时自动修正 设置 `update-on-init` 控制组件初始化时是否将值修正为符合规则的结果。 ```html ``` ### 异步变更 通过 `before-change` 可以在数值变化前进行校验和拦截。 ```html ``` ```typescript import { ref } from 'vue' import { useToast } from '@/uni_modules/wot-ui' import type { InputNumberBeforeChange } from '@/uni_modules/wot-ui/components/wd-input-number/types' const { loading, close } = useToast() const value = ref(1) const beforeChange: InputNumberBeforeChange = (value) => { loading({ msg: `正在更新到${value}...` }) return new Promise((resolve) => { setTimeout(() => { close() resolve(true) }, 500) }) } ``` ### 长按加减 设置 `long-press` 后,支持长按按钮连续增减。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 绑定值 | `number \| string` | - | | min | 最小值 | `number` | `1` | | max | 最大值 | `number` | `Number.MAX_SAFE_INTEGER` | | step | 步进值 | `number` | `1` | | step-strictly | 是否严格按步进值递增或递减 | `boolean` | `false` | | precision | 数值精度 | `number \| string` | `0` | | disabled | 是否禁用 | `boolean` | `false` | | disable-input | 是否禁用输入框 | `boolean` | `false` | | disable-minus | 是否禁用减号按钮 | `boolean` | `false` | | disable-plus | 是否禁用加号按钮 | `boolean` | `false` | | without-input | 是否不显示输入框 | `boolean` | `false` | | input-width | 输入框宽度,支持数字和带单位字符串 | `number \| string` | - | | allow-null | 是否允许输入值为空,设置为 `true` 后允许传入空字符串 | `boolean` | `false` | | placeholder | 输入框占位文本 | `string` | `''` | | adjust-position | 键盘弹起时是否自动上推页面 | `boolean` | `true` | | before-change | 数值变更前触发,返回 `false` 可阻止值更新,支持返回 `Promise` | `(value: number \| string) => boolean \| Promise` | - | | long-press | 是否允许长按进行加减 | `boolean` | `false` | | immediate-change | 是否立即响应输入变化,`false` 时仅在失焦或按钮点击时更新 | `boolean` | `true` | | update-on-init | 是否在初始化时更新 `v-model` 为修正后的值 | `boolean` | `true` | | input-type | 输入框类型,可选值为 `number`、`digit` | `'number' \| 'digit'` | `digit` | | theme | 主题风格,可选值为 `default`、`outline`、`outline-split`、`primary` | `InputNumberTheme` | `default` | | round | 是否启用圆角样式 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 值修改时触发 | `{ value }` | | focus | 输入框获取焦点时触发 | `{ value, height }` | | blur | 输入框失去焦点时触发 | `{ value }` | | update:modelValue | `v-model` 更新时触发 | `number \| string` | --- --- url: 'https://wot-ui.cn/component/keyboard.md' --- # Keyboard 虚拟键盘 虚拟数字键盘,用于输入数字、密码、身份证或车牌号等场景。 ## 基本用法 可以通过 `v-model:visible` 控制键盘是否展示。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ## 组件类型 ### 带右侧栏的键盘 将 `mode` 属性设置为 `custom` 来展示键盘的右侧栏,常用于输入金额的场景。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ### 身份证键盘 通过 `extra-key` 属性可以设置左下角按键内容,比如需要输入身份证号时,可以将 `extra-key` 设置为 `X`。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ### 车牌号键盘 将 `mode` 属性设置为 `car` 来展示车牌号键盘,常用于输入车牌号的场景。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ## 组件变体 ### 车牌号键盘语言控制 通过 `car-lang` 属性可以控制车牌键盘的语言模式,支持中文省份(`zh`)和英文字母(`en`)。通过 `auto-switch-lang` 属性可以控制是否自动切换语言。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) const visible2 = ref(false) const value = ref('') const value2 = ref('') const lang = ref<'zh' | 'en'>('zh') function showKeyBoard() { visible.value = true } function showKeyBoard2() { visible2.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ### 带标题的键盘 通过 `title` 属性可以设置键盘标题。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ### 使用 slot 自定义标题 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ### 多个额外按键 当 `mode` 为 `custom` 时,支持以数组的形式配置两个 `extra-key`。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ### 随机数字键盘 通过 `random-key-order` 属性可以随机排序数字键盘,常用于安全等级较高的场景。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ## 特殊用法 ### 双向绑定 可以通过 `v-model` 绑定键盘当前输入值,并通过 `maxlength` 属性来限制输入长度。 ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) const value1 = ref('') function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ### 展示蒙层遮罩 `hideOnClickOutside`控制键盘弹窗是否有遮罩,通过`modal`控制遮罩是否为透明。 ::: tip 提示 当前`modal`仅控制遮罩是否为透明,`hideOnClickOutside`控制弹窗是否有遮罩,当存在遮罩时,点击遮罩就可以关闭键盘,但是键盘展开时必须点击遮罩关闭当前键盘后才可以再点击别的按钮。也可以关闭`hideOnClickOutside`,手动控制键盘是否展示来实现点击外部时收起键盘,这样更灵活。 ::: ```html ``` ```ts const { show: showToast } = useToast() const visible = ref(false) const value1 = ref('') function showKeyBoard() { visible.value = true } const onInput = (value) => showToast(`${value}`) const onDelete = () => showToast('删除') ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model:visible | 是否展开 | `boolean` | `false` | | v-model | 当前输入值 | `string` | `''` | | title | 键盘标题 | `string` | - | | mode | 键盘模式,可选值为 `default`、`custom`、`car` | `KeyboardMode` | `default` | | z-index | 层级 | `number` | `100` | | maxlength | 最大输入长度 | `number` | `Infinity` | | show-delete-key | 是否显示删除键;仅对默认数字键盘与右侧栏键盘生效 | `boolean` | `true` | | random-key-order | 是否随机排序数字按键 | `boolean` | `false` | | close-text | 关闭按钮文本;在默认/车牌模式中显示在头部,在 `custom` 模式中显示在右侧大按钮上 | `string` | - | | delete-text | 删除按钮文本 | `string` | - | | close-button-loading | 关闭按钮是否显示加载状态 | `boolean` | `false` | | modal | 是否显示蒙层;设为 `false` 时蒙层透明 | `boolean` | `false` | | hide-on-click-outside | 是否允许点击外部关闭键盘,同时控制是否渲染遮罩 | `boolean` | `true` | | lock-scroll | 是否锁定背景滚动 | `boolean` | `true` | | safe-area-inset-bottom | 是否适配底部安全区 | `boolean` | `true` | | extra-key | 额外按键,可传单个字符串或字符串数组;`custom` 模式下支持两个额外按键 | `string \| string[]` | - | | root-portal | 是否从页面中脱离出来,用于解决 fixed 失效问题 | `boolean` | `false` | | v-model:car-lang | 车牌键盘语言模式,当 `mode=car` 时生效,可选值为 `zh`、`en` | `CarKeyboardLang` | - | | auto-switch-lang | 是否自动切换车牌键盘语言,当 `mode=car` 且 `car-lang` 为非受控状态时生效 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Slots | 名称 | 说明 | | --- | --- | | title | 自定义标题内容 | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | input | 点击可输入按键时触发 | `key: string` | | delete | 点击删除键时触发 | - | | close | 点击关闭按钮或遮罩关闭时触发 | - | | update:visible | 键盘显隐状态变化时触发 | `visible: boolean` | | update:modelValue | 当前输入值变化时触发 | `value: string` | | update:carLang | 车牌键盘语言变化时触发 | `lang: 'zh' \| 'en'` | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式类 | | custom-style | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/layout.md' --- # Layout 布局 用于快速进行布局。 ## 布局能力 ### 基础用法 `Layout` 组件提供了 `24列` 栅格,通过在 `wd-col` 上设置 `span` 属性,通过计算当前内容所占百分比进行分栏。 注意:分栏布局仅提供布局,即元素宽度,内部样式用户可根据需要通过 `custom-class` 或修改内部标签来自行定义样式。 ::: code-group ```html span: 24 span: 12 span: 12 span: 8 span: 8 span: 8 span: 6 span: 6 span: 6 span: 6 ``` ```scss .bg-dark1, .bg-dark, .bg-light { border-radius: 4px; min-height: 30px; text-align: center; line-height: 30px; font-size: 12px; margin-bottom: 10px; color: rgba(0, 0, 0, 0.45); } .bg-dark1 { background: #99a9bf; color: #fff; } .bg-dark { background: #d3dce6; } .bg-light { background: #e5e9f2; } ``` ::: ### 分栏偏移 `offset` 属性可以设置分栏的偏移量,计算方式以及偏移大小与 `span` 相同。 ```html span: 4 span: 8 offset: 4 span: 8 offset: 4 span: 8 offset: 4 ``` ### 分栏间隔 通过 `gutter` 属性可以设置列元素之间的间距,默认间距为 0。 ```html span: 8 span: 8 span: 8 ``` ### Justify 对齐 通过 `justify` 属性可以设置主轴对齐方式,可选值为 `start`、`center`、`end`、`space-between`、`space-around`、`space-evenly`。 ```html center center center end end end between between between around around around ``` ### Align 对齐 通过 `align` 属性可以设置交叉轴对齐方式,可选值为 `top`、`middle`、`bottom`。 ```html middle middle middle bottom bottom bottom ``` ## Row Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | gutter | 列元素之间的间距(单位为 px) | `number` | `0` | | justify | 主轴对齐方式,可选值为 `start`、`center`、`end`、`space-between`、`space-around`、`space-evenly` | `string` | `start` | | align | 交叉轴对齐方式,可选值为 `top`、`middle`、`bottom` | `string` | `top` | | custom-class | 根节点样式类名 | `string` | - | | custom-style | 根节点样式 | `string` | - | ## Col Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | span | 列元素宽度(栅格占据的列数,共 24 列) | `number` | `24` | | offset | 列元素偏移距离(栅格左侧的间隔列数) | `number` | `0` | | custom-class | 根节点样式类名 | `string` | - | | custom-style | 根节点样式 | `string` | - | ## Row Slots | name | 说明 | | --- | --- | | default | 行内容 | ## Col Slots | name | 说明 | | --- | --- | | default | 列内容 | --- --- url: 'https://wot-ui.cn/guide/llms-txt.md' --- # LLMs.txt [llms.txt](https://llmstxt.org/) 是一个专为大型语言模型设计的文本文件,类似 robots.txt,但目标不同。robots.txt 告诉搜索引擎爬虫哪些页面可以爬取,而 llms.txt 为 AI 工具提供网站内容的结构化信息,帮助它们更好地理解和索引组件库文档、示例和最佳实践。 如果你不确定该选择哪种 AI 接入方式,可以先阅读 [AI 使用指南](/guide/ai)。 ## 可用资源 我们也提供 2 个 `llms.txt` 路由来帮助 AI 工具访问文档: * [llms.txt](https://wot-ui.cn/llms.txt) - 包含所有组件及其文档链接的结构化概览 * [llms-full.txt](https://wot-ui.cn/llms-full.txt) - 提供包含实现细节和示例的完整文档 ## 在 AI 工具中使用 ### Cursor 在 Cursor 中找到 `Indexing & Docs` 设置,并将 `llms.txt` 添加到 `Docs` 中,使用 `@Docs` 功能将 llms.txt 文件包含到项目中。 [详细了解 Cursor 中的 @Docs 功能](https://cursor.com/docs/agent/tools/search) ### TRAE 在 TRAE 中找到 `上下文/文档集` 设置,并将 `llms.txt` 添加到 `文档集` 中,使用 `#Docs` 功能将 llms.txt 文件包含到项目中。 [详细了解 TRAE 中的 #Docs 功能](https://docs.trae.ai/ide/number-sign) ### 其他工具 任何支持 `llms.txt` 标准,或支持通过 URL 摄取文档的工具,都可以使用我们提供的 llms.txt 文件。你可以将它加入工具的 `文档集`、`rules` 或知识库配置中,帮助 AI 更好地理解 Wot UI 组件库。 ### context7 如果不使用 llms.txt,也可以通过 [context7](https://github.com/upstash/context7) 直接读取组件库文档。 [详细了解 context7](https://github.com/upstash/context7) ## 延伸阅读 * [AI 使用指南](/guide/ai) * [Skills](/guide/skills) * [llms.txt:让 AI 更好地理解你的文档](https://juejin.cn/post/7500981295105015847) --- --- url: 'https://wot-ui.cn/component/loading.md' --- # Loading 加载指示器 加载动画,用于表示加载中的过渡状态。 ## 组件类型 ### 类型 通过 `type` 属性设置指示器类型,可选值为 `circular`、`spinner`、`dots`、`wave`,默认为 `circular`。 ```html ``` ## 组件样式 ### 颜色 通过 `color` 属性修改指示器的颜色。 ```html ``` ### 大小 通过 `size` 属性设置指示器的大小,支持 `number` / `string` 类型。 ```html ``` ## 内容形态 ### 显示文字 通过 `text` 属性或默认插槽设置加载文字。 ```html 加载中... 加载中... 加载中... ``` ### 水平方向 通过 `direction` 属性设置文字与指示器的排列方向,可选值为 `vertical`、`horizontal`,默认为 `vertical`。 ```html 加载中... 加载中... 加载中... ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | type | 加载指示器类型,可选值为 `circular`、`spinner`、`dots`、`wave` | `LoadingType` | `circular` | | color | 设置加载指示器颜色 | `string` | - | | size | 设置加载指示器大小 | `number \| string` | - | | text | 加载指示器文字 | `string` | - | | direction | 排列方向,可选值为 `vertical`、`horizontal` | `LoadingDirection` | `vertical` | | inherit-color | 是否继承父元素颜色 | `boolean` | `false` | | custom-class | 根节点样式类名 | `string` | - | | custom-style | 根节点样式 | `string` | - | | custom-spinner-class | 自定义加载指示器样式类 | `string` | - | ## Slots | name | 说明 | | --- | --- | | default | 加载文字内容 | --- --- url: 'https://wot-ui.cn/component/loadmore.md' --- # loadmore 加载更多 用于在列表底部展示加载状态。 ## 基本用法 在需要进行加载的列表的底部引入该组件即可。当滑动到列表底部时,通过设置`state`展示不同的文案。 ```html ``` ```scss :deep(.loadmore) { background-color: #f4f4f4; margin: 20px 0; } ``` ## 自定义文案 通过设置`loading-text`、`finished-text`、`error-text`配合`state`展示不同状态时的文案 ```html ``` ## 点击继续加载 当 `state` 为 `error` 时,点击组件区域会触发 `reload` 事件。 ```html ``` ## 应用实现 配合`onReachBottom`事件实现滚动到底部加载更多 ```html 这是一条测试{{ index + 1 }} ``` ```typescript import { ref } from 'vue' import { onLoad, onReachBottom } from '@dcloudio/uni-app' const state = ref('loading') const num = ref(0) const max = ref(60) onReachBottom(() => { if (num.value === 45) { state.value = 'error' } else if (num.value < max.value) { loadmore() } else if (num.value === max.value) { state.value = 'finished' } }) onLoad(() => { loadmore() }) function loadmore() { setTimeout(() => { num.value = num.value + 15 state.value = 'loading' }, 200) } ``` ```scss .list-item { position: relative; display: flex; padding: 10px 15px; background: #fff; color: #464646; } .list-item:after { position: absolute; display: block; content: ''; height: 1px; left: 0; width: 100%; bottom: 0; background: #eee; transform: scaleY(0.5); } image { display: block; width: 120px; height: 78px; margin-right: 15px; } .right { -webkit-box-flex: 1; -ms-flex: 1; flex: 1; } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | state | 加载状态,可选值为 `loading`、`finished`、`error` | `LoadMoreState` | - | | loading-text | 加载状态文案 | `string` | 国际化文案“正在努力加载中...” | | finished-text | 加载完成文案 | `string` | 国际化文案“已加载完毕” | | error-text | 加载失败文案;“点击重试”为组件内独立提示文案,不包含在该属性默认值中 | `string` | 国际化文案“加载失败” | | loading-props | 内部 `wd-loading` 的属性配置,类型参见下方 `LoadingProps` | `Partial` | - | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | #### LoadingProps 参见 [LoadingProps](/component/loading.html#attributes)。传入的 `customClass` 会自动追加 `wd-loadmore__loading` 类名。 ## Slots | name | 说明 | | --- | --- | | loading | 自定义加载中内容 | | finished | 自定义加载完成内容 | | error | 自定义加载失败内容 | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | reload | `state` 为 `error` 时,点击组件触发 | - | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/navbar.md' --- # Navbar 导航栏 为页面提供导航功能,常用于页面顶部。 ::: tip 常见问题 **右图标被小程序胶囊挡住?** 在小程序平台开启自定义顶部导航时,右上角会固定显示胶囊,所以此时右侧插槽及选项是不建议使用。 **如何设置为背景透明?** 通过 `custom-style` 设置组件 `background-color` 为 `transparent`。 ```html ``` **组件会被 `video` 覆盖?** `video` 为原生组件,层级较高,目前无法遮盖,需要具体平台具体分析。 ::: ## 组件类型 ### 基础用法 通过 `title` 属性设置导航栏标题。 ```html ``` ### 返回上级 在导航栏实现返回上级功能。 ::: code-group ```html ``` ```ts function handleClickLeft() { uni.navigateBack() } ``` ::: ### 右侧按钮 在导航栏右侧添加可点击的按钮。 ::: code-group ```html ``` ```ts import { useToast } from '@/uni_modules/wot-ui' const { show: showToast } = useToast() function handleClickRight() { showToast('按钮') } ``` ::: ## 组件状态 ### 禁用按钮 通过 `left-disabled` 或 `right-disabled` 属性来禁用两侧的按钮。按钮被禁用时透明度降低,且无法点击。 ```html ``` ## 组件样式 ### 固定在顶部 通过 `fixed` 属性设置导航栏固定在页面顶部,通过 `placeholder` 在顶部生成占位空间,通过 `safeAreaInsetTop` 开启顶部安全区的适配。 ```html ``` ## 内容形态 ### 使用插槽 可以通过 `left` 和 `right` 插槽自定义导航栏两侧的内容。 ```html ``` ### 胶囊样式 通过 `capsule` 插槽和 `wd-navbar-capsule` 组件定制返回胶囊。 ::: code-group ```html ``` ```ts function handleBack() { uni.navigateBack({}) } function handleBackHome() { uni.reLaunch({ url: '/pages/index/Index' }) } ``` ::: ### 带搜索栏 通过 `title` 插槽自定义标题区域。 ::: code-group ```html ``` ```scss .search-box { display: flex; height: 100%; align-items: center; --wot-search-padding: 0; --wot-search-side-padding: 0; :deep() { .wd-search { background: transparent; } } } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | title | 标题文字 | `string` | - | | left-text | 左侧文案 | `string` | - | | right-text | 右侧文案 | `string` | - | | left-arrow | 是否显示左侧箭头 | `boolean` | `false` | | bordered | 是否显示下边框 | `boolean` | `false` | | fixed | 是否固定到顶部 | `boolean` | `false` | | placeholder | 固定在顶部时,在标签位置生成一个等高的占位元素 | `boolean` | `false` | | z-index | 导航栏 z-index | `number` | `10` | | safe-area-inset-top | 是否开启顶部安全区适配 | `boolean` | `false` | | left-disabled | 是否禁用左侧按钮,禁用时透明度降低,且无法点击 | `boolean` | `false` | | right-disabled | 是否禁用右侧按钮,禁用时透明度降低,且无法点击 | `boolean` | `false` | | custom-class | 根节点样式类名 | `string` | - | | custom-style | 根节点样式 | `string` | - | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click-left | 点击左侧按钮时触发 | - | | click-right | 点击右侧按钮时触发 | - | ## Slots | name | 说明 | | --- | --- | | capsule | 自定义胶囊(当存在胶囊时,left 不生效) | | left | 左侧内容 | | title | 标题内容 | | right | 右侧内容 | ## NavbarCapsule Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | custom-class | 根节点样式类名 | `string` | - | | custom-style | 根节点样式 | `string` | - | ## NavbarCapsule Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | back | 点击返回按钮时触发 | - | | back-home | 点击返回首页按钮时触发 | - | --- --- url: 'https://wot-ui.cn/component/notice-bar.md' --- # NoticeBar 通知栏 通知栏组件,用于在页面顶部展示通知提醒。 ## 组件类型 ### 基本用法 设置 `text` 文本内容和 `prefix` 左侧图标。 ```html ``` ## 组件变体 ### 类型修改 设置 `type` 可修改通知类型,通知类型共有三种 `info`|`warning`|`danger`,默认值为`warning`。 ```html ``` ```scss :deep(.space) { margin-bottom: 10px; } ``` ### 可关闭的 设置 `closable` 属性,使通知栏可以关闭。 ```html ``` ## 内容形态 ### 禁止滚动 设置 `scrollable` 为 `false` 可以关闭滚动效果,通知栏会保持静态展示。 ```html ``` ### 插槽演示 未传 `prefix` 属性时,可以通过 `prefix` 插槽自定义左侧内容;`suffix` 插槽会覆盖默认的关闭图标区域。 ```html 通知被禁或时段内消息屏蔽可能造成消… ``` ```scss :deep(.prefix) { font-size: 18px; padding-right: 4px; width: 18px; height: 18px; } ``` ### 多行展示 设置 `wrapable` 属性为 `true` 且同时禁止滚动 `scrollable` 即可开启多行展示。 ```html ``` ## 组件样式 ### 自定义颜色 设置 `color` 修改文字和图标颜色,设置 `background-color` 修改背景颜色。 ```html ``` ## 特殊用法 ### 多文本轮播 将一个`string[]`传递给`text`属性,即可开启多文本轮播,并且会在展示下一条文本时触发`next`事件,该事件接收一个`number`参数,代表的是当前展示的文本数组索引 ```html ``` ```javascript import { ref } from 'vue' const textArray = ref([ '欢迎使用 wot-ui 组件库', '该组件库基于uniapp ->Vue3, ts构建', '项目地址:https://github.com/wot-ui/wot-ui', '我们的目标是打造最强uniapp组件库', '诚挚邀请大家共同建设', '这是一条消息提示信息,这是一条消息提示信息,这是一条消息提示信息,这是一条消息提示信息,这是一条消息提示信息' ]) const onNext = (index: number) => { console.log('展示下一条,index: ', index) console.log('文本是:' + textArray.value[index]) } ``` ### 垂直滚动 1. `direction`传递`vertical`即可开启垂直滚动,目前仅支持一个方向的垂直滚动 2. `text`为数组时才会进行滚动 ```html ``` ### 点击事件 点击通知内容区时会触发 `click` 事件,返回当前展示文本和对应索引。 ```html ``` ```ts function handleClick(result: { text: string; index: number }) { console.log(result) } ``` ### 重置播放动画 通过`ref`获取组件实例,调用`reset`方法即可重置播放动画。当你遇到`NoticeBar`的播放动画异常的情况时,可以调用`reset`方法重置动画。 例如:在`APP-VUE`端,`Tabbar`页面使用`NoticeBar`时,从其它界面返回到`NoticeBar`页面,会偶发`NoticeBar`动画异常,此时可以调用`reset`方法重置动画。 参考issues:[#358](https://github.com/Moonofweisheng/wot-design-uni/issues/358)、[#650](https://github.com/Moonofweisheng/wot-design-uni/issues/650) ```html 重置播放动画 ``` ```ts // uni_modules import { type NoticeBarInstance } from '@/uni_modules/wot-design-uni/components/wd-notice-bar/types' // npm // import { type NoticeBarInstance } from 'wot-design-uni/components/wd-notice-bar/types' const notice = ref() const textArray = ref([ '欢迎使用 wot-ui 组件库', '该组件库基于uniapp ->Vue3, ts构建', '项目地址:https://github.com/wot-ui/wot-ui', '我们的目标是打造最强uniapp组件库', '诚挚邀请大家共同建设', '这是一条消息提示信息,这是一条消息提示信息,这是一条消息提示信息,这是一条消息提示信息,这是一条消息提示信息' ]) function handleReset() { notice.value?.reset() } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | text | 通知栏文案 | `string \| string[]` | `''` | | type | 通知栏类型,可选值为 `warning`、`info`、`danger` | `NoticeBarType` | `warning` | | prefix | 左侧图标名称 | `string` | - | | scrollable | 是否开启滚动播放 | `boolean` | `true` | | delay | 滚动动画初始延时,单位为秒 | `number` | `1` | | speed | 滚动速度,单位为 `px/s` | `number` | `50` | | closable | 是否显示关闭按钮 | `boolean` | `false` | | wrapable | 是否换行展示;仅在 `scrollable=false` 的横向模式下生效 | `boolean` | `false` | | color | 文字和图标颜色 | `string` | - | | background-color | 背景颜色 | `string` | - | | direction | 滚动方向,可选值为 `horizontal`、`vertical` | `NoticeBarScrollDirection` | `horizontal` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | close | 点击关闭按钮时触发 | - | | next | 切换到下一条文本时触发 | `index: number` | | click | 点击内容区时触发 | `{ text: string, index: number }` | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | reset | 重置播放动画 | - | ## Slots | name | 说明 | | --- | --- | | prefix | 自定义前置内容;传入 `prefix` 属性时该插槽不生效 | | suffix | 自定义后置内容;会覆盖默认关闭图标 | | default | 自定义通知文本内容;仅在 `direction='horizontal'` 时生效 | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/notify.md' --- # Notify 消息通知 通知类组件,用于在页面顶部展示通知信息。 ## 组件状态 ### 基础用法 需要在页面中引入该组件,作为挂载点。 ::: code-group ```html ``` ```ts import { useNotify } from '@/uni_modules/wot-ui' const { showNotify, closeNotify } = useNotify() // 3 秒后自动关闭 showNotify('通知内容') // 主动关闭 closeNotify() ``` ::: ### 自定义配置 支持自定义颜色、弹出位置、展示时长以及是否显示关闭按钮。 ::: code-group ```ts // 自定义颜色 showNotify({ message: '自定义颜色', color: '#ad0000', background: '#ffe1e1' }) // 自定义位置 showNotify({ message: '自定义位置', position: 'bottom' }) // 自定义时长 showNotify({ message: '自定义时长', duration: 1000 }) // 显示关闭按钮 showNotify({ message: '通知内容', closable: true, duration: 0 }) ``` ::: ## 组件类型 ### 通知类型 支持 `primary`、`success`、`warning`、`danger` 四种通知类型,默认为 `danger`。 ::: code-group ```ts // 主要通知 showNotify({ type: 'primary', message: '通知内容' }) // 成功通知 showNotify({ type: 'success', message: '通知内容' }) // 危险通知 showNotify({ type: 'danger', message: '通知内容' }) // 警告通知 showNotify({ type: 'warning', message: '通知内容' }) ``` ::: ## 组件样式 ### 悬浮通知 通过 `variant` 属性设置为 `floating` 可展示悬浮卡片式通知。悬浮通知具有独立的外边距、圆角与阴影,并且其前缀图标会自动适配当前 `type` 的状态主色。 ::: code-group ```ts showNotify({ type: 'primary', message: '通知内容', variant: 'floating', closable: true }) ``` ::: ## 内容形态 ### 使用 Notify 组件 如果需要在 Notify 内嵌入组件或其他自定义内容,可以直接使用 Notify 组件,并使用默认插槽进行定制。 ::: code-group ```html 使用 Notify 组件调用 成功通知 ``` ```ts import { ref, onMounted } from 'vue' let timer: ReturnType export default { setup() { const visible = ref(false) const safeHeight = ref(0) const showNotify = () => { visible.value = true if (timer) clearTimeout(timer) timer = setTimeout(() => { visible.value = false }, 3000) } onMounted(() => { // #ifdef H5 safeHeight.value = 44 // #endif }) return { visible, showNotify, safeHeight } } } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | type | 类型,可选值为 `primary` `success` `warning` `danger` | `NotifyType` | `danger` | | message | 展示文案,支持通过`\n`换行 | `string \| number` | - | | duration | 展示时长(ms),值为 0 时,notify 不会消失 | `number` | `3000` | | visible | 显示状态(支持 v-model) | `boolean` | `false` | | position | 弹出位置,可选值为 `top` `bottom` | `NotifyPosition` | `top` | | color | 字体颜色 | `string` | - | | background | 背景颜色 | `string` | - | | z-index | 将组件的 z-index 层级设置为一个固定值 | `number` | `99` | | safe-height | 顶部安全高度 | `number \| string` | - | | selector | 指定唯一标识 | `string` | - | | root-portal | 是否从页面中脱离出来,用于解决各种 fixed 失效问题 | `boolean` | `false` | | closable | 是否显示关闭按钮 | `boolean` | `false` | | variant | 展示形态,可选值为 `filled` `floating` | `NotifyVariant` | `filled` | | custom-class | 根节点样式类名 | `string` | - | | custom-style | 根节点样式 | `string` | - | ## Events | 事件名 | 说明 | 参数 | | --- | --- | --- | | click | 点击时的回调函数 | `(event: MouseEvent) => void` | | closed | 关闭时的回调函数 | `() => void` | | opened | 展示后的回调函数 | `() => void` | ## Slots | name | 说明 | | --- | --- | | default | 自定义通知内容 | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | showNotify | 展示提示 | `NotifyOptions` / `string` | | closeNotify | 关闭提示 | - | | setNotifyDefaultOptions | 修改默认配置,影响所有的 `showNotify` 调用 | `NotifyOptions` | | resetNotifyDefaultOptions | 重置默认配置,影响所有的 `showNotify` 调用 | - | ## Options 调用 `showNotify`、 `setNotifyDefaultOptions` 等方法时,支持传入以下选项: | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | type | 类型,可选值为 `primary` `success` `warning` `danger` | `NotifyType` | `danger` | | message | 展示文案,支持通过`\n`换行 | `string \| number` | - | | duration | 展示时长(ms),值为 0 时,notify 不会消失 | `number` | `3000` | | position | 弹出位置,可选值为 `top` `bottom` | `NotifyPosition` | `top` | | color | 字体颜色 | `string` | - | | background | 背景颜色 | `string` | - | | zIndex | 将组件的 z-index 层级设置为一个固定值 | `number` | `99` | | safeHeight | 顶部安全高度 | `number \| string` | - | | rootPortal | 是否从页面中脱离出来,用于解决各种 fixed 失效问题 | `boolean` | `false` | | closable | 是否显示关闭按钮 | `boolean` | `false` | | variant | 展示形态,可选值为 `filled` `floating` | `NotifyVariant` | `filled` | | customClass | 根节点样式类名 | `string` | - | | customStyle | 根节点样式 | `string` | - | | onClick | 点击时的回调函数 | `(event: MouseEvent) => void` | - | | onClosed | 关闭时的回调函数 | `() => void` | - | | onOpened | 展示后的回调函数 | `() => void` | - | --- --- url: 'https://wot-ui.cn/component/overlay.md' --- # Overlay 遮罩层 创建一个遮罩层,用于强调特定的页面元素,并阻止用户进行其他操作。 ## 基础用法 ### 基础组件 使用 `show` 控制遮罩层的显示/隐藏。 ```html 显示遮罩层 ``` ## 特殊样式 ### 嵌入内容 通过默认插槽可以在遮罩层上嵌入任意内容。 ::: code-group ```html 嵌入内容 ``` ```scss .wrapper { display: flex; align-items: center; justify-content: center; height: 100%; } .block { width: 120px; height: 120px; background-color: #fff; } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | show | 是否展示遮罩层 | `boolean` | `false` | | duration | 动画时长,单位为毫秒 | Record\ | number | boolean | `300` | | lock-scroll | 是否锁定背景滚动,锁定时蒙层里的内容也将无法滚动 | `boolean` | `true` | | z-index | 层级 | `number` | `10` | | custom-style | 根节点样式 | `string` | `''` | | custom-class | 根节点样式类名 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 点击遮罩层时触发 | - | | before-enter | 进入动画开始前触发 | - | | enter | 进入动画开始时触发 | - | | after-enter | 进入动画结束后触发 | - | | before-leave | 离开动画开始前触发 | - | | leave | 离开动画开始时触发 | - | | after-leave | 离开动画结束后触发 | - | ## Slots | name | 说明 | | --- | --- | | default | 遮罩层内容 | --- --- url: 'https://wot-ui.cn/component/pagination.md' --- # Pagination 分页 当数据量过多时,使用分页分解数据。 ## 组件类型 ### 基本用法 通过 `v-model` 来绑定当前页码,`total`设置总条数,`page-size`设置一页展示条数,默认为10条,总页数通过`total`和`page-size`自动计算。 ```html ``` ```typescript const value = ref(1) function handleChange({ value }) { console.log(value) } ``` ## 组件变体 ### 按钮风格 通过 `button-variant` 设置按钮风格,可选值为 `text`、`plain`、`dashed`、`base`。 ```html ``` ### Icon 图标 设置 `show-icon` 属性,将分页导航展示为Icon图标。 ```html ``` ### 文字提示 设置 `show-message` 属性,展示文字提示。 ```html ``` ```typescript const value = ref(1) const total = ref(160) const pageSize = ref(20) ``` ## 内容形态 ### 自定义插槽 组件提供 `prev`、`size`、`next`、`message` 四个插槽,可用于自定义分页按钮、中间页码信息和底部提示。 ```html ``` ```scss .custom-pagination__content { display: flex; justify-content: center; align-items: center; flex: 1; } .custom-pagination__page { color: #f00; } .custom-pagination__separator { margin: 0 5px; } .custom-pagination__total { color: #00f; } .custom-pagination__message { margin-top: 10px; color: #999; text-align: center; } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前页码 | `number` | - | | total-page | 总页数;传入 `total` 时会优先根据 `total` 与 `page-size` 计算 | `number` | `1` | | total | 总数据条数 | `number` | `0` | | page-size | 每页条数 | `number` | `10` | | prev-text | 上一页按钮文字;未设置时使用内置国际化文案 | `string` | - | | next-text | 下一页按钮文字;未设置时使用内置国际化文案 | `string` | - | | show-icon | 是否展示翻页图标 | `boolean` | `false` | | show-message | 是否展示文字提示 | `boolean` | `false` | | button-variant | 分页按钮风格,可选值为 `base`、`plain`、`dashed`、`text` | `ButtonVariant` | `text` | | hide-if-one-page | 总页数只有一页时是否隐藏 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 页码变化时触发 | `{ value }` | | update:modelValue | `v-model` 更新时触发 | `value: number` | ## Slots | name | 说明 | 参数 | | --- | --- | --- | | prev | 自定义上一页按钮 | `{ modelValue, totalPageNum, total, pageSize }` | | size | 自定义中间页码显示区域 | `{ modelValue, totalPageNum, total, pageSize }` | | next | 自定义下一页按钮 | `{ modelValue, totalPageNum, total, pageSize }` | | message | 自定义底部提示信息,仅在 `show-message` 为 `true` 时生效 | `{ modelValue, totalPageNum, total, pageSize }` | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/password-input.md' --- # PasswordInput 密码输入框 带网格的密码输入组件,适用于支付密码、短信验证码等场景,通常与 [Keyboard 键盘](./keyboard.md) 组件配合使用。 `wd-password-input` 仅负责展示输入值、光标和提示信息,不直接处理录入逻辑。通常将 `focused` 与键盘显隐状态绑定,并在 `focus` 事件中打开键盘。 ## 组件类型 ### 基础用法 搭配 `wd-keyboard` 组件实现密码输入。 ```html ``` ```typescript import { ref } from 'vue' const value = ref('123') const showKeyboard = ref(false) ``` ## 组件变体 ### 自定义长度 通过 `length` 设置密码位数,并同步设置键盘的 `maxlength`。 ```html ``` ## 组件样式 ### 格子间距 通过 `gutter` 设置格子之间的间距,默认单位为 `px`。 ```html ``` ## 内容形态 ### 明文展示 将 `mask` 设置为 `false` 可以明文展示输入内容,适用于短信验证码等场景。 ```html ``` ### 提示信息 通过 `info` 设置普通提示信息,通过 `error-info` 设置错误提示。 ```html ``` ```typescript import { ref, watch } from 'vue' const value = ref('123') const errorInfo = ref('') const showKeyboard = ref(false) watch(value, (newVal) => { if (newVal.length === 6 && newVal !== '123456') { errorInfo.value = '密码错误' } else { errorInfo.value = '' } }) ``` ## 特殊用法 ### 随机键盘 结合 `wd-keyboard` 的 `random-key-order` 能力,可以提升数字输入场景的安全性。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前输入值 | `string` | `''` | | mask | 是否隐藏密码内容 | `boolean` | `true` | | info | 输入框下方文字提示 | `string` | `''` | | error-info | 输入框下方错误提示 | `string` | `''` | | gutter | 输入框格子之间的间距,默认单位为 `px` | `number \| string` | `0` | | length | 密码长度 | `number` | `6` | | focused | 是否处于聚焦状态;聚焦时显示光标,通常与键盘显隐状态联动 | `boolean` | `true` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | focus | 点击密码输入框时触发 | `event: Event` | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/picker.md' --- # Picker 选择器 Picker 包含了一个弹出层(`wd-popup`)与一个选择器视图(`wd-picker-view`),不包含外层的触发元素(如 Input、Cell 等)。通常需要结合 `wd-cell` 或表单相关组件来触发显示。 ## 基础用法 需结合一个外部触发器,比如 `wd-cell`,并通过绑定 `v-model` 来保存选中的内容数组,利用 `v-model:visible` 控制 Picker 的显示或隐藏。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const show = ref(false) const value = ref([]) const columns = ref([ { label: '选项1', value: '1' }, { label: '选项2', value: '2' }, { label: '选项3', value: '3' } ]) ``` ::: ## 多列 `columns` 属性传入二维数组,此时 `value` 为对应列选中项 `value` 的一维数组。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const show = ref(false) const value = ref([]) const displayValue = ref('') const columns = ref([ [ { label: '中山大学', value: '1' }, { label: '中南大学', value: '2' }, { label: '华南理工大学', value: '3' } ], [ { label: '计算机科学与技术', value: '1' }, { label: '软件工程', value: '2' }, { label: '通信工程', value: '3' } ] ]) const handleConfirm = ({ selectedItems }: any) => { displayValue.value = selectedItems.map((item: any) => item.label).join(', ') } ``` ::: ## 多级联动 设置 `cascade` 属性,并将 `columns` 设定为带层级的树状结构(通过 `children` 嵌套子项)。 可以结合自定义的展示函数进行页面回填格式化。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const show = ref(false) const value = ref(['110000', '110100', '110102']) const displayValue = ref('北京 - 北京市 - 西城区') const columns = ref([ { label: '北京', value: '110000', children: [ { label: '北京市', value: '110100', children: [ { label: '东城区', value: '110101' }, { label: '西城区', value: '110102' }, { label: '朝阳区', value: '110105' } ] } ] } ]) function handleConfirm({ selectedItems }: any) { displayValue.value = selectedItems.map((item: any) => item.label).join(' - ') } ``` ::: ## 自定义弹窗标题 可通过 `title` 属性为内部弹窗配置顶部提示性文字标题。 ::: code-group ```html ``` ::: ## 确定前校验 设置 `before-confirm` 函数,在用户点击弹出层右上角“完成”按钮时进行拦截,支持返回 `boolean` 或 `Promise` 控制是否允许选定并关闭弹窗。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' import { useToast } from '@/uni_modules/wot-ui' const toast = useToast() const show = ref(false) const columns = ref([ { label: '选项1', value: '1' }, { label: '选项2', value: '2' }, { label: '选项3', value: '3' } ]) const value = ref([]) const beforeConfirm = (value: string[]) => { return new Promise((resolve) => { setTimeout(() => { // 假设选项2与选项3被判断为无效选择 if (['2', '3'].includes(value[0])) { toast.error('该选项校验不通过,请重新选择') resolve(false) } else { resolve(true) } }, 1000) }) } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 选中项。单列选择器为长度为 1 的数组,多列则为对应多项值组成的数组 | `(string \| number)[]` | `[]` | | v-model:visible | 控制选择器弹出层的显示与隐藏 | `boolean` | `false` | | columns | 选项数据结构数组配置,对于多列使用二维数组,多级联动结合 cascade 嵌套 children | `PickerOption[] \| PickerOption[][]` | `[]` | | cascade | 是否开启级联模式 | `boolean` | `false` | | title | 弹出层大标题 | `string` | - | | cancel-button-text | 顶部操作栏左侧取消按钮文案 | `string` | - | | confirm-button-text | 顶部操作栏右侧确认按钮文案 | `string` | - | | value-key | 选项对象中负责标示值的键名 | `string` | `'value'` | | label-key | 选项对象中负责呈现文本的键名 | `string` | `'label'` | | children-key | 级联模式中对应的下一级子级键名 | `string` | `'children'` | | item-height | 内部滚筒每个选项的单个高度(px) | `number` | `44` | | visible-item-count | 单屏视窗内最多可见的选项数量 | `number` | `6` | | before-confirm | 确定前校验函数,接收 `(value)` 参数,返回 `boolean` 或 `Promise` | `Function` | - | | close-on-click-modal | 点击遮罩层时是否关闭弹窗 | `boolean` | `true` | | z-index | 弹出层层级深度 | `number` | `15` | | safe-area-inset-bottom | 弹出面板是否设置默认的底部安全距离 | `boolean` | `true` | | immediate-change | 是否在手指松开时立即触发 `change` 而非滚动结束 | `boolean` | `false` | | root-portal | 是否开启 `root-portal` 将组件脱离当前节点进行渲染 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | | custom-view-class | pickerView 组件的外部自定义样式类 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | confirm | 点击完成按钮触发 | `{ value, selectedItems }` | | cancel | 点击取消或蒙层关闭触发 | - | | open | 打开弹出层选择器时触发 | - | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | open | 打开 Picker 弹窗 | - | | close | 关闭 Picker 弹窗 | - | --- --- url: 'https://wot-ui.cn/component/picker-view.md' --- # PickerView 选择器视图 选择器视图,用于从一组数据中选择单个或多个值。 `wd-picker-view` 只负责滚筒选择区域本身,不包含弹出层与顶部操作栏;如果需要完整的弹窗选择器,可以使用 [Picker](./picker.md)。 当 `columns` 中的选项为对象时,组件默认读取 `label` 作为展示文本、读取 `value` 作为选中值;也可以通过 `label-key`、`value-key`、`children-key` 自定义字段映射。 ## 组件类型 ### 基本用法 单列选择器可直接传入字符串数组或对象数组,`v-model` 推荐始终使用数组形式保存当前选中值。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const value = ref(['选项1']) const columns = ref(['选项1', '选项2', '选项3', '选项4', '选项5']) ``` ::: 当 `columns` 为对象数组时,单项数据结构如下: | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | value | 选项值 | `string \| number` | - | | label | 选项文本 | `string \| number` | - | | disabled | 是否禁用 | `boolean` | `false` | | children | 子选项列表,用于级联模式 | `PickerOption[]` | - | ## 组件状态 ### 禁用选项 通过给选项对象设置 `disabled`,可以禁止某一项被选中。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const value = ref(['选项1']) const columns = ref([ { label: '选项1', value: '选项1' }, { label: '选项2', value: '选项2' }, { label: '选项3', value: '选项3', disabled: true }, { label: '选项4', value: '选项4' } ]) ``` ::: ## 组件变体 ### 立即触发 设置 `immediate-change` 后,手指松开时就会触发 `change` 事件;默认情况下会在滚动动画结束后再触发。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const value = ref(['选项1']) const columns = ref([ { label: '选项1', value: '选项1' }, { label: '选项2', value: '选项2' }, { label: '选项3', value: '选项3' } ]) function handleChange({ selectedValues, selectedLabels, columnIndex }: any) { console.log(selectedValues, selectedLabels, columnIndex) } ``` ::: ### 多列 将 `columns` 设为二维数组即可展示多列选择器,对应的 `v-model` 仍为一维数组,按列顺序保存每一列的选中值。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const value = ref(['中南大学', '软件工程']) const columns = ref([ ['中山大学', '中南大学', '华南理工大学'], ['计算机科学与技术', '软件工程', '通信工程', '法学', '经济学'] ]) ``` ::: ### 多级联动 设置 `cascade` 后,`columns` 应传入树形数据结构。组件会根据当前选中值自动展开后续列。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const value = ref(['110000', '110100', '110102']) const columns = ref([ { label: '北京', value: '110000', children: [ { label: '北京市', value: '110100', children: [ { label: '东城区', value: '110101' }, { label: '西城区', value: '110102' }, { label: '朝阳区', value: '110105' } ] } ] }, { label: '广东省', value: '440000', children: [ { label: '广州市', value: '440100', children: [ { label: '荔湾区', value: '440103' }, { label: '越秀区', value: '440104' }, { label: '海珠区', value: '440105' } ] } ] } ]) ``` ::: ## 特殊用法 ### 自定义字段名 通过 `value-key`、`label-key`、`children-key` 可以适配非标准字段名的数据结构。 ::: code-group ```html ``` ```typescript import { ref } from 'vue' const value = ref([1]) const columns = ref([ { id: 1, text: '选项一' }, { id: 2, text: '选项二' }, { id: 3, text: '选项三' } ]) ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前选中值;单列时通常为长度为 1 的数组,多列与级联时按列顺序保存各列选中值 | `(string \| number)[]` | `[]` | | columns | 选择器数据;可传入一维数组、对象数组、二维数组,级联模式下传入树形数据 | `Array \| Array>` | `[]` | | item-height | 每个选项的高度 | `number` | `44` | | visible-item-count | 可见选项数量 | `number` | `6` | | value-key | 选项对象中值字段对应的键名 | `string` | `'value'` | | label-key | 选项对象中文本字段对应的键名 | `string` | `'label'` | | immediate-change | 是否在手指松开时立即触发 `change` 事件;若不开启,则在滚动动画结束后触发 | `boolean` | `false` | | cascade | 是否开启级联模式;开启后 `columns` 应传入树形数据 | `boolean` | `false` | | children-key | 级联模式下子节点字段对应的键名 | `string` | `'children'` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Methods | 方法名称 | 说明 | 参数 | | --- | --- | --- | | getSelectedOptions | 获取所有列选中项 | - | | getSelectedValues | 获取所有列的选中值 | - | | getColumnsData | 获取所有列数据 | - | | getColumnData | 获取指定列数据 | `columnIndex: number` | | getColumnIndex | 获取指定列的选中下标 | `columnIndex: number` | | getSelectedLabels | 获取所有列选中项的文本 | - | | getSelectedIndex | 获取所有列的选中下标 | - | | resetColumns | 重置列数据 | `columns: PickerOption[] \| PickerOption[][]` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 选中值变化时触发 | `{ selectedValues, selectedOptions, selectedLabels, selectedIndexes, columnIndex }` | | pickstart | 开始滚动选择时触发 | - | | pickend | 结束滚动选择时触发 | - | | update:modelValue | `v-model` 更新时触发 | `value: (string \| number)[]` | ### change 事件参数 | 参数名 | 说明 | 类型 | | --- | --- | --- | | selectedValues | 所有列的选中值数组 | `Array` | | selectedOptions | 所有列的选中项对象数组 | `Array` | | selectedLabels | 所有列的选中文本数组 | `Array` | | selectedIndexes | 所有列的选中下标数组 | `Array` | | columnIndex | 当前发生变化的列索引;单列时为当前选项下标 | `number` | ## Slots 组件未提供插槽。 ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/popover.md' --- # Popover 气泡 常用于展示提示信息或菜单操作。 Popover 的定位规则与 [Tooltip](/component/tooltip.html) 保持一致,支持 12 个方向的弹出位置,并提供内容插槽和菜单模式。 :::warning 因为 `uni-app` 组件无法监听点击自己以外的地方,为了在点击页面其他地方时自动关闭 `popover`,建议使用组件库的 `useQueue` hook(会关闭所有 dropmenu、popover、toast、swipeAction、fab),并在页面根元素上监听点击事件冒泡。 如果存在用户手动点击 `popover` 以外某个地方如按钮弹出 `popover` 的场景,则需要在该元素上加 `@click.stop=""` 阻止事件冒泡到根元素上,避免触发 `closeOutside` 把要手动打开的 `popover` 关闭。 ::: ## 组件类型 ### 普通模式 默认使用 `normal` 模式,直接通过 `content` 展示一段文本内容。 ::: code-group ```html [vue/html] 点击展示 ``` ```ts [typescript] import { ref } from 'vue' import { useQueue } from '@/uni_modules/wot-ui' const { closeOutside } = useQueue() const showBasic = ref(false) ``` ::: ### 菜单模式 设置 `mode="menu"` 后,`content` 需要传入 `PopoverMenuItem[]`。点击菜单项后会自动关闭当前气泡,并触发 `menuclick` 事件。 ::: code-group ```html [vue/html] 列表 ``` ```ts [typescript] import { ref } from 'vue' import { useToast } from '@/uni_modules/wot-ui' import type { PopoverMenuItem } from '@/uni_modules/wot-ui/components/wd-popover/types' const { show: showToast } = useToast() const showMenu = ref(false) const menuItems: PopoverMenuItem[] = [ { iconClass: 'check', content: '全部标记已读' }, { iconClass: 'delete', content: '清空最近会话' }, { iconClass: 'subscribe', content: '消息订阅设置' }, { iconClass: 'scan', content: '消息异常检测' } ] function handleMenuClick({ item }: { item: PopoverMenuItem }) { showToast('选择了' + item.content) } ``` ::: ### PopoverMenuItem `mode="menu"` 时,`content` 数组内每一项的数据结构如下: | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | content | 菜单项文案 | string | - | | iconClass | 菜单项图标类名,不设置时只展示标题 | string | - | ## 组件状态 ### 受控显隐 通过 `v-model` 控制 Popover 的显示与隐藏,外部按钮和触发目标都可以驱动显隐状态变化。 ::: code-group ```html [vue/html] {{ showControlled ? '关闭' : '打开' }} 触发目标 ``` ```ts [typescript] import { ref } from 'vue' const showControlled = ref(false) ``` ::: ### 禁用 设置 `disabled` 后,点击触发目标不会打开气泡。 ```html 禁用状态 ``` ## 组件变体 ### 弹出位置 通过 `placement` 指定弹出位置,支持 `top`、`bottom`、`left`、`right` 及各自的 `start`、`end` 对齐方式。 ::: code-group ```html [vue/html] {{ item }} {{ placement }} ``` ```ts [typescript] import { ref } from 'vue' import type { PlacementType } from '@/uni_modules/wot-ui/components/wd-popover/types' const placement = ref('bottom') const showPlacement = ref(false) const placementItems = [ 'bottom', 'bottom-start', 'bottom-end', 'top', 'top-start', 'top-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end' ] as const ``` ::: ## 组件样式 ### 内容插槽 通过 `content` 插槽可以自定义气泡内容结构和样式,不需要额外开启开关属性。 ::: code-group ```html [vue/html] 点击展示 ``` ```ts [typescript] import { ref } from 'vue' const showCustom = ref(false) ``` ```scss [scss] .pop-content { position: relative; z-index: 500; border-radius: 4px; background: #fff; color: #8268de; font-weight: 600; padding: 10px; width: 150px; } ``` ::: ### 显示关闭按钮 设置 `show-close` 后,会在气泡内容区域右上角显示关闭按钮。 ```html 显示关闭按钮 ``` ## 特殊样式 ### 动态内容与位置更新 当使用 `content` 插槽且插槽内容尺寸发生变化时,可以通过组件实例的 `updatePosition` 重新测量并更新定位。 ::: code-group ```html [vue/html] 动态内容 ``` ```ts [typescript] import { nextTick, ref } from 'vue' import type { PlacementType, PopoverInstance } from '@/uni_modules/wot-ui/components/wd-popover/types' const placement = ref('bottom') const showDynamic = ref(false) const dynamicWidth = ref(150) const popoverRef = ref(null) function changeSize() { dynamicWidth.value = dynamicWidth.value === 150 ? 250 : 150 nextTick(() => { popoverRef.value?.updatePosition() }) } ``` ```scss [scss] .status { margin-bottom: 10px; } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 是否显示气泡 | `boolean` | `false` | | content | 显示内容,`normal` 模式下为字符串,`menu` 模式下为 `PopoverMenuItem[]`,也可以通过 `content` 插槽传入 | `string \| PopoverMenuItem[]` | - | | mode | 当前显示模式,可选值为 `normal`、`menu` | `PopoverMode` | `normal` | | placement | 弹出位置,可选值为 `top`、`top-start`、`top-end`、`bottom`、`bottom-start`、`bottom-end`、`left`、`left-start`、`left-end`、`right`、`right-start`、`right-end` | `PlacementType` | `bottom` | | offset | 偏移量,支持 number、number\[] 或 `{ x: number, y: number }` | `PopoverOffset` | `0` | | visible-arrow | 是否显示箭头 | `boolean` | `true` | | disabled | 是否禁用 | `boolean` | `false` | | show-close | 是否显示关闭按钮 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | | custom-arrow | 箭头节点自定义类名 | `string` | `''` | | custom-pop | 气泡内容容器自定义类名 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | open | 气泡显示时触发 | - | | close | 气泡隐藏时触发 | - | | change | 显隐状态变化时触发 | `{ show: boolean }` | | menuclick | `menu` 模式下点击选项时触发 | `{ item: PopoverMenuItem; index: number }` | ## Methods | 方法名 | 说明 | 参数 | | --- | --- | --- | | open | 打开气泡 | - | | close | 关闭气泡 | - | | updatePosition | 重新测量内容尺寸并更新定位 | - | ## Slots | 名称 | 说明 | 参数 | | --- | --- | --- | | default | 触发器区域内容 | - | | content | 自定义气泡内容 | - | --- --- url: 'https://wot-ui.cn/component/popup.md' --- # Popup 弹出层 弹出层组件,用于展示弹窗、信息提示等内容。 ## 组件类型 ### 基本用法 `v-model` 为绑定值,表示是否展示弹出层。 ```html 弹弹弹 ``` ```css .custom-txt { color: black; width: 400rpx; height: 400rpx; display: flex; justify-content: center; align-items: center; font-size: 40rpx; border-radius: 32rpx; } ``` ### 弹出位置 设置 `position`,可选值为 `center`、`top`、`right`、`bottom`、`left`,默认值为 `center`。 ```html ``` ## 组件状态 ### 关闭按钮 设置 `closable` 属性。 ```html ``` ### 禁用遮罩点击 通过设置 `close-on-click-modal="false"`,可以禁用点击遮罩层关闭弹出层。 ```html ``` ### 禁用遮罩 通过设置 `modal="false"`,可以关闭遮罩层,使底层内容仍可交互。 ```html ``` ## 组件样式 ### 底部安全区 通过设置 `safe-area-inset-bottom="true"`,可以确保底部弹层在刘海屏机型上不会被安全区域遮挡。 ```html ``` ## 特殊样式 ### 锁定滚动 `lock-scroll` 用于锁定背景滚动。在小程序和 APP 中,如果还需要彻底防止页面滚动穿透,推荐配合 `page-meta` 控制页面 `overflow`。 ```html ``` :::tip 提示 H5 端默认已经处理滚动锁定,一般不需要额外处理滚动穿透。 ::: ### 嵌套弹窗与 root-portal 当使用 `root-portal` 属性时,弹出层会从当前页面结构中脱离出来,用于避免父元素的 `transform`、`filter` 等样式影响弹层的 fixed 定位。 不同平台的实现方式如下: * H5:使用 Vue 3 的 teleport 特性 * APP:使用 renderjs 将元素移动到 uni-app 根节点 * 微信小程序 / 支付宝小程序:使用 root-portal 组件 * 其他平台:不支持此能力 ```html 打开传送子弹窗 这个子弹窗会脱离父层级渲染 ``` :::tip 提示 `root-portal` 主要用于解决复杂布局中的层级和定位问题,建议在有明确需要时再开启。 ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 弹出层是否显示 | `boolean` | `false` | | transition | 动画类型,参见 `wd-transition` 组件的 `name` | `TransitionName` | - | | closable | 是否显示关闭按钮 | `boolean` | `false` | | position | 弹出位置,可选值为 `center`、`top`、`right`、`bottom`、`left` | `string` | `center` | | close-on-click-modal | 点击遮罩是否关闭弹出层 | `boolean` | `true` | | duration | 动画持续时间 | `number \| boolean` | `300` | | modal | 是否显示遮罩 | `boolean` | `true` | | z-index | 弹层层级 | `number` | `10` | | hide-when-close | 关闭时是否隐藏弹层节点 | `boolean` | `true` | | modal-style | 自定义遮罩样式 | `string` | - | | safe-area-inset-bottom | 底部弹层是否适配底部安全区 | `boolean` | `false` | | lazy-render | 弹层内容是否懒渲染 | `boolean` | `true` | | lock-scroll | 是否锁定背景滚动,锁定后蒙层内内容也将无法滚动 | `boolean` | `true` | | root-portal | 是否从页面结构中脱离出来,用于解决 fixed 失效问题 | `boolean` | `false` | | round | 是否开启圆角,开启后根据弹出位置自动适配(底部弹出→上圆角,顶部弹出→下圆角,居中→四圆角) | `boolean` | `false` | | custom-class | 自定义根节点类名 | `string` | - | | custom-style | 自定义弹层样式 | `string` | - | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | close | 弹出层关闭时触发 | - | | click-modal | 点击遮罩时触发 | - | | before-enter | 进入前触发 | - | | enter | 进入时触发 | - | | after-enter | 进入后触发 | - | | before-leave | 离开前触发 | - | | leave | 离开时触发 | - | | after-leave | 离开后触发 | - | ## Slots | name | 说明 | | --- | --- | | default | 弹层内容 | --- --- url: 'https://wot-ui.cn/component/progress.md' --- # Progress 进度条 用于展示操作的当前进度。 ## 组件类型 ### 基本用法 设置百分比 `percentage`。 ```html ``` ### 内置百分比 通过 `percent-position` 配置百分比显示在进度条内部,并设置对齐方式。 ```html ``` ## 组件状态 ### 状态 设置 `status`,告知用户当前状态和预期。 ```html ``` ## 组件样式 ### 隐藏进度文字 设置 `hide-text` 隐藏进度文字。 ```html ``` ### 修改颜色 设置 `color` 修改进度条颜色。 ```html ``` ### 颜色数组 `color` 也可以设置为颜色数组或 `ProgressColor[]`。当传入字符串数组时,组件会自动计算每段颜色对应的进度边界。 ```html ``` ```ts import type { ProgressColor } from '@/uni_modules/wot-ui/components/wd-progress/types' const colorObject: ProgressColor[] = [ { color: 'yellow', percentage: 30 }, { color: 'red', percentage: 60 }, { color: 'blue', percentage: 80 }, { color: 'black', percentage: 90 } ] ``` ## 特殊样式 ### 动态控制 通过修改 `percentage` 绑定值,可以实现动态进度控制。 ```html -10 +10 ``` ```ts const percentage = ref(50) function add() { percentage.value = Math.min(percentage.value + 10, 100) } function reduce() { percentage.value = Math.max(percentage.value - 10, 0) } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | percentage | 进度数值,最大值为 `100` | `number` | `0` | | hide-text | 是否隐藏进度文字 | `boolean` | `false` | | color | 进度条颜色,可选值为 `string`、`string[]`、`ProgressColor[]` | `string \| string[] \| ProgressColor[]` | - | | status | 进度条状态,可选值为 `success`、`danger`、`warning` | `string` | - | | duration | 进度增加 `1%` 所需毫秒数 | `number` | `30` | | percent-position | 百分比显示位置配置,`type` 可选 `inner`、`outer`,`align` 可选 `left`、`center`、`right` | `PercentPosition` | `{ align: 'right', type: 'outer' }` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ### ProgressColor | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | color | 颜色值 | `string` | - | | percentage | 颜色生效的进度阈值 | `number` | - | ### PercentPosition | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | type | 百分比显示位置,可选值为 `inner`、`outer` | `string` | `'outer'` | | align | 百分比文本对齐方式,可选值为 `left`、`center`、`right` | `string` | `'right'` | --- --- url: 'https://wot-ui.cn/component/radio.md' --- # Radio 单选框 单选框用于在一组备选项中进行单选。 ## 组件类型 ### 基本用法 `v-model` 为绑定值,即当前选中的 `wd-radio` 的 `value`。 ```html 单选框 1 单选框 2 单选框 3 ``` ```ts const value = ref(1) ``` ### 按钮形态 设置 `type="button"`,可切换为按钮式单选。 ```html 选项一 选项二 ``` ## 组件状态 ### 禁用 可以在 `wd-radio-group` 上设置 `disabled`,统一禁用整组单选框;也可以在单个 `wd-radio` 上单独设置。 ```html 选项一 选项二 ``` ### 只读状态 设置 `readonly` 后,单选项仍然展示当前值,但不会响应点击切换。 ```html 选项一 选项二 ``` ### 允许取消选中 设置 `allow-uncheck` 后,点击当前已选中的单选项可以取消选中。 ```html 支持取消选中 支持取消选中 ``` ## 组件样式 ### 图标位置 设置 `placement` 控制图标显示在文本左侧还是右侧。 ```html 单选框 1 单选框 2 ``` ### 修改选中的颜色 设置 `checked-color` 修改选中状态的图标颜色。 ```html 选项一 选项二 ``` ### 修改未选中颜色 设置 `unchecked-color` 修改未选中状态的图标颜色。 ```html 选项一 选项二 ``` ## 特殊样式 ### Props 优先级 单个 `wd-radio` 上设置的属性优先级高于 `wd-radio-group`。 ```html 选项一 选项二 选项三 ``` ### 结合 Cell 使用 可以将 `wd-radio` 放入 `wd-cell` 的右侧区域,配合整行点击实现列表选择效果。 ```html ``` ### 自定义图标 通过 `icon` 插槽可自定义选中与未选中图标。 ```html 自定义图标 ``` ## 布局能力 ### 同行展示 设置 `direction="horizontal"`,可让单选框同行排列。 ```html 单选框 1 单选框 2 ``` ## RadioGroup Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前选中的值,会自动匹配对应 `wd-radio` 的 `value` | `string \| number \| boolean` | - | | type | 单选框类型,可选值为 `circle`、`dot`、`square`、`button` | `string` | `circle` | | checked-color | 选中状态的图标颜色 | `string` | - | | unchecked-color | 未选中状态的图标颜色 | `string` | - | | disabled | 是否禁用整组单选框 | `boolean` | `false` | | readonly | 是否只读 | `boolean` | `false` | | placement | 图标位置,可选值为 `left`、`right` | `string` | `left` | | direction | 布局方向,可选值为 `horizontal`、`vertical` | `string` | `vertical` | | allow-uncheck | 是否允许取消当前已选中的值 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## RadioGroup Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 绑定值变化时触发 | `{ value }` | ## Radio Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | value | 单选项的值,会与 `wd-radio-group` 的 `v-model` 匹配 | `string \| number \| boolean` | - | | type | 单选框类型,可选值为 `circle`、`dot`、`square`、`button` | `string` | 继承自 `wd-radio-group` | | checked-color | 选中状态的图标颜色 | `string` | 继承自 `wd-radio-group` | | unchecked-color | 未选中状态的图标颜色 | `string` | 继承自 `wd-radio-group` | | disabled | 是否禁用当前单选项 | `boolean` | 继承自 `wd-radio-group` | | readonly | 是否只读 | `boolean` | 继承自 `wd-radio-group` | | placement | 图标位置,可选值为 `left`、`right` | `string` | 继承自 `wd-radio-group` | | direction | 布局方向,可选值为 `horizontal`、`vertical` | `string` | 继承自 `wd-radio-group` | | custom-label-class | 自定义文本节点类名 | `string` | - | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Slots | 组件 | name | 说明 | 参数 | | --- | --- | --- | --- | | wd-radio | default | 单选项文本内容 | - | | wd-radio | icon | 自定义图标内容 | `{ isChecked }` | --- --- url: 'https://wot-ui.cn/component/rate.md' --- # Rate 评分 用于快速评价,或展示评分结果。 ## 组件类型 ### 基本用法 设置 `v-model` 绑定当前分数,`num` 用于设置总分,默认值为 `5`。 ```html ``` ```ts const value = ref(5) function handleChange({ value }: { value: number }) { console.log(value) } ``` ## 组件状态 ### 只读 设置 `readonly` 属性。 ```html ``` ### 禁用 设置 `disabled` 属性。 ```html ``` ## 组件样式 ### 修改选中颜色 可以通过 `active-color` 修改选中图标颜色,也支持传入双色数组实现分段颜色。 ```html ``` ### 修改图标与颜色 可以通过 `icon`、`active-icon` 分别设置未选中和选中图标,结合 `active-color` 自定义视觉风格。 ```html ``` ### 修改大小与间隔 通过 `size` 修改图标大小,`space` 修改图标间距。 ```html ``` ## 特殊样式 ### 允许半选 设置 `allow-half` 属性。 ```html ``` ### 允许清空评分 设置 `clearable` 属性后,再次点击当前最小分值时可清空评分。与 `allow-half` 组合时,可清空半星评分。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前分数 | `number \| null` | `null` | | num | 评分最大值 | `number` | `5` | | readonly | 是否只读 | `boolean` | `false` | | size | 图标大小 | `string` | - | | space | 图标间距 | `string \| number` | - | | color | 未选中图标颜色 | `string` | - | | active-color | 选中图标颜色,支持 `string` 或 `string[]` | `string \| string[]` | - | | icon | 未选中图标类名 | `string` | `'star-fill'` | | active-icon | 选中图标类名 | `string` | `'star-fill'` | | disabled | 是否禁用 | `boolean` | `false` | | allow-half | 是否允许半选 | `boolean` | `false` | | clearable | 是否允许再次点击后清除 | `boolean` | `false` | | block | 是否块级显示 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 点击图标修改分值时触发 | `{ value }` | --- --- url: 'https://wot-ui.cn/component/resize.md' --- # Resize 监听元素尺寸变化 当组件包裹的文档流尺寸发生变化时,触发 `resize` 事件。一般用于监听内容更新引起的尺寸和位置信息变化,再据此重新进行布局计算。 ## 组件类型 ### 基本用法 不要给 `wd-resize` 自身增加额外布局样式,而是把需要被监听的内容放在默认插槽中。 ::: code-group ```html [vue] ``` ```ts [ts] import { onReady } from '@dcloudio/uni-app' import { ref } from 'vue' const width = ref('') const height = ref('') onReady(() => { setTimeout(() => { width.value = '100px' height.value = '100px' }, 1500) }) function handleResize(detail: Record) { const { height, width, top, right, bottom, left } = detail } ``` ::: ## Resize Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | custom-style | 自定义根节点样式 | `string` | `''` | | custom-class | 自定义根节点样式类 | `string` | `''` | | custom-container-class | 自定义容器样式类 | `string` | `''` | ## Resize Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | resize | 尺寸发生变化时触发 | { width: number; height: number; top: number; right: number; bottom: number; left: number } | ## Resize Slots | 名称 | 说明 | | --- | --- | | default | 需要监听尺寸变化的内容 | --- --- url: 'https://wot-ui.cn/component/root-portal.md' --- # Root Portal 根节点传送 是否从页面中脱离出来,用于解决各种 fixed 失效问题,主要用于制作弹窗、弹出层等。 :::tip 提示 根节点传送组件仅支持`微信小程序`、`支付宝小程序`、`APP`和`H5`平台,组件会自动根据平台选择合适的实现方式: * **H5 端**:使用 `teleport` 特性 * **微信小程序和支付宝小程序**:使用 `root-portal` 组件 * **App 端**:使用 renderjs 实现 * **其他平台**:不支持此功能 该功能主要用于解决复杂布局中弹窗的层级和定位问题,在需要时才建议使用。 ::: ## 组件类型 ### 基本用法 使用 `wd-root-portal` 将内容渲染到根节点,避免被父组件样式影响。 ```html 显示弹窗 这是一个全局弹窗 关闭 ``` ```scss .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; } .modal-content { background-color: #fff; padding: 24px; border-radius: 12px; width: 280px; text-align: center; } ``` ## 特殊样式 ### 与弹层组件配合使用 部分弹层组件本身支持 `root-portal` 属性,例如 `wd-select-picker`。这类场景仍然需要由外部触发器控制弹层显隐,再通过组件属性开启根节点传送能力。 ```html ``` ```typescript import { ref } from 'vue' const showPicker = ref(false) const value = ref([]) const selectedLabel = ref('') const columns = ref([ { value: '101', label: '男装' }, { value: '102', label: '奢侈品' }, { value: '103', label: '女装' } ]) function handleConfirm({ value }: { value: string[] }) { selectedLabel.value = columns.value .filter((item) => value.includes(item.value)) .map((item) => item.label) .join('、') } ``` ## Slots | name | 说明 | | --- | --- | | default | 默认插槽,用于渲染传送内容 | --- --- url: 'https://wot-ui.cn/component/search.md' --- # Search 搜索框 搜索框组件,支持输入框聚焦、失焦、输入、搜索、取消、清空事件。 ## 组件类型 ### 基本用法 `v-model` 设置输入框绑定值,`change` 监听输入事件,`search` 监听搜索事件,`cancel` 监听取消事件,`clear` 监听清空事件。 ```html ``` ```ts const value = ref('') function search({ value }: { value: string }) { console.log('搜索', value) } function clear() { console.log('重置') } function cancel({ value }: { value: string }) { console.log('取消', value) } function change({ value }: { value: string }) { console.log('输入', value) } ``` ## 组件状态 ### 自动聚焦 设置 `focus` 属性,组件挂载后自动聚焦。 ```html ``` ### 清空后自动聚焦 设置 `focus-when-clear`,点击清空按钮后重新聚焦输入框。 ```html ``` ### 禁用并隐藏取消按钮 设置 `disabled` 和 `hide-cancel`。可用于跳转到独立搜索页的入口场景。 ```html ``` ## 组件变体 ### 样式变体 通过 `variant` 切换不同视觉样式,可选值为 `plain`、`filled`、`light`。 ```html ``` ## 组件样式 ### 输入框提示文案靠左 设置 `placeholder-left` 属性。 ```html ``` ### 设置最大长度 通过 `maxlength` 限制输入框最大长度,`-1` 表示不限制。 ```html ``` ### 自定义文案 通过 `placeholder` 修改占位文本,`cancel-txt` 修改取消按钮文案。 ```html ``` ## 特殊样式 ### 自定义左侧插槽 通过 `prefix` 插槽自定义搜索框左侧内容。 ```html ``` ```typescript const searchType = ref('全部') const value = ref('') const menu = ref([ { content: '全部' }, { content: '订单号' }, { content: '退款单号' } ]) function changeSearchType({ item }) { searchType.value = item.content } ``` ```scss .search-type { position: relative; height: 30px; line-height: 30px; padding: 0 8px 0 16px; } .search-type::after { position: absolute; content: ''; width: 1px; right: 0; top: 5px; bottom: 5px; background: rgba(0, 0, 0, 0.25); } .search-type { :deep(.icon-arrow) { display: inline-block; font-size: 20px; vertical-align: middle; } } ``` ### 自定义输入框右侧图标 ```html ``` ### 自定义右侧插槽 ```html ``` ### 多种插槽组合 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 输入框内容,双向绑定 | `string` | `''` | | custom-input-class | 自定义输入框类名 | `string` | `''` | | placeholder | 搜索框占位文本 | `string` | `'搜索'` | | cancel-txt | 搜索框右侧文本 | `string` | `'取消'` | | variant | 搜索框变体,可选值为 `plain`、`filled`、`light` | `string` | `'plain'` | | hide-cancel | 是否隐藏右侧文本 | `boolean` | `false` | | disabled | 是否禁用搜索框 | `boolean` | `false` | | maxlength | 原生属性,设置最大长度,`-1` 表示无限制 | `number \| string` | `-1` | | placeholder-left | placeholder 是否左对齐 | `boolean` | `false` | | focus | 是否自动聚焦 | `boolean` | `false` | | focus-when-clear | 是否在点击清空按钮后聚焦输入框 | `boolean` | `false` | | placeholder-style | 原生属性,指定 placeholder 的样式,目前仅支持 `color`、`font-size` 和 `font-weight` | `string` | - | | placeholder-class | 原生属性,指定 placeholder 的样式类 | `string` | `''` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | focus | 输入框聚焦事件 | `{ value }` | | blur | 输入框失焦事件 | `{ value }` | | search | 输入框搜索事件 | `{ value }` | | clear | 点击清空按钮时触发 | - | | cancel | 点击右侧文本时触发 | `{ value }` | | change | 输入框内容变化时触发 | `{ value }` | | click | 禁用状态下点击组件时触发 | - | ## Slots | name | 说明 | | --- | --- | | prefix | 输入框左侧自定义内容 | | input-suffix | 输入框内部右侧自定义内容 | | suffix | 输入框右侧自定义内容 | --- --- url: 'https://wot-ui.cn/component/segmented.md' --- # Segmented 分段器 分段器用于展示多个选项并允许用户选择其中单个选项。 ## 何时使用 * 用于展示多个选项并允许用户选择其中单个选项; * 当切换选中选项时,关联区域的内容会发生变化。 ## 组件类型 ### 基本用法 通过 `options` 设置选项列表,通过 `v-model:value` 绑定当前选中项。 ```vue ``` ```ts const list = ref(['评论', '点赞', '贡献', '打赏']) const current = ref('点赞') ``` ## 组件状态 ### 禁用 设置 `disabled` 属性禁用整个分段器。 ```html ``` ## 组件变体 ### 轮廓主题 通过 `theme="outline"` 切换为轮廓样式。 ```html ``` ## 组件样式 ### 自定义渲染分段器标签 使用插槽 `label` 可以自定义渲染分段器的标签内容。 ```html ``` ```ts const list = ref([ { value: '李雷', disabled: false, payload: { avatar: 'https://wot-ui.cn/assets/redpanda.jpg' } }, { value: '韩梅梅', disabled: false, payload: { avatar: 'https://wot-ui.cn/assets/capybara.jpg' } } ]) ``` ```scss .section { width: 100%; padding: 0 24rpx; box-sizing: border-box; &-slot { padding: 4px; } } ``` ## 特殊样式 ### 带振动效果的分段器 设置 `vibrate-short` 后,切换选项时会触发短振动反馈。 ```html ``` ### 在弹出框中使用 微信小程序端,在弹出框中使用本组件时,需要调用 `updateActiveStyle` 方法更新分段器样式,参见[常见问题](/guide/common-problems.html#%E4%B8%BA%E4%BB%80%E4%B9%88%E5%9C%A8%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%B8%8A%E4%BD%BF%E7%94%A8popup%E3%80%81actionsheet%E3%80%81dropdownitem%E7%AD%89%E5%BC%B9%E5%87%BA%E6%A1%86%E7%BB%84%E4%BB%B6%E5%8C%85%E8%A3%B9slider%E3%80%81tabs%E7%AD%89%E7%BB%84%E4%BB%B6%E6%97%B6-slider%E3%80%81tabs%E8%A1%A8%E7%8E%B0%E5%BC%82%E5%B8%B8)。 ```html 打开弹窗 在弹出框中使用 ``` ```ts const list = ref(['评论', '点赞', '贡献', '打赏']) const current = ref('点赞') const segmentedRef = ref() // 获取分段器实例 const showPopup = ref(false) // 控制popup显示 /** * 点击按钮打开popup */ function handleClick() { showPopup.value = true } /** * popup打开后更新分段器样式 */ function handlePopupShow() { segmentedRef.value?.updateActiveStyle() } ``` ```css .title { display: flex; font-size: 32rpx; align-items: center; justify-content: center; padding: 24rpx 0; } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | value / v-model:value | 当前选中的值 | `string \| number` | - | | disabled | 是否禁用分段器 | `boolean` | `false` | | options | 数据集合 | `string[] \| number[] \| SegmentedOption[]` | `[]` | | theme | 分段器主题,可选值为 `card`、`outline` | `string` | `'card'` | | vibrate-short | 切换选项时是否触发短振动 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ### SegmentedOption | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | value | 选项值 | `string \| number` | - | | disabled | 是否禁用该选项 | `boolean` | `false` | | payload | 附加数据,可用于插槽渲染 | `any` | - | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 选项切换时触发 | `SegmentedOption` | | click | 选项点击时触发 | `SegmentedOption` | ## Methods | 方法名 | 说明 | 类型 | | --- | --- | --- | | updateActiveStyle | 更新滑块偏移量,参数 `animation` 用于控制是否启用动画,默认开启 | `(animation?: boolean) => void` | ## Slots | name | 说明 | 参数 | | --- | --- | --- | | label | 选项标签内容 | `{ option: SegmentedOption }` | --- --- url: 'https://wot-ui.cn/component/select-picker.md' --- # SelectPicker 单复选选择器 用于从一组选项中进行单选或多选,通常配合外部单元格或按钮控制弹层显示。 ## 组件类型 ### 基本用法 默认 `type` 为 `checkbox`,`v-model` 的值类型为数组。通常配合 `v-model:visible` 控制弹层开关。 ```html ``` ```ts const columns = ref([ { value: '101', label: '男装' }, { value: '102', label: '奢侈品' }, { value: '103', label: '女装' } ]) const value = ref(['101']) const show = ref(false) function handleConfirm({ value }: { value: string[] }) { console.log(value) } ``` ### 类型切换 设置 `type="radio"` 开启单选模式,此时 `v-model` 的值类型为 `string`、`number` 或 `boolean`。 ```html ``` ## 组件状态 ### 禁用选项 选项数据支持 `disabled` 字段,用于禁用某一项。 ```html ``` ```ts const columns = ref([ { value: '101', label: '男装', disabled: true }, { value: '102', label: '奢侈品' }, { value: '103', label: '女装' } ]) ``` ### 加载中 设置 `loading` 后会在内容区域显示加载状态。 ```html ``` ## 组件样式 ### 设置标题 通过 `title` 自定义弹层标题。 ```html ``` ### 可搜索 设置 `filterable` 开启本地搜索;单选和多选模式都支持。 ```html ``` ## 特殊样式 ### 选项变化事件 选择器内部选项发生变化时,会触发 `change` 事件。 ```html ``` ```ts function handleChange({ value }: { value: string[] }) { console.log(value) } ``` ### 确定前校验 设置 `before-confirm`,可在点击确认按钮前执行同步或异步校验。返回 `false` 或 `Promise` 时不会关闭弹层。 ```html ``` ```ts const beforeConfirm = (value: string[]) => { return new Promise((resolve) => { if (value.length > 0) { resolve(false) } else { resolve(true) } }) } ``` ### 自动完成 `radio` 模式下可通过 `show-confirm="false"` 隐藏确认按钮,选中后自动完成。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 选中项,`checkbox` 时为数组,`radio` 时为 `string`、`number` 或 `boolean` | `string \| number \| boolean \| (string \| number \| boolean)[]` | - | | visible / v-model:visible | 控制弹层显示状态 | `boolean` | `false` | | title | 弹出层标题 | `string` | `'选择器'` | | checked-color | 单选框或复选框选中颜色 | `string` | - | | min | 最小选中数量,仅 `checkbox` 生效 | `number` | `0` | | max | 最大选中数量,`0` 表示不限制,仅 `checkbox` 生效 | `number` | `0` | | select-size | 选择器内部选项尺寸 | `string` | - | | loading | 是否显示加载状态 | `boolean` | `false` | | loading-color | 加载图标颜色 | `string` | `'#4D80F0'` | | close-on-click-modal | 点击遮罩是否关闭 | `boolean` | `true` | | columns | 选择器数据,一维数组 | `Record[]` | `[]` | | type | 选择器类型,可选值为 `checkbox`、`radio` | `string` | `'checkbox'` | | value-key | 选项对象中值字段的 key | `string` | `'value'` | | label-key | 选项对象中展示文本字段的 key | `string` | `'label'` | | confirm-button-text | 确认按钮文案 | `string` | `'确认'` | | before-confirm | 确认前校验函数,接收当前选中值,返回 `boolean` 或 `Promise` | `function` | - | | z-index | 弹层层级 | `number` | `15` | | safe-area-inset-bottom | 是否适配底部安全区 | `boolean` | `true` | | filterable | 是否支持本地搜索 | `boolean` | `false` | | filter-placeholder | 搜索框占位符 | `string` | `'搜索'` | | scroll-into-view | 重新打开时是否滚动到选中项 | `boolean` | `true` | | custom-content-class | 自定义弹层内容区域类名 | `string` | `''` | | show-confirm | 是否显示确认按钮,仅 `radio` 模式生效 | `boolean` | `true` | | root-portal | 是否从页面结构中脱离出来,用于解决 fixed 失效问题 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## 选项数据结构 | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | value | 选项值 | `string \| number \| boolean` | - | | label | 选项文案 | `string` | - | | disabled | 是否禁用该选项 | `boolean` | `false` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 选择器内部选项变化时触发 | `{ value }` | | cancel | 点击关闭按钮或遮罩关闭时触发 | - | | confirm | 点击确认时触发 | `{ value, selectedItems }` | | open | 弹层打开时触发 | - | | close | 弹层关闭时触发 | - | ## Methods | 方法名 | 说明 | 类型 | | --- | --- | --- | | open | 打开弹层 | `() => void` | | close | 关闭弹层 | `() => void` | --- --- url: 'https://wot-ui.cn/component/sidebar.md' --- # Sidebar 侧边导航 垂直展示的导航栏,用于在不同内容区域之间进行切换。 ## 组件类型 ### 基础用法 通过 `v-model` 绑定当前选中项的值。 ```html ``` ```ts const active = ref(0) ``` ## 组件状态 ### 徽标提示 设置 `is-dot` 可展示红点徽标;设置 `badge` 或 `badge-props` 可展示数字徽标。 ```html ``` ### 禁用与异步切换 设置 `disabled` 可禁用当前选项;设置 `before-change` 可在切换前执行同步或异步逻辑。 ```html ``` ```ts import type { SidebarBeforeChange } from '@/uni_modules/wot-ui/components/wd-sidebar/types' const beforeChange: SidebarBeforeChange = (value) => { return new Promise((resolve) => { setTimeout(() => resolve(true), 2000) }) } ``` ## 特殊样式 ### 锚点用法示例 sidebar 可以与 `scroll-view` 结合,实现长内容页的锚点切换。仓库中的示例可参考 `src/subPages/sidebar/demo1.vue`。 ### 切换页面用法示例 sidebar 也可以作为左侧目录,右侧内容区按当前选中项整屏切换。仓库中的示例可参考 `src/subPages/sidebar/demo2.vue`。 ### 自定义图标示例 设置 `wd-sidebar-item` 的 `icon` 属性,可在导航项中显示不同图标。仓库中的示例可参考 `src/subPages/sidebar/demo3.vue`。 ## Sidebar Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | model-value / v-model | 当前激活项的值 | `string \| number` | `0` | | before-change | 切换前钩子,接收目标值,返回 `boolean` 或 `Promise` | `function` | - | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Sidebar Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 激活项切换时触发 | `{ value, label }` | ## Sidebar Slots | name | 说明 | | --- | --- | | default | SidebarItem 列表 | ## Sidebar 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式 | ## SidebarItem Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | label | 当前选项标题 | `string` | - | | value | 当前选项值,唯一标识 | `string \| number` | - | | badge | 徽标显示值 | `string \| number` | - | | badge-props | 自定义徽标属性,会透传给 Badge 组件 | `Partial` | - | | icon | 图标名称 | `string` | - | | is-dot | 是否显示点状徽标 | `boolean` | `false` | | max | 徽标最大值 | `number` | `99` | | disabled | 是否禁用当前选项 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## SidebarItem Slots | name | 说明 | | --- | --- | | icon | 自定义图标内容 | --- --- url: 'https://wot-ui.cn/component/signature.md' --- # Signature 签名 用于签名场景,基于 Canvas 实现的签名组件,支持导出图片、历史记录、笔锋效果、自定义底部操作等能力。 :::tip 提醒 如果遇到导出图片不清晰,可以将 `export-scale` 设置为 `2` 以上。 ::: ## 组件类型 ### 基础用法 设置 `@confirm` 监听确认事件,可在确认后获取签名结果。 ```html ``` ```ts import type { SignatureResult } from '@/uni_modules/wot-ui/components/wd-signature/types' function handleConfirm(result: SignatureResult) { if (result.success) { uni.previewImage({ urls: [result.tempFilePath] }) } } ``` ### 历史记录 设置 `enable-history` 后,可使用撤销与恢复能力。 ```html ``` ## 组件变体 ### 笔锋模式 设置 `pressure` 开启压感笔锋效果。 ```html ``` ### 笔锋模式结合历史记录 签名组件支持同时开启 `pressure` 与 `enable-history`,用于更完整的签字场景。 ```html ``` ## 组件样式 ### 自定义底部按钮 设置 `footer` 插槽后,可完全自定义底部操作区。 ```html ``` ```ts const disabled = ref(true) ``` ### 自定义画笔 通过 `pen-color`、`line-width` 设置画笔颜色与宽度。 ```html ``` ## 特殊样式 ### 弹窗中使用 签名组件可以与 `wd-popup` 结合使用,建议在弹窗展示完成后调用实例的 `init` 方法完成初始化。 ::: code-group ```html [vue] 打开签名板 ``` ```ts [ts] import { ref } from 'vue' import type { SignatureInstance, SignatureResult } from '@/uni_modules/wot-ui/components/wd-signature/types' const showPopup = ref(false) const signatureRef = ref() function handlePopupConfirm(result: SignatureResult) { showPopup.value = false if (result.success) { uni.previewImage({ urls: [result.tempFilePath] }) } } ``` ::: :::tip 提示 弹窗中使用签名板时,建议: 1. 开启 `closable` 显示关闭按钮。 2. 设置 `safe-area-inset-bottom` 适配底部安全区。 3. 使用 `custom-style` 调整弹窗内边距,为关闭按钮留出空间。 4. 在弹窗的 `after-enter` 事件中调用签名板的 `init` 方法,确保正确初始化。 ::: ### 横屏签名 支持以下两种横屏签名实现方案: #### 1. 通用横屏方案 (推荐) 通过自定义布局和按钮旋转实现横屏效果,适用于所有平台。 :::tip 实现说明 通用横屏方案特点: 1. 使用 fixed 布局配合旋转实现左侧垂直按钮栏 2. 通过 footer 插槽自定义操作按钮 3. 使用 transform 实现按钮的旋转效果 4. 适用于所有平台,实现方式一致 5. 建议使用 inited 变量配合延迟加载避免画布初始化问题 ::: ::: code-group ```html [vue] ``` ```ts [ts] import { pause } from '@/uni_modules/wot-ui/common/util' const height = ref(0) const width = ref(0) const inited = ref(false) onMounted(() => { const { windowWidth, windowHeight } = uni.getSystemInfoSync() width.value = windowWidth - 48 height.value = windowHeight - 48 pause(100).then(() => { inited.value = true }) }) ``` ```scss [css] .landscape-signature { height: 100vh; // #ifdef H5 height: calc(100vh - 44px); // #endif background: #fff; position: relative; padding: 24px 0; padding-left: 48px; box-sizing: border-box; .custom-actions { position: fixed; left: 0; top: 50%; width: 48px; transform: translateY(-50%) rotate(90deg); transform-origin: center; z-index: 10; .button-group { display: flex; flex-direction: row; gap: 12px; white-space: nowrap; width: max-content; transform: translateX(-50%); } } } ``` ::: #### 2. 原生横屏方案 (仅微信小程序) 微信小程序提供了原生的横屏支持,使用时需要注意区分平台: :::warning 注意事项 1. `pageOrientation` 配置仅在微信小程序端生效 2. 使用条件编译区分不同平台的布局结构 3. 微信小程序页面会自动旋转,按钮布局不需要特殊处理 4. 预留底部按钮空间时需要考虑横屏布局 5. 其他平台请使用通用横屏方案 ::: ::: code-group ```json [json] { "path": "pages/signature/landscape", "style": { "navigationBarTitleText": "横屏签名", // #ifdef MP-WEIXIN "pageOrientation": "landscape" // #endif } } ``` ```html [vue] ``` ```ts [ts] import { pause } from '@/uni_modules/wot-ui/common/util' const height = ref(0) const width = ref(0) const inited = ref(false) onMounted(() => { const { windowWidth, windowHeight } = uni.getSystemInfoSync() width.value = windowWidth height.value = windowHeight - 60 // 预留底部按钮空间 pause(100).then(() => { inited.value = true }) }) ``` ```scss [css] .landscape-signature { height: 100vh; background: #fff; position: relative; box-sizing: border-box; // #ifdef MP-WEIXIN padding: 0; display: flex; flex-direction: column; .weixin-actions { padding: 12px; background-color: #f8f8f8; .button-group { display: flex; justify-content: center; gap: 12px; } } // #endif } ``` ::: ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | pen-color | 签名笔颜色 | `string` | `'#000'` | | line-width | 签名笔宽度 | `number` | `3` | | confirm-text | 确认按钮文本 | `string` | 内置文案 | | clear-text | 清空按钮文本 | `string` | 内置文案 | | revoke-text | 撤回按钮文本 | `string` | 内置文案 | | restore-text | 恢复按钮文本 | `string` | 内置文案 | | file-type | 导出图片类型,可选值为 `png`、`jpg` | `'png' \| 'jpg'` | `'png'` | | quality | 导出图片质量,取值范围为 `0` 到 `1` | `number` | `1` | | export-scale | 导出图片缩放比例 | `number` | `1` | | disabled | 是否禁用签名板 | `boolean` | `false` | | height | 画布高度 | `string \| number` | - | | width | 画布宽度 | `string \| number` | - | | background-color | 画板背景色 | `string` | - | | disable-scroll | 是否禁用画布滚动 | `boolean` | `true` | | enable-history | 是否开启历史记录 | `boolean` | `false` | | step | 撤回和恢复的步长 | `number` | `1` | | undo-text | 撤销按钮文本 | `string` | 内置文案 | | redo-text | 恢复按钮文本 | `string` | 内置文案 | | pressure | 是否开启压感模式 | `boolean` | `false` | | max-width | 压感模式下的最大笔触宽度 | `number` | `6` | | min-width | 压感模式下的最小笔触宽度 | `number` | `2` | | min-speed | 压感模式下的最小速度阈值 | `number` | `1.5` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | start | 开始签名时触发 | event | | end | 结束签名时触发 | event | | signing | 签名过程中持续触发 | event | | confirm | 确认签名时触发 | `SignatureResult` | | clear | 清空签名时触发 | - | ## Methods | 方法名 | 说明 | 参数 | | --- | --- | --- | | init | 初始化签名板 | `forceUpdate?: boolean` | | confirm | 确认并导出签名图片 | - | | clear | 清空签名 | - | | restore | 恢复上一步 | - | | revoke | 撤销上一步 | - | ## Slots | name | 说明 | 参数 | | --- | --- | --- | | footer | 自定义底部操作区 | `{ clear, confirm, currentStep, revoke, restore, canUndo, canRedo, historyList }` | --- --- url: 'https://wot-ui.cn/component/skeleton.md' --- # Skeleton 骨架屏 骨架屏用于内容加载时的占位展示,支持多种主题类型、行列自定义、动画效果和插槽内容。 ## 组件类型 ### 基本用法 通过 `theme` 设置不同骨架主题,常用于文本、头像、图片、段落等场景。 ::: code-group ```html ``` ::: ## 组件样式 ### 宫格骨架屏 通过 `row-col` 组合多行多列占位结构,可以构造宫格骨架屏。 ::: code-group ```html ``` ```ts const grid = [ [ { width: '48px', height: '48px' }, { width: '48px', height: '48px' }, { width: '48px', height: '48px' }, { width: '48px', height: '48px' }, { width: '48px', height: '48px' } ], [ { width: '48px', height: '16px' }, { width: '48px', height: '16px' }, { width: '48px', height: '16px' }, { width: '48px', height: '16px' }, { width: '48px', height: '16px' } ] ] as SkeletonRowCol[] ``` ::: ### 单元格骨架屏 可以组合头像、矩形块与文本行,模拟常见单元格列表布局。 ```html ``` ### 图片组合骨架屏 可以结合 `row-col` 自定义图片卡片与图文混排占位结构。 ```html ``` ## 特殊样式 ### 渐变加载动画 设置 `animation="gradient"` 开启渐变加载动画。 ```html ``` ### 闪烁加载动画 设置 `animation="flashed"` 开启闪烁加载动画。 ```html ``` ### 插槽内容 通过默认插槽写入实际内容,`loading` 为 `true` 时显示骨架屏,切换为 `false` 后显示插槽内容。 ::: code-group ```html ``` ```ts const showContent = ref(true) ``` ::: *** ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | theme | 骨架屏主题,可选值为 `text`、`avatar`、`paragraph`、`image` | `SkeletonTheme` | `'text'` | | row-col | 自定义每行占位配置,用于设置行列数量、宽高、间距、圆角和占位类型等,支持数字、对象、对象数组 | `SkeletonRowCol[]` | `[]` | | loading | 是否显示骨架屏 | `boolean` | `true` | | animation | 动画类型,可选值为 `gradient`、`flashed` | `SkeletonAnimation` | `''` | | customClass | 自定义样式类名 | `string \| string[] \| Record` | `''` | | custom-style | 自定义内联样式 | `CSSProperties` | `{}` | ## Slots | name | 说明 | | --- | --- | | default | `loading` 结束后展示的实际内容 | ## 类型说明 ### SkeletonTheme 可选值:`'text' | 'avatar' | 'paragraph' | 'image'` ### SkeletonAnimation 可选值:`'gradient' | 'flashed'` ### SkeletonRowCol 配置示例 ```ts // 三行,分别显示为一列、一列、两列的占位符 [1, 1, 2] // 三行,第三行自定义宽度 [1, 1, { width: '100px' }] // 第三行包含两列,分别设置宽度和右外边距 [1, 1, [{ width: '50%' }, { width: '50%', marginRight: '10px' }]] ``` --- --- url: 'https://wot-ui.cn/guide/skills.md' --- # Skills [Skills](https://agentskills.io/what-are-skills) 是 AI 的“超能力模板”,是一套完整的、可复用的、能解决特定问题的方案,我们专为 AI Agent(如 Trae, Cursor, Cline 等)设计了 Wot UI 相关的 Skills,以帮助 AI 更加准确、高效地处理 `wot-ui` 相关的开发任务。 如果你只需要让 AI 读取文档或查询组件 API,可以先查看 [AI 使用指南](/guide/ai) 选择更轻量的接入方式。 ## 🎯 内置技能 我们提供以下 AI 技能,可供 AI 智能体根据任务需求加载: | Skill | 描述 | 适用场景 | 入口 | | --- | --- | --- | --- | | `wot-ui-v2` | 处理 wot-ui v2 组件库日常开发的核心技能。 | 组件选型、API 查询、生成 Vue3 + uni-app 页面代码、排查常见组件坑位(如 Toast, Dialog 挂载等)。 | [skills/wot-ui-v2/SKILL.md](https://github.com/wot-ui/open-wot/tree/main/skills/wot-ui-v2/SKILL.md) | | `wot-ui-cli` | 专门用于回答、使用和调试 `@wot-ui/cli` 工具本身的技能。 | 查询 CLI 命令用法(list, info, doc 等)、配置 MCP Server、本地调试 CLI 源码、执行离线数据提取。 | [skills/wot-ui-cli/SKILL.md](https://github.com/wot-ui/open-wot/tree/main/skills/wot-ui-cli/SKILL.md) | | `wot-ui-unocss-preset-guide` | 指导安装、配置并使用 `@wot-ui/unocss-preset`。 | 预设接入、`unocss.config.ts` 配置(如 `presetWot`)、`prefix/preflight/baseTokens` 使用示例、类名不生效/自动补全不出现等问题排查。 | [skills/wot-ui-unocss-preset-guide/SKILL.md](https://github.com/wot-ui/open-wot/tree/main/skills/wot-ui-unocss-preset-guide/SKILL.md) | | `create-wot-ui-theme` | 生成 wot-ui 单文件主题 SCSS 的专项技能。 | 需要为 wot-ui 定制品牌主题,且要求遵循“单文件包含 mixin 和挂载选择器、App.vue 仅作 `@use` 引入”的约束时使用。 | [skills/create-wot-ui-theme/SKILL.md](https://github.com/wot-ui/open-wot/tree/main/skills/create-wot-ui-theme/SKILL.md) | ## 安装 推荐使用脚本安装 Skills,可以根据实际需求选择安装项: ```sh pnpm dlx skills add wot-ui/open-wot # or npx skills add wot-ui/open-wot ``` ## 延伸阅读 * [AI 使用指南](/guide/ai) * [llms.txt](/guide/llms-txt) * [Agent Skills、Rules、Prompt、MCP,一文把它们理清楚了](https://juejin.cn/post/7599268297201958950) --- --- url: 'https://wot-ui.cn/component/slider.md' --- # Slider 滑块 支持单向滑块和双向滑块,可用于在范围内选择一个值或一段区间。 ## 组件类型 ### 基本用法 `v-model` 为绑定值。值为 `number` 时显示一个滑块。 ```html ``` ```ts const value = ref(30) ``` ### 双向滑块 设置 `range` 后,绑定值变为数组类型。 ```html ``` ```ts const value = ref([20, 60]) ``` ## 组件状态 ### 禁用状态 设置 `disabled` 禁用滑块。 ```html ``` ## 组件样式 ### 显示极值 设置 `show-extreme-value` 显示最小值和最大值。 ```html ``` ### 管道样式 设置 `theme="capsule"` 使用管道样式。 ```html ``` ### 指定步长 通过 `step` 设置步长。 ```html ``` ### 指定选择范围 通过 `min` 和 `max` 设置取值范围。 ```html ``` ### 刻度标记 通过 `marks` 配置刻度标记。 ```html ``` ### 刻度标记(管道) 刻度标记也可以与管道样式组合使用。 ```html ``` ## 布局能力 ### 垂直方向 设置 `vertical` 以垂直方向展示。 ```html ``` ### 垂直 + 管道 垂直方向支持与 `theme="capsule"` 组合使用。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | model-value / v-model | 当前滑块值,单滑块为 `number`,双滑块为 `number[]` | `SliderValue` | `0` | | min | 最小值 | `number` | `0` | | max | 最大值 | `number` | `100` | | step | 步长 | `number` | `1` | | range | 是否为双向滑块模式 | `boolean` | `false` | | vertical | 是否垂直展示 | `boolean` | `false` | | theme | 滑块风格,可选值为 `default`、`capsule` | `SliderTheme` | `'default'` | | disabled | 是否禁用 | `boolean` | `false` | | show-extreme-value | 是否显示最小值和最大值文本 | `boolean` | `false` | | popover-visible | 气泡显示模式,可选值为 `always`、`normal`、`never` | `SliderPopoverVisible` | `'normal'` | | marks | 刻度标记,支持数组或对象形式 | `SliderMarks` | - | | active-color | 进度条激活态颜色 | `string` | `''` | | inactive-color | 进度条未激活态颜色 | `string` | `''` | | custom-class | 根节点样式类 | `string` | `''` | | custom-style | 根节点样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | dragstart | 开始拖动时触发 | `{ value }` | | dragmove | 拖动过程中触发 | `{ value }` | | dragend | 拖动结束时触发 | `{ value }` | | change | 值变化时触发 | `value` | ## Methods | 方法名 | 说明 | 参数 | | --- | --- | --- | | initSlider | 初始化 slider 尺寸数据 | - | --- --- url: 'https://wot-ui.cn/component/slide-verify.md' --- # SlideVerify 滑动验证 滑动验证组件,用于人机验证场景。 ## 组件类型 ### 基本用法 ```html ``` ```ts const toast = useToast() function handleSuccess() { toast.success('验证成功') } function handleFail() { toast.error('验证失败,请重试') } ``` ## 组件状态 ### 禁用状态 设置 `disabled` 后禁用滑动验证。 ```html ``` ## 组件样式 ### 自定义文案 通过 `text` 和 `success-text` 属性自定义提示文字。 ```html ``` ### 自定义颜色 通过 `background-color` 和 `active-background-color` 属性自定义颜色。 ```html ``` ### 自定义图标 通过 `icon` 和 `success-icon` 属性自定义图标。 ```html ``` ## 特殊样式 ### 自定义容错范围 通过 `tolerance` 属性设置容错范围(单位:px),默认为 10px。 ```html ``` ### 重置方法 通过 `ref` 获取组件实例,调用 `reset` 方法重置验证状态。 ```html 重置 ``` ```ts import { ref } from 'vue' import type { SlideVerifyInstance } from '@/uni_modules/wot-ui/components/wd-slide-verify/types' const slideVerifyRef = ref() function handleReset() { slideVerifyRef.value?.reset() } ``` ### 插槽用法 支持通过插槽自定义内容。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | tolerance | 容错范围,单位为 `px` | number | `10` | | text | 提示文字,为空时显示内置文案 | string | `''` | | success-text | 验证成功提示文字,为空时显示内置文案 | string | `''` | | disabled | 是否禁用 | boolean | `false` | | background-color | 背景颜色 | string | - | | active-background-color | 激活时的背景颜色 | string | - | | icon | 滑块图标名称 | string | `double-right` | | success-icon | 成功图标名称 | string | `check-circle-fill` | | icon-size | 图标大小 | string / number | - | | success-icon-size | 成功图标大小 | string / number | - | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | success | 验证成功时触发 | - | | fail | 验证失败时触发 | - | ## Methods | 方法名 | 说明 | 参数 | | --- | --- | --- | | init | 初始化尺寸信息 | - | | reset | 重置验证组件到初始状态 | - | ## Slots | name | 说明 | | --- | --- | | text | 自定义提示文字内容 | | success-text | 自定义验证成功提示文字内容 | | icon | 自定义滑块图标 | | success-icon | 自定义成功图标 | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式类 | | custom-style | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/sort-button.md' --- # SortButton 排序按钮 用于展示排序按钮,支持升序、降序、重置三种状态。 ## 组件类型 ### 基本用法 使用 `v-model` 绑定当前排序状态,取值为 `-1`、`0`、`1`,分别表示降序、重置状态、升序。 ```html ``` ```ts const value = ref(0) function handleChange({ value }) { console.log(value) } ``` ## 组件变体 ### 允许重置 设置 `allow-reset` 后,排序按钮可回到重置状态。 ```html ``` ### 优先切换为降序 设置 `desc-first` 后,首次切换优先进入降序。 ```html ``` ## 组件样式 ### 显示下划线 设置 `line` 显示下划线。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | model-value / v-model | 当前排序方向值,`1` 表示升序,`0` 表示重置状态,`-1` 表示降序 | `SortButtonValue` | `0` | | title | 排序按钮文案 | `string` | `''` | | allow-reset | 是否允许重置为未选中状态 | `boolean` | `false` | | desc-first | 是否优先切换为降序 | `boolean` | `false` | | line | 是否显示下划线 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 排序方向变化时触发 | `{ value }` | --- --- url: 'https://wot-ui.cn/component/steps.md' --- # Steps 步骤条 用于引导用户按照流程完成任务,或向用户展示当前所处的步骤状态。 :::tip 提示 `wd-step` 已直接支持 `title`、`icon` 和 `description` 插槽,无需再设置旧版的 `*-slot` 控制字段。 ::: ## 组件类型 ### 基本用法 `active` 为当前步骤进度,对应步骤下标。 ```html ``` ### 标题和描述信息 通过 `title` 和 `description` 设置每个步骤的标题和描述。 ```html 下一步 ``` ```ts const active = ref(0) function nextStep() { active.value += 1 } ``` ### 修改图标 通过 `icon` 设置步骤图标。 ```html ``` ## 组件状态 ### 修改状态 通过 `status` 设置指定步骤的状态。 ```html ``` ## 组件样式 ### 水平居中 设置 `align-center` 水平居中,只对横向步骤条有效。 ```html ``` ## 布局能力 ### 竖向步骤条 设置 `vertical` 以垂直方向展示。 ```html ``` ## 特殊样式 ### 点状步骤条 设置 `dot` 使用点状步骤条。 ```html ``` ### 可控制的点状步骤条 点状步骤条支持通过外部 `active` 控制当前步骤。 ```html ``` ### 竖向点状步骤条 `vertical` 和 `dot` 可以组合使用。 ```html ``` ## Steps Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | active | 当前激活步骤下标 | `number` | `0` | | vertical | 是否垂直方向展示 | `boolean` | `false` | | dot | 是否使用点状步骤条 | `boolean` | `false` | | space | 步骤条间距,默认自动计算 | `string` | `''` | | align-center | 是否水平居中,只对横向步骤条有效 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Step Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | title | 步骤标题,不传时显示默认文案 | `string` | - | | description | 步骤描述 | `string` | - | | icon | 步骤图标 | `string` | - | | status | 步骤状态,可选值为 `finished`、`process`、`error`、`wait` | `StepStatus` | - | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Steps Slots | name | 说明 | | --- | --- | | default | Step 列表 | ## Step Slots | name | 说明 | | --- | --- | | icon | 自定义步骤图标 | | title | 自定义步骤标题 | | description | 自定义步骤描述 | --- --- url: 'https://wot-ui.cn/component/sticky.md' --- # Sticky 粘性布局 粘性布局组件,用于在页面滚动时将元素固定在指定位置。 ## 组件类型 ### 基本用法 将需要吸顶的内容包裹在 `wd-sticky` 组件内即可。 > 注意:被包裹的元素在样式中使用百分比单位 `width:xx%;height:xx%;` 无效,建议使用 `vh`、`vw`。 ```html 基础用法 ``` ### 指定容器 将 `wd-sticky` 放入相对容器中,再使用 `wd-sticky-box` 包裹该容器,可限制吸顶区域。 ```html 指定容器 ``` ```scss .container { height: 120px; width: 100vw; } ``` ## 组件样式 ### 吸顶距离 通过 `offset-top` 设置组件吸顶时与顶部的距离。 ::: tip 提醒 在 H5 端默认导航栏为普通元素,所以吸顶距离会自动在 `offset-top` 的基础上增加 `44px`。当 H5 端使用自定义导航栏时,需要自行扣除这部分高度。 ::: ```html 吸顶距离 ``` ### 相对容器吸顶距离 `offset-top` 也可以与 `wd-sticky-box` 组合使用。 ```html 相对容器吸顶距离 ``` ## 特殊样式 ### 动态插入 `wd-sticky` 支持包裹动态生成的内容。 > 注意包裹动态生成的内容时,内容的宽高不小于 `1px` ```html 点击插入 动态生成 ``` ```ts const show = ref(false) function display() { show.value = true } function insert() { display() } onShow(() => { setTimeout(display, 5000) }) ``` ## Sticky Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | z-index | 层级 | `number` | `1` | | offset-top | 吸顶距离 | `number` | `0` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Sticky Slots | name | 说明 | | --- | --- | | default | 需要吸顶的内容 | ## Sticky 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式类 | | custom-style | 根节点样式 | ## Sticky Box Slots | name | 说明 | | --- | --- | | default | 相对容器内容 | ## Sticky Box 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式类 | | custom-style | 根节点样式 | --- --- url: 'https://wot-ui.cn/component/swipe-action.md' --- # SwipeAction 滑动操作 常用于单元格左右滑删除等手势操作。 :::warning 滑动操作组件对页面的功能隐藏较深,用户难以发现,建议优先使用更直接的交互方式,例如列表项按钮或 ActionSheet。 如果仍然使用滑动操作,建议在用户进入页面时提供显式提示,告知列表项支持左右滑动。 ::: ## 组件类型 ### 基本用法 `wd-swipe-action` 由三部分组成:左侧操作区、内容区、右侧操作区。左右操作区分别通过 `left` 和 `right` 插槽定义,内容区使用默认插槽。 在页面根节点上监听点击事件,并结合 `useQueue` 提供的 `closeOutside`,可以在点击组件外部区域时统一关闭已展开的滑动项。 :::warning 如果页面上存在“点击按钮后手动展开 `swipe-action`”之类的交互,需要在这些按钮外层使用 `@click.stop` 阻止事件冒泡,避免触发根节点上的 `closeOutside`。 ::: ::: code-group ```html [vue] ``` ```ts [ts] import { useToast, useQueue } from '@/uni_modules/wot-ui' const { closeOutside } = useQueue() const toast = useToast() function handleAction(action: string) { toast.show(`点击了${action}`) } ``` ```scss [scss] .action { height: 100%; } .button { display: inline-block; padding: 0 15px; height: 100%; color: #fff; line-height: 44px; } ``` ::: ### 左右滑动 通过 `left` 和 `right` 插槽可以同时配置左右两侧操作区。 ```html ``` ## 组件状态 ### 禁用滑动按钮 设置 `disabled` 后,组件不会响应滑动和点击关闭相关交互。 ```html ``` ## 特殊样式 ### 切换按钮 通过 `v-model` 可以直接控制当前展开状态,可选值为 `left`、`close`、`right`,分别表示展开左侧、收起全部、展开右侧。 ::: code-group ```html [vue] 打开左边 关闭所有 打开右边 ``` ```ts [ts] import { ref } from 'vue' import type { SwipeActionStatus } from '@/uni_modules/wot-ui/components/wd-swipe-action/types' const value = ref('close') function changeState(position: SwipeActionStatus) { value.value = position } function noop() {} ``` ::: ### 按钮关闭前的钩子函数 `before-close` 会在组件执行关闭逻辑前触发,可用于关闭前校验或异步确认。 钩子函数接收两个参数: * `reason`:关闭原因,可选值为 `click`、`swipe`、`value` * `position`:关闭位置,可选值为 `left`、`right`、`inside` 其中 `inside` 表示点击了内容区域内部但不属于左右操作按钮的位置。 需要显式返回 `true` 或 `Promise` 才会继续关闭,返回 `false` 或 `Promise` 会阻止关闭。 ::: code-group ```html [vue] ``` ```ts [ts] import { useToast } from '@/uni_modules/wot-ui' import type { SwipeActionBeforeClose } from '@/uni_modules/wot-ui/components/wd-swipe-action/types' const toast = useToast() const beforeClose: SwipeActionBeforeClose = (reason, position) => { return new Promise((resolve) => { const shouldClose = !(reason === 'click' && position === 'inside') if (!shouldClose) { toast.show('已拦截点击内容区导致的关闭') resolve(false) } else { toast.loading('处理中...') setTimeout(() => { toast.close() if (reason === 'click') { toast.show(`${reason} ${position} 导致滑动按钮关闭`) } else { toast.show(`${reason} 导致 ${position} 滑动按钮关闭`) } resolve(true) }, 3000) } }) } ``` ::: ### 点击事件 `click` 事件会在已展开状态下点击内容区、左侧操作区或右侧操作区,并且关闭成功后发出;若被 `before-close` 拦截则不会触发。 ```html ``` ```ts import { useToast } from '@/uni_modules/wot-ui' import type { SwipeActionClickEvent } from '@/uni_modules/wot-ui/components/wd-swipe-action/types' const toast = useToast() function handleClick({ value }: SwipeActionClickEvent) { toast.show(`点击 ${value} 关闭操作按钮`) } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前滑动状态,可选值为 `left`、`close`、`right` | `SwipeActionStatus` | `close` | | disabled | 是否禁用滑动操作 | `boolean` | `false` | | before-close | 关闭前拦截函数,接收 `(reason, position)`,返回 `true` 或 `Promise` 时继续关闭,返回 `false` 时阻止关闭 | `SwipeActionBeforeClose` | - | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 已展开状态下点击内容区或操作区并关闭时触发 | `SwipeActionClickEvent` | | update:modelValue | 滑动状态变化时触发 | `SwipeActionStatus` | ## Methods 通过组件实例可以调用以下方法。 | 方法名 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | close | 关闭已展开的操作按钮 | `reason: SwipeActionReason, position?: SwipeActionPosition` | - | ## Slots | 名称 | 说明 | | --- | --- | | left | 自定义左侧操作区 | | default | 自定义内容区 | | right | 自定义右侧操作区 | ## 外部样式类 | 类名 | 说明 | | --- | --- | | custom-class | 根节点样式类 | | custom-style | 根节点内联样式 | --- --- url: 'https://wot-ui.cn/component/swiper.md' --- # Swiper 轮播 用于创建轮播,支持水平和垂直方向滑动、自定义指示器、图片和视频资源展示,以及基于对象数据渲染标题。 ::: danger 请注意 嵌入视频仅在 H5、微信小程序和钉钉小程序支持,其余端不支持,请了解后使用。 ::: ## 组件类型 ### 点状指示器 基础轮播可通过 `indicator` 配置展示点状指示器。 ::: code-group ```html [vue] ``` ```ts [ts] import { ref } from 'vue' const current = ref(0) const swiperList = ref([ 'https://wot-ui.cn/assets/redpanda.jpg', 'https://wot-ui.cn/assets/capybara.jpg', 'https://wot-ui.cn/assets/panda.jpg', 'https://wot-ui.cn/assets/moon.jpg', 'https://wot-ui.cn/assets/meng.jpg' ]) ``` ::: ### 点条状指示器 ```html ``` ### 数字指示器 ```html ``` ## 组件变体 ### 手动切换 关闭 `autoplay` 并开启 `showControls` 后,可通过控制按钮手动切换轮播项。 ```html ``` ### 垂直方向 ```html ``` ### 指定 value-key 和 text-key 当 `list` 为对象数组时,可通过 `value-key` 和 `text-key` 指定图片地址字段与标题字段。 ::: code-group ```html [vue] ``` ```ts [ts] import { ref } from 'vue' const current = ref(0) const customSwiperList = ref([ { url: 'https://wot-ui.cn/assets/redpanda.jpg', title: '小熊猫' }, { url: 'https://wot-ui.cn/assets/capybara.jpg', title: '卡皮巴拉' }, { url: 'https://wot-ui.cn/assets/panda.jpg', title: '大熊猫' }, { url: 'https://wot-ui.cn/assets/moon.jpg', title: '诗画中国' } ]) ``` ::: ## 组件样式 ### 卡片样式 设置 `previous-margin` 和 `next-margin`,并结合自定义类名,可以实现卡片轮播样式。 ```html ``` ```scss .card-swiper { --wot-swiper-radius: 0; --wot-swiper-item-padding: 0 24rpx; --wot-swiper-nav-dot-color: #e7e7e7; --wot-swiper-nav-dot-active-color: #4d80f0; padding-bottom: 24rpx; :deep(.custom-indicator-class) { bottom: -16px; } :deep(.custom-image) { border-radius: 12rpx; } :deep(.custom-image-prev) { height: 168px !important; } } ``` ### 同时展示 2 个滑块 通过 `display-multiple-items` 控制同时展示的滑块数量。 ```html ``` ### 自定义指示器 通过 `indicator` 插槽可以完全自定义指示器展示。 ```html ``` ```scss .custom-indicator { position: absolute; right: 24rpx; bottom: 24rpx; padding: 0 12rpx; height: 48rpx; line-height: 48rpx; border-radius: 45%; background: rgba(0, 0, 0, 0.6); color: #ffffff; font-size: 24rpx; } ``` ## 特殊样式 ### 视频轮播 ```html ``` ```ts import { ref } from 'vue' const videoList = ref([ 'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_115503.mp4', 'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_150752.mp4', 'https://unpkg.com/wot-design-uni-assets@1.0.3/VID_155516.mp4', 'https://wot-ui.cn/assets/moon.jpg' ]) ``` ### 手动播放视频 ```html ``` ### 播放视频时停止轮播 ```html ``` ### 属性控制切换 ```html prev next ``` ### 插槽用法 通过默认插槽可以自定义轮播项内容。 ```html ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | autoplay | 是否自动播放 | `boolean` | `true` | | v-model:current | 当前轮播项索引 | `number` | `0` | | direction | 轮播方向,可选值为 `horizontal`、`vertical` | `DirectionType` | `horizontal` | | display-multiple-items | 同时显示的滑块数量 | `number` | `1` | | duration | 滑动动画时长,单位为 `ms` | `number` | `300` | | easing-function | 切换缓动动画类型,可选值为 `default`、`linear`、`easeInCubic`、`easeOutCubic`、`easeInOutCubic` | `EasingType` | `default` | | height | 轮播高度 | string | number | `192` | | interval | 自动轮播间隔时间,单位为 `ms` | `number` | `5000` | | list | 轮播数据列表,支持字符串数组或对象数组 | string\[] | SwiperItem\[] | `[]` | | loop | 是否循环播放 | `boolean` | `true` | | video-loop | 视频是否循环播放 | `boolean` | `true` | | muted | 视频是否静音播放 | `boolean` | `true` | | next-margin | 后边距 | string | number | `0` | | indicator-position | 指示器位置,可选值为 `left`、`top-left`、`top`、`top-right`、`bottom-left`、`bottom`、`bottom-right`、`right` | `IndicatorPositionType` | `bottom` | | previous-margin | 前边距 | string | number | `0` | | radius | 轮播圆角 | string | number | - | | snap-to-edge | 是否将边距应用到首尾元素 | `boolean` | `false` | | indicator | 指示器配置,传入 `false` 时隐藏指示器 | boolean | Partial\ | `true` | | image-mode | 图片裁剪模式,取值参考 uni-app Image 组件 `mode` | `ImageMode` | `aspectFill` | | show-menu-by-longpress | 是否开启长按图片显示识别小程序码菜单 | `boolean` | `false` | | value-key | 选项对象中图片地址字段名 | `string` | `value` | | text-key | 选项对象中标题字段名 | `string` | `text` | | autoplay-video | 视频是否自动播放 | `boolean` | `true` | | stop-previous-video | 切换轮播项时是否停止上一个视频播放 | `boolean` | `true` | | stop-autoplay-when-video-play | 视频播放时是否停止自动轮播 | `boolean` | `false` | | adjust-height | 自动根据滑块高度调整容器高度,可选值为 `first`、`current`、`highest`、`none`,仅支付宝小程序支持 | `AdjustHeightType` | `highest` | | adjust-vertical-height | `vertical` 为 `true` 时强制让 `adjust-height` 生效,仅支付宝小程序支持 | `boolean` | `false` | | custom-indicator-class | 自定义指示器类名 | `string` | `''` | | custom-image-class | 自定义图片类名 | `string` | `''` | | custom-prev-image-class | 自定义前一个图片类名 | `string` | `''` | | custom-next-image-class | 自定义后一个图片类名 | `string` | `''` | | custom-item-class | 自定义轮播项类名 | `string` | `''` | | custom-prev-class | 自定义前一个轮播项类名 | `string` | `''` | | custom-next-class | 自定义后一个轮播项类名 | `string` | `''` | | custom-text-class | 自定义标题类名 | `string` | `''` | | custom-text-style | 自定义标题样式 | `string` | `''` | | custom-class | 根节点自定义样式类 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | click | 点击轮播项时触发 | { index: number; item: SwiperItem | string } | | change | 轮播切换时触发 | { current: number; source: string } | | animationfinish | 轮播动画结束时触发 | { current: number; source: string } | | update:current | 当前轮播项更新时触发 | `number` | ## Slots | 名称 | 说明 | | --- | --- | | default | 自定义轮播项内容,参数为 { item, index } | | indicator | 自定义指示器内容,参数为 { current, total } | ## 类型定义 ### DirectionType 轮播方向,可选值为 `horizontal`、`vertical`。 ### EasingType 切换缓动动画类型,可选值为 `default`、`linear`、`easeInCubic`、`easeOutCubic`、`easeInOutCubic`。 ### IndicatorPositionType 指示器位置,可选值为 `left`、`top-left`、`top`、`top-right`、`bottom-left`、`bottom`、`bottom-right`、`right`。 ### AdjustHeightType 自动高度策略,可选值为 `first`、`current`、`highest`、`none`。 ### SwiperIndicatorType 指示器类型,可选值为 `dots`、`dots-bar`、`fraction`。 ### SwiperItem 轮播项对象配置,支持扩展字段。 | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | value | 图片或视频地址 | `string` | - | | poster | 视频封面地址 | `string` | - | | type | 资源类型,可选值为 `image`、`video` | `SwiperItemType` | - | ### SwiperIndicator Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | current | 当前轮播项索引 | `number` | `0` | | direction | 轮播方向,可选值为 `horizontal`、`vertical` | `DirectionType` | `horizontal` | | min-show-num | 小于该数量时不显示导航器 | `number` | `2` | | indicator-position | 指示器位置,可选值为 `left`、`top-left`、`top`、`top-right`、`bottom-left`、`bottom`、`bottom-right`、`right` | `IndicatorPositionType` | `bottom` | | show-controls | 是否显示两侧控制按钮 | `boolean` | `false` | | total | 轮播项总数 | `number` | `0` | | type | 指示器类型,可选值为 `dots`、`dots-bar`、`fraction` | `SwiperIndicatorType` | `dots` | --- --- url: 'https://wot-ui.cn/component/switch.md' --- # Switch 开关 用来打开或关闭选项。 ## 组件类型 ### 基本用法 `v-model` 为绑定值,默认为 boolean 类型。 ```html ``` ```ts const checked = ref(true) ``` ### 修改值 通过 `active-value` 属性修改开关打开时的值,`inactive-value` 属性修改开关关闭时的值。 ```html ``` ## 组件状态 ### 加载状态 设置 `loading` 显示加载状态。 ```html ``` ### 禁用状态 设置 `disabled` 禁用开关。 ```html ``` ## 组件样式 ### 修改颜色 通过 `active-color` 属性修改开关打开时的颜色,`inactive-color` 属性修改开关关闭时的颜色。 ```html ``` ### 文字描述 通过 `active-text` 和 `inactive-text` 设置开关内文案。 ```html ``` ### 自定义显示图标 通过 `active-icon` 和 `inactive-icon` 自定义开关内部图标。 ```html ``` ### 自定义动作图标 通过 `active-action-icon` 和 `inactive-action-icon` 自定义按钮图标。 ```html ``` ### 形状 通过 `shape` 设置形状,可选值为 `round`、`square`。 ```html ``` ### 自定义大小 设置 `size` 修改开关大小。 ```html ``` ## 特殊样式 ### 搭配表单使用 可以放入表单项中作为右侧操作控件。 ```html ``` ### 修改前钩子 设置 `before-change` 属性,修改前钩子,接收目标 `value`,返回 `false` 表示不修改,支持返回 `Promise`。 ```html ``` ```ts import { useDialog } from '@/uni_modules/wot-ui' const message = useDialog() const beforeChange = (value) => { return message.confirm('是否切换开关').then(() => true).catch(() => false) } ``` ## Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | model-value / v-model | 绑定值 | `boolean \| string \| number` | `false` | | disabled | 是否禁用 | `boolean` | `false` | | inactive-action-icon | 非激活状态操作按钮图标 | `string` | - | | active-action-icon | 激活状态操作按钮图标 | `string` | - | | active-icon | 激活状态图标,设置后会忽略 `active-text` | `string` | - | | inactive-icon | 非激活状态图标,设置后会忽略 `inactive-text` | `string` | - | | class-prefix | 类名前缀,用于使用自定义图标,用法参考 Icon 组件 | `string` | `'wd-icon'` | | inactive-action-css-icon | 非激活状态操作按钮 CSS 图标,用法参考 Icon 组件 | `boolean \| string` | `false` | | active-action-css-icon | 激活状态操作按钮 CSS 图标,用法参考 Icon 组件 | `boolean \| string` | `false` | | active-css-icon | 激活状态 CSS 图标,设置后将忽略 `active-text`,用法参考 Icon 组件 | `boolean \| string` | `false` | | inactive-css-icon | 非激活状态 CSS 图标,设置后将忽略 `inactive-text`,用法参考 Icon 组件 | `boolean \| string` | `false` | | active-text | 激活状态文本 | `string` | `''` | | inactive-text | 非激活状态文本 | `string` | `''` | | active-value | 激活值 | `boolean \| string \| number` | `true` | | inactive-value | 非激活值 | `boolean \| string \| number` | `false` | | active-color | 激活颜色 | `string` | - | | inactive-color | 非激活颜色 | `string` | - | | size | 开关大小 | `string \| number` | - | | shape | 形状,可选值为 `round`、`square` | `SwitchShape` | `'round'` | | loading | 是否显示加载中 | `boolean` | `false` | | loading-props | 加载配置项 | `Partial` | - | | before-change | 修改前钩子 | `SwitchBeforeChange` | - | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 值修改事件 | `{ value }` | --- --- url: 'https://wot-ui.cn/component/tabs.md' --- # Tab 标签页 标签页组件,用于在不同内容区域之间进行切换。 ## 组件类型 ### 基本用法 `v-model` 可以使用数字下标,也可以使用字符串名称。 ```html 内容{{ tab1 + 1 }} ``` ```ts const tab1 = ref(0) function handleChange(event) { console.log(event) } ``` ### name 匹配 为 `wd-tab` 设置 `name` 后,可通过字符串值匹配当前激活项。 ```html 内容{{ tab }} ``` ```ts const tabs = ref(['this', 'is', 'a', 'individual', 'example']) const tab = ref('a') ``` ### 使用徽标 通过 `badge-props` 为标签添加徽标。 ```html {{ item.title }}徽标 ``` ## 组件状态 ### 粘性布局 设置 `sticky` 开启吸顶布局,可配合 `offset-top` 控制吸顶偏移量。 ```html 内容{{ tab2 + 1 }} ``` ### 禁用 Tab 通过 `wd-tab` 的 `disabled` 属性禁用单个页签。 ```html 内容{{ tab3 + 1 }} ``` ## 组件样式 ### 底部条样式 通过 `line-theme` 调整底部条表现,支持 `normal`、`text`、`underline`、`dot`。 ```html 内容{{ item }} ``` ## 特殊样式 ### 点击事件 监听 `click` 获取当前点击的页签信息。 ```html 内容{{ tab4 + 1 }} ``` ```ts function handleClick({ index, name }) { console.log(index, name) } ``` ### 切换动画 设置 `animated` 开启内容切换动画。 ```html 内容{{ tab8 + 1 }} ``` ### 手势滑动 设置 `swipeable` 开启手势滑动,常与 `animated` 组合使用。 ```html 内容{{ tab5 + 1 }} ``` ### 超出滚动与导航地图 标签数量超过 `slidable-num` 后可滑动,超过 `map-num` 后会显示导航地图;将 `slidable` 设为 `always` 时可始终左对齐滚动。 ```html 内容{{ tab6 + 1 }} 内容{{ tab9 + 1 }} ``` ### 在弹出框中使用 在微信小程序等场景中,弹出层打开后可调用 `updateLineStyle` 更新激活项样式。 ::: code-group ```html [vue] 打开弹窗 内容{{ tab10 }} ``` ```ts [ts] import type { TabsInstance } from '@/uni_modules/wot-ui/components/wd-tabs/types' const showPopup = ref(false) const tabsRef = ref() function handleOpenClick() { showPopup.value = true } function handlePopupShow() { tabsRef.value?.updateLineStyle(false) } ``` ::: ## Tabs Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前激活项,可为索引或名称 | `number | string` | `0` | | slidable-num | 自动开启滚动的标签数量阈值 | `number` | `6` | | map-num | 显示导航地图的标签数量阈值 | `number` | `10` | | map-title | 导航地图标题 | `string` | - | | sticky | 是否开启粘性布局 | `boolean` | `false` | | offset-top | 吸顶偏移量 | `number` | `0` | | swipeable | 是否开启手势滑动 | `boolean` | `false` | | line-theme | 底部条样式,可选值为 `normal`、`text`、`underline`、`dot` | `TabsLineTheme` | `normal` | | line-width | 底部条宽度 | `number | string` | - | | line-height | 底部条高度 | `number | string` | - | | color | 激活项文字颜色 | `string` | `''` | | inactive-color | 非激活项文字颜色 | `string` | `''` | | animated | 是否开启切换动画 | `boolean` | `false` | | duration | 动画时长,单位毫秒 | `number` | `300` | | slidable | 是否开启滚动导航,可选值为 `auto`、`always` | `TabsSlidable` | `auto` | | show-scrollbar | 滚动时是否显示滚动条 | `boolean` | `false` | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Tabs Events | 事件名称 | 说明 | 参数 | | --- | --- | --- | | change | 激活项变化时触发 | `{ index, name }` | | click | 点击页签标题时触发 | `{ index, name }` | | disabled | 点击禁用页签时触发 | `{ index, name }` | | update:modelValue | 激活项变化时触发 | `number | string` | ## Tabs Methods | 方法名 | 说明 | 参数 | 返回值 | | --- | --- | --- | --- | | setActive | 设置激活项 | `(value: number \| string, init: boolean, setScroll: boolean)` | - | | scrollIntoView | 使选中项滚动到可视区域 | - | - | | updateLineStyle | 更新激活项底部条样式 | `(animation?: boolean)` | - | ## Tabs Slots | 名称 | 说明 | | --- | --- | | default | Tab 内容 | ## Tab Attributes | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | name | 标签唯一标识,默认取索引 | `number | string` | - | | title | 标签标题 | `string` | - | | disabled | 是否禁用 | `boolean` | `false` | | lazy | 是否懒加载内容 | `boolean` | `true` | | badge-props | 徽标属性,透传给 Badge 组件 | `Partial` | - | | custom-class | 根节点自定义类名 | `string` | `''` | | custom-style | 根节点自定义样式 | `string` | `''` | ## Tab Slots | 名称 | 说明 | | --- | --- | | default | 页签内容 | --- --- url: 'https://wot-ui.cn/component/tabbar.md' --- # Tabbar 标签栏 底部导航栏,用于在不同页面之间进行切换。 ## 组件类型 ### 基础用法 `v-model` 为绑定值,表示选中标签的索引值或者名称。 ```html ``` ```ts import { ref } from 'vue' const tabbar = ref(1) ``` ### 通过名称匹配 通过设置 `name` 属性,可以通过名称匹配选中标签。 ```html ``` ```ts import { ref } from 'vue' const tabbar = ref('home') ``` ## 组件状态 ### 徽标提示 通过设置 `value` 属性,可以显示徽标提示,而设置 is-dot 属性后,会在图标右上角展示一个小红点。 ```html ``` ```ts import { ref } from 'vue' const tabbar = ref(1) ``` ## 组件变体 ### 悬浮标签栏 通过设置 `shape` 属性为 `round`,可以将标签栏设置为悬浮样式。 ```html ``` ```ts import { ref } from 'vue' const tabbar = ref(1) ``` ## 组件样式 ### 自定义图标 通过使用 `