tdesign-miniprogram
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTDesign Mini Program Skill
TDesign 小程序开发技能
TDesign WeChat Mini Program component library, an enterprise-level design system by Tencent. Provides 60+ high-quality components with dark mode support, theme customization, and more.
TDesign微信小程序组件库是腾讯推出的企业级设计体系,提供60+高品质组件,支持深色模式、主题定制等功能。
When to Use This Skill
适用场景
This skill should be triggered when:
- Developing WeChat Mini Programs with TDesign component library
- Using TDesign UI components (Button, Input, Dialog, etc.)
- Implementing interfaces following TDesign design specifications
- Configuring TDesign themes and style customization
- Building AI chat interfaces (using TDesign Chat components)
- Implementing dark mode adaptation
以下场景可使用本技能:
- 开发基于TDesign组件库的微信小程序
- 使用TDesign UI组件(Button、Input、Dialog等)
- 遵循TDesign设计规范实现界面
- 配置TDesign主题与样式定制
- 搭建AI聊天界面(使用TDesign Chat组件)
- 实现深色模式适配
Quick Start
快速开始
Installation
安装
bash
npm i tdesign-miniprogram -S --productionbash
npm i tdesign-miniprogram -S --productionModify app.json
修改app.json
Remove from to avoid style conflicts.
"style": "v2"app.json从app.json中移除以避免样式冲突。
"style": "v2"Modify project.config.json
修改project.config.json
Add the following to the section of :
settingproject.config.jsonjson
{
"setting": {
"packNpmManually": true,
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./"
}
]
}
}在project.config.json的部分添加以下配置:
settingjson
{
"setting": {
"packNpmManually": true,
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./"
}
]
}
}Modify tsconfig.json (TypeScript projects)
修改tsconfig.json(TypeScript项目)
json
{
"paths": {
"tdesign-miniprogram/*": [
"./miniprogram/miniprogram_npm/tdesign-miniprogram/*"
]
}
}After modifying project.config.json, build npm in WeChat DevTools:Tools - Build npm
After successful build, checkCompile JS to ES5
json
{
"paths": {
"tdesign-miniprogram/*": [
"./miniprogram/miniprogram_npm/tdesign-miniprogram/*"
]
}
}修改project.config.json后,在微信开发者工具中执行工具 - 构建npm
构建成功后,勾选将JS编译为ES5
Using Components
使用组件
Import in page or component JSON file:
json
{
"usingComponents": {
"t-button": "tdesign-miniprogram/button/button"
}
}Use in WXML:
html
<t-button theme="primary">Button</t-button>在页面或组件的JSON文件中引入:
json
{
"usingComponents": {
"t-button": "tdesign-miniprogram/button/button"
}
}在WXML中使用:
html
<t-button theme="primary">Button</t-button>Component Categories
组件分类
Basic Components (6)
基础组件(6个)
| Component | Description | Import Path |
|---|---|---|
| Button | Button | |
| Divider | Divider | |
| Fab | Floating Action Button | |
| Icon | Icon | |
| Layout | Layout | |
| Link | Link | |
| 组件 | 说明 | 引入路径 |
|---|---|---|
| Button | 按钮 | |
| Divider | 分割线 | |
| Fab | 悬浮操作按钮 | |
| Icon | 图标 | |
| Layout | 布局 | |
| Link | 链接 | |
Navigation Components (8)
导航组件(8个)
| Component | Description | Import Path |
|---|---|---|
| BackTop | Back to Top | |
| Drawer | Drawer | |
| Indexes | Index List | |
| Navbar | Navigation Bar | |
| SideBar | Side Navigation | |
| Steps | Steps | |
| TabBar | Bottom Tab Bar | |
| Tabs | Tabs | |
| 组件 | 说明 | 引入路径 |
|---|---|---|
| BackTop | 返回顶部 | |
| Drawer | 抽屉 | |
| Indexes | 索引列表 | |
| Navbar | 导航栏 | |
| SideBar | 侧边导航 | |
| Steps | 步骤条 | |
| TabBar | 底部标签栏 | |
| Tabs | 标签页 | |
Input Components (16)
输入组件(16个)
| Component | Description | Import Path |
|---|---|---|
| Calendar | Calendar | |
| Cascader | Cascader | |
| CheckBox | Checkbox | |
| DateTimePicker | Date Time Picker | |
| Input | Input | |
| Picker | Picker | |
| Radio | Radio | |
| Rate | Rate | |
| Search | Search | |
| Slider | Slider | |
| Stepper | Stepper | |
| Switch | Switch | |
| Textarea | Textarea | |
| TreeSelect | Tree Select | |
| Upload | Upload | |
| Form | Form | |
| 组件 | 说明 | 引入路径 |
|---|---|---|
| Calendar | 日历 | |
| Cascader | 级联选择器 | |
| CheckBox | 复选框 | |
| DateTimePicker | 日期时间选择器 | |
| Input | 输入框 | |
| Picker | 选择器 | |
| Radio | 单选框 | |
| Rate | 评分 | |
| Search | 搜索框 | |
| Slider | 滑块 | |
| Stepper | 步进器 | |
| Switch | 开关 | |
| Textarea | 多行输入框 | |
| TreeSelect | 树形选择 | |
| Upload | 上传 | |
| Form | 表单 | |
Data Display Components (18)
数据展示组件(18个)
| Component | Description | Import Path |
|---|---|---|
| Avatar | Avatar | |
| Badge | Badge | |
| Cell | Cell | |
| Collapse | Collapse | |
| CountDown | Countdown | |
| Empty | Empty State | |
| Footer | Footer | |
| Grid | Grid | |
| Image | Image | |
| ImageViewer | Image Viewer | |
| Progress | Progress | |
| Result | Result | |
| Skeleton | Skeleton | |
| Sticky | Sticky | |
| Swiper | Swiper | |
| Table | Table | |
| Tag | Tag | |
| List | List | |
| 组件 | 说明 | 引入路径 |
|---|---|---|
| Avatar | 头像 | |
| Badge | 徽标 | |
| Cell | 单元格 | |
| Collapse | 折叠面板 | |
| CountDown | 倒计时 | |
| Empty | 空状态 | |
| Footer | 页脚 | |
| Grid | 宫格 | |
| Image | 图片 | |
| ImageViewer | 图片预览 | |
| Progress | 进度条 | |
| Result | 结果页 | |
| Skeleton | 骨架屏 | |
| Sticky | 吸顶 | |
| Swiper | 轮播图 | |
| Table | 表格 | |
| Tag | 标签 | |
| List | 列表 | |
Feedback Components (12)
反馈组件(12个)
| Component | Description | Import Path |
|---|---|---|
| ActionSheet | Action Sheet | |
| Dialog | Dialog | |
| DropdownMenu | Dropdown Menu | |
| Guide | Guide | |
| Loading | Loading | |
| Message | Message | |
| NoticeBar | Notice Bar | |
| Overlay | Overlay | |
| Popup | Popup | |
| PullDownRefresh | Pull Down Refresh | |
| SwipeCell | Swipe Cell | |
| Toast | Toast | |
| 组件 | 说明 | 引入路径 |
|---|---|---|
| ActionSheet | 操作面板 | |
| Dialog | 对话框 | |
| DropdownMenu | 下拉菜单 | |
| Guide | 引导提示 | |
| Loading | 加载提示 | |
| Message | 消息提示 | |
| NoticeBar | 通知栏 | |
| Overlay | 遮罩层 | |
| Popup | 弹出层 | |
| PullDownRefresh | 下拉刷新 | |
| SwipeCell | 滑动单元格 | |
| Toast | 轻提示 | |
AI Chat Components (9)
AI聊天组件(9个)
| Component | Description | Import Path |
|---|---|---|
| ChatList | Chat List | |
| ChatMessage | Chat Message | |
| ChatSender | Chat Sender | |
| ChatContent | Chat Content | |
| ChatActionbar | Chat Action Bar | |
| ChatLoading | Chat Loading | |
| ChatMarkdown | Chat Markdown | |
| ChatThinking | Chat Thinking | |
| Attachments | Attachments | |
| 组件 | 说明 | 引入路径 |
|---|---|---|
| ChatList | 聊天列表 | |
| ChatMessage | 聊天消息 | |
| ChatSender | 聊天输入框 | |
| ChatContent | 聊天内容 | |
| ChatActionbar | 聊天操作栏 | |
| ChatLoading | 聊天加载状态 | |
| ChatMarkdown | 聊天Markdown渲染 | |
| ChatThinking | 思考状态提示 | |
| Attachments | 附件选择器 | |
Common Patterns
常用示例
Button
按钮
html
<!-- Basic Buttons -->
<t-button theme="primary" size="large">Primary Button</t-button>
<t-button theme="light" size="large">Light Button</t-button>
<t-button size="large">Default Button</t-button>
<!-- Outline and Text Buttons -->
<t-button theme="primary" size="large" variant="outline"
>Outline Button</t-button
>
<t-button theme="primary" size="large" variant="text">Text Button</t-button>
<!-- Icon Button -->
<t-button
theme="primary"
icon="app"
content="Icon Button"
size="large"
></t-button>
<!-- Loading State -->
<t-button theme="primary" size="large" loading>Loading</t-button>
<!-- Disabled State -->
<t-button theme="primary" size="large" disabled>Disabled</t-button>
<!-- Block Button -->
<t-button theme="primary" size="large" block>Block Button</t-button>
<!-- Ghost Button (transparent background) -->
<t-button theme="primary" ghost size="large">Ghost Button</t-button>html
<!-- 基础按钮 -->
<t-button theme="primary" size="large">主按钮</t-button>
<t-button theme="light" size="large">浅色按钮</t-button>
<t-button size="large">默认按钮</t-button>
<!-- 轮廓与文字按钮 -->
<t-button theme="primary" size="large" variant="outline"
>轮廓按钮</t-button
>
<t-button theme="primary" size="large" variant="text">文字按钮</t-button>
<!-- 图标按钮 -->
<t-button
theme="primary"
icon="app"
content="图标按钮"
size="large"
></t-button>
<!-- 加载状态 -->
<t-button theme="primary" size="large" loading>加载中</t-button>
<!-- 禁用状态 -->
<t-button theme="primary" size="large" disabled>已禁用</t-button>
<!-- 块级按钮 -->
<t-button theme="primary" size="large" block>块级按钮</t-button>
<!-- 幽灵按钮(透明背景) -->
<t-button theme="primary" ghost size="large">幽灵按钮</t-button>Input
输入框
json
{
"usingComponents": {
"t-input": "tdesign-miniprogram/input/input"
}
}html
<t-input
label="Label"
placeholder="Please enter"
value="{{value}}"
bind:change="onChange"
/>json
{
"usingComponents": {
"t-input": "tdesign-miniprogram/input/input"
}
}html
<t-input
label="标签"
placeholder="请输入"
value="{{value}}"
bind:change="onChange"
/>Dialog
对话框
json
{
"usingComponents": {
"t-dialog": "tdesign-miniprogram/dialog/dialog"
}
}html
<t-dialog
visible="{{visible}}"
title="Dialog Title"
content="Dialog content"
confirm-btn="Confirm"
cancel-btn="Cancel"
bind:confirm="onConfirm"
bind:cancel="onCancel"
/>json
{
"usingComponents": {
"t-dialog": "tdesign-miniprogram/dialog/dialog"
}
}html
<t-dialog
visible="{{visible}}"
title="对话框标题"
content="对话框内容"
confirm-btn="确认"
cancel-btn="取消"
bind:confirm="onConfirm"
bind:cancel="onCancel"
/>Toast
轻提示
javascript
import Toast from 'tdesign-miniprogram/toast/index';
Toast({
context: this,
selector: '#t-toast',
message: 'Toast message',
});javascript
import Toast from 'tdesign-miniprogram/toast/index';
Toast({
context: this,
selector: '#t-toast',
message: '提示信息',
});AI Chat Interface
AI聊天界面
json
{
"usingComponents": {
"t-chat-list": "tdesign-miniprogram/chat-list/chat-list",
"t-chat-message": "tdesign-miniprogram/chat-message/chat-message",
"t-chat-sender": "tdesign-miniprogram/chat-sender/chat-sender"
}
}html
<t-chat-list layout="single">
<t-chat-message
avatar="{{item.avatar}}"
name="{{item.name}}"
content="{{item.content}}"
role="{{item.role}}"
/>
<view slot="footer">
<t-chat-sender bind:send="onSend" />
</view>
</t-chat-list>javascript
Component({
data: {
messages: [
{
role: 'user',
content: [{ type: 'text', data: 'Hello' }],
},
{
role: 'assistant',
content: [{ type: 'text', data: 'Hello! How can I help you?' }],
},
],
},
methods: {
onSend(e) {
const { value } = e.detail;
// Handle send message
},
},
});json
{
"usingComponents": {
"t-chat-list": "tdesign-miniprogram/chat-list/chat-list",
"t-chat-message": "tdesign-miniprogram/chat-message/chat-message",
"t-chat-sender": "tdesign-miniprogram/chat-sender/chat-sender"
}
}html
<t-chat-list layout="single">
<t-chat-message
avatar="{{item.avatar}}"
name="{{item.name}}"
content="{{item.content}}"
role="{{item.role}}"
/>
<view slot="footer">
<t-chat-sender bind:send="onSend" />
</view>
</t-chat-list>javascript
Component({
data: {
messages: [
{
role: 'user',
content: [{ type: 'text', data: '你好' }],
},
{
role: 'assistant',
content: [{ type: 'text', data: '你好!请问有什么可以帮你的?' }],
},
],
},
methods: {
onSend(e) {
const { value } = e.detail;
// 处理发送消息逻辑
},
},
});Style Customization
样式定制
Method 1: Using Style Attribute
方法1:使用style属性
html
<t-button style="color: red">Custom Style</t-button>
<t-button custom-style="color: red">Custom Style</t-button>html
<t-button style="color: red">自定义样式按钮</t-button>
<t-button custom-style="color: red">自定义样式按钮</t-button>Method 2: Disable Style Isolation
方法2:关闭样式隔离
Override styles directly in page:
css
.t-button--primary {
background-color: navy;
}In custom components, enable :
styleIsolationjavascript
Component({
options: {
styleIsolation: 'shared',
},
});在页面中直接覆盖样式:
css
.t-button--primary {
background-color: navy;
}在自定义组件中,开启:
styleIsolationjavascript
Component({
options: {
styleIsolation: 'shared',
},
});Method 3: External Style Classes
方法3:外部样式类
html
<t-button t-class="my-button-class">Button</t-button>css
.my-button-class {
background-color: navy !important;
}html
<t-button t-class="my-button-class">按钮</t-button>css
.my-button-class {
background-color: navy !important;
}Method 4: CSS Variables
方法4:CSS变量
TDesign provides rich CSS variables for theme customization:
css
page {
--td-button-primary-bg-color: #0052d9;
--td-button-border-radius: 8rpx;
}TDesign提供丰富的CSS变量用于主题定制:
css
page {
--td-button-primary-bg-color: #0052d9;
--td-button-border-radius: 8rpx;
}Dark Mode
深色模式
1. Modify app.json
1. 修改app.json
json
{
"darkmode": true
}json
{
"darkmode": true
}2. Import Design Token
2. 引入设计令牌
In :
app.wxsscss
@import 'miniprogram_npm/tdesign-miniprogram/common/style/theme/_index.wxss';在中:
app.wxsscss
@import 'miniprogram_npm/tdesign-miniprogram/common/style/theme/_index.wxss';3. Use CSS Variables
3. 使用CSS变量
css
.text {
color: var(--td-text-color-secondary);
}css
.text {
color: var(--td-text-color-secondary);
}4. Special Component Adaptation
4. 特殊组件适配
For components wrapped in or , add class:
custom-tab-barroot-portal.pagehtml
<view class="page">
<t-tab-bar />
</view>对于被或包裹的组件,添加类:
custom-tab-barroot-portal.pagehtml
<view class="page">
<t-tab-bar />
</view>Reference Files
参考文档
This skill includes comprehensive documentation in :
references/本技能在目录下包含完整文档:
references/Basic Documentation
基础文档
- miniprogram/getting-started.md - Quick start guide
- miniprogram/overview.md - Component overview
- miniprogram/custom-style.md - Style customization
- miniprogram/custom-theme.md - Theme customization
- miniprogram/dark-mode.md - Dark mode
- miniprogram/getting-started.md - 快速开始指南
- miniprogram/overview.md - 组件概览
- miniprogram/custom-style.md - 样式定制
- miniprogram/custom-theme.md - 主题定制
- miniprogram/dark-mode.md - 深色模式
Component Documentation (miniprogram/components/)
组件文档(miniprogram/components/)
- button.md - Button
- input.md - Input
- dialog.md - Dialog
- form.md - Form
- ... more component docs
- button.md - 按钮组件
- input.md - 输入框组件
- dialog.md - 对话框组件
- form.md - 表单组件
- ... 更多组件文档
AI Chat Component Documentation (miniprogram-chat/)
AI聊天组件文档(miniprogram-chat/)
- getting-started.md - Chat component quick start
- sse.md - SSE streaming
- components/chat-message.md - Chat message
- components/chat-sender.md - Chat sender
- components/chat-list.md - Chat list
- ... more chat component docs
Use tool to access specific reference files when detailed API information is needed.
Read- getting-started.md - 聊天组件快速开始
- sse.md - SSE流式传输
- components/chat-message.md - 聊天消息组件
- components/chat-sender.md - 聊天输入组件
- components/chat-list.md - 聊天列表组件
- ... 更多聊天组件文档
需要详细API信息时,可使用工具访问具体参考文档。
ReadKey Requirements
核心要求
- Minimum base library version:
^2.12.0 - Build npm in WeChat DevTools required
- Remove from
"style": "v2"app.json
- 最低基础库版本:
^2.12.0 - 需在微信开发者工具中构建npm
- 从app.json中移除
"style": "v2"
Resources
相关资源
Notes
注意事项
- This skill was automatically generated from TDesign official documentation
- Reference files preserve the structure and examples from source docs
- Some reference content remains in Chinese as per official documentation
- 本技能由TDesign官方文档自动生成
- 参考文档保留了源文档的结构与示例
- 部分参考内容保留官方文档中的中文表述