Skip to content

Commit 7dbd4e0

Browse files
Feature/add chat record (#4391)
* feat: add chat-record component 新增chat-record 语音输入组件 * feat: 新增语音书输入插件 BREAKING CHANGE: 新增语音输入组件 * feat: 新增语音输入组件 * feat(chat-record 组件样式调整): chat-record 组件样式调整 * feat(chat-record 组件样式优化): chat-record 组件样式优化 * feat: 更新chat-record 组件文档 * feat: 更新chat-record 组件文档 * feat: chat-record 组件交互更改 * feat: chat-record 组件demo调整 * feat: chat-record 组件,麦克风权限相关问题修改 * feat: chat-record bug 修复 * feat(chat-record demo bug修复): chat-record demo 修复 * feat: chat-record 组件bug修复 * feat: 删除快码插件配置 * feat: 还原setting.json文件
1 parent e895c9b commit 7dbd4e0

File tree

7 files changed

+141
-4
lines changed

7 files changed

+141
-4
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"editor.defaultFormatter": "esbenp.prettier-vscode"
4848
},
4949
"cSpell.words": [
50-
"stylelint",
50+
"stylelint",
5151
"cascader",
5252
"tdesign",
5353
"uniapp",

packages/pro-components/chat/attachments/attachments.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
align-items: center;
143143
justify-content: center;
144144

145-
image {
145+
.attachment-image {
146146
width: 100%;
147147
height: 100%;
148148
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
Page({
2+
/**
3+
* 页面的初始数据
4+
*/
5+
data: {
6+
query: '', // 输入框内容
7+
placeholder: '请输入内容', // 输入框占位符
8+
loading: false, // 发送按钮加载状态
9+
showVoice: false, // 是否显示语音输入组件
10+
allowSpeech: 'keyboard',
11+
},
12+
13+
/**
14+
* 返回上一页
15+
*/
16+
navigateBack() {
17+
wx.navigateBack({
18+
delta: 1,
19+
});
20+
},
21+
22+
/**
23+
* 处理输入框内容变化
24+
*/
25+
handleInput(e) {
26+
this.setData({
27+
query: e.detail.value,
28+
});
29+
},
30+
31+
/**
32+
* 切换语音输入显示状态
33+
*/
34+
handleVoice() {
35+
const showVoice = !this.data.showVoice;
36+
this.setData({
37+
showVoice,
38+
allowSpeech: showVoice ? 'speech' : 'keyboard',
39+
});
40+
},
41+
42+
toggleVoiceIcon() {
43+
this.setData({
44+
allowSpeech: this.data.allowSpeech === 'keyboard' ? 'speech' : 'keyboard',
45+
});
46+
},
47+
48+
49+
/**
50+
* 语音识别回调
51+
* @param {Object} e - 事件对象
52+
*/
53+
handleRecognize(e) {
54+
const voiceMsg = e.detail;
55+
console.log('语音识别结果:', voiceMsg);
56+
57+
// 将语音识别结果设置到输入框中
58+
this.setData({
59+
query: voiceMsg.voiceText,
60+
showVoice: false, // 识别完成后隐藏语音输入组件
61+
allowSpeech: 'keyboard',
62+
});
63+
64+
// 提示用户
65+
wx.showToast({
66+
title: '识别成功',
67+
icon: 'success',
68+
duration: 1500,
69+
});
70+
},
71+
72+
/**
73+
* 发送消息
74+
*/
75+
handleSend() {
76+
const { query, loading } = this.data;
77+
78+
// 如果正在加载或内容为空,不处理
79+
if (loading || !query.trim()) {
80+
if (!query.trim()) {
81+
wx.showToast({
82+
title: '请输入内容',
83+
icon: 'none',
84+
duration: 1500,
85+
});
86+
}
87+
return;
88+
}
89+
// 设置加载状态
90+
this.setData({
91+
loading: true,
92+
});
93+
94+
// 模拟发送请求
95+
setTimeout(() => {
96+
this.setData({
97+
loading: false,
98+
query: '', // 清空输入框
99+
});
100+
101+
wx.showToast({
102+
title: '发送成功',
103+
icon: 'success',
104+
duration: 1500,
105+
});
106+
}, 1000);
107+
},
108+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
:deep(.chat-sender-placeholder) {
2+
--demo-chat-sender-placeholder: rgba(0, 0, 0, 0.1);
3+
}
4+
5+
@media (prefers-color-scheme: dark) {
6+
:deep(.chat-sender-placeholder) {
7+
--demo-chat-sender-placeholder: rgba(255, 255, 255, 0.1);
8+
}
9+
}
10+
11+
.t-button {
12+
margin-right: 32rpx;
13+
}
14+
15+
.t-button:last-child {
16+
margin-right: 0;
17+
}

packages/pro-components/chat/chat-sender/props.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ const props: TdChatSenderProps = {
4848
/** 预设发送区渲染配置,用于灵活配置发送区的上传入口和发送按钮,支持自定义类型、顺序、样式 */
4949
renderPresets: {
5050
type: Array,
51-
value: [{name: 'upload', presets: ['uploadCamera', 'uploadImage', 'uploadAttachment'], status: ''},{ name: 'send', type: 'icon'}],
51+
value: [
52+
{ name: 'upload', presets: ['uploadCamera', 'uploadImage', 'uploadAttachment'], status: '' },
53+
{ name: 'send', type: 'icon' },
54+
],
5255
},
5356
/** 透传给 Textarea 组件的属性,autosize数值单位为 rpx */
5457
textareaProps: {
@@ -60,6 +63,11 @@ const props: TdChatSenderProps = {
6063
type: String,
6164
value: '',
6265
},
66+
// 输入类型, keyboard-键盘输入,speech-语音输入
67+
allowSpeech: {
68+
type: String,
69+
value: 'keyboard',
70+
},
6371
/** 上传面板是否可见 */
6472
visible: {
6573
type: Boolean,

packages/pro-components/chat/chat-sender/type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ export interface TdChatSenderProps {
9494
type: StringConstructor;
9595
value?: string;
9696
};
97+
allowSpeech?: {
98+
type: StringConstructor;
99+
value?: 'keyboard' | 'speech';
100+
};
97101
/**
98102
* 上传面板是否可见
99103
* @default false

packages/tdesign-miniprogram/example/project.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,4 @@
505505
}
506506
}
507507
}
508-
}
508+
}

0 commit comments

Comments
 (0)