@tencentcloud/sdk-mcp 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/package.json +2 -2
  2. package/resource/doc/chatuikit/react/integration.md +516 -48
  3. package/resource/doc/chatuikit/react/workflow.md +254 -0
  4. package/resource/doc/chatuikit/uniapp-app/faq.md +0 -0
  5. package/resource/doc/chatuikit/uniapp-app/integration.md +619 -0
  6. package/resource/doc/chatuikit/uniapp-app/workflow.md +576 -0
  7. package/resource/doc/chatuikit/vue/integration.md +511 -129
  8. package/resource/doc/chatuikit/vue/workflow.md +395 -0
  9. package/tools/chat/get-web-chat-integration.js +31 -14
  10. package/tools/chat/get-web-chat-integration.js.map +1 -1
  11. package/tools/definitions/get_web_chat_uikit_integration_def.js +18 -11
  12. package/tools/definitions/get_web_chat_uikit_integration_def.js.map +1 -1
  13. package/tools/definitions/present_framework_choice_def.js +1 -1
  14. package/tools/definitions/record_result_def.js +1 -1
  15. package/tools/definitions/record_result_def.js.map +1 -1
  16. package/tools/index.js +0 -2
  17. package/tools/index.js.map +1 -1
  18. package/tools/live/get-web-live-uikit-integration.js +1 -1
  19. package/utils/generate-structured-result.js +2 -2
  20. package/utils/generate-structured-result.js.map +1 -1
  21. package/utils/report-cls-client.js +1 -1
  22. package/utils/report-es-client.js +1 -1
  23. package/resource/doc/chatuikit/react/chat_window_integration.md +0 -83
  24. package/resource/doc/chatuikit/vue/chat_window_integration.md +0 -131
  25. package/tools/chat/get-web-chat-window-integration.js +0 -28
  26. package/tools/chat/get-web-chat-window-integration.js.map +0 -1
  27. package/tools/definitions/get_web_chat_window_integration_def.js +0 -26
  28. package/tools/definitions/get_web_chat_window_integration_def.js.map +0 -1
@@ -1,186 +1,568 @@
1
- AI 模型必须遵守以下**硬性限制**。
2
- * **严格文档步骤集成:** 在集成组件时必须按照文档步骤和说明进行,且在 1.1 中不需要执行 `npm run dev` or `pnpm run dev`, 集成完成后按照 1.4 启动项目。
3
- * **严格使用文档中的示例代码:** 创建文件时必须严格使用文档中的示例代码填充文件, style 标签优先推荐不使用 scoped 属性。
4
- * **打开默认会话:** 必须使用 `setActiveConversation` 打开 `C2Cadministrator` 会话。
5
- * **调用工具获取 userSig:** 必须先按照文档下载和集成 TUIKit 代码后,再自动生成测试 userID 并调用工具 `get_usersig` 获取 userSig,userID 不需要拼接时间戳,避免动态计算出错。
6
- * **账号信息填写:** 获取到 userSig 后把 SDKAppID、userID、 userSig 自动填写到代码中。
7
- * **禁止创建用户信息配置文件:** 不得自动创建填写 SDKAppID、userID、userSig 的 config 目录或文件。
1
+ TUIKit 是基于腾讯云 Chat SDK 的一款 Vue 3 UI 组件库,它提供了一些通用的 UI 组件,包含会话、聊天、群组等功能。本文介绍如何快速集成 TUIKit 并实现核心功能。
8
2
 
9
- # chat-uikit-vue3 Integration
3
+ > **说明:**
4
+ >
10
5
 
11
- 用户的集成需求一般有两种,你必须理性分析需求到底属于哪一种:
12
- 1. 普通集成:指集成 ConversationList、Chat、ChatHeader、MessageList、MessageInput、ContactList、ContactInfo 等组件,具体信息必须阅读第 2.1 节 “最佳实践-普通集成”。
13
- 2. 集成通话功能:指在普通集成的基础上,集成通话功能,具体信息必须阅读第 2.2 节 “最佳实践-集成通话功能”。
6
+ > 您好!我们正在开发一款即时通讯产品 UIKit,它基于腾讯云 Chat SDK,是一款 Vue3 UI 组件库,能帮助您快速集成并实现核心功能。
7
+ >
14
8
 
9
+ > **为了更好地提升我们的产品,了解您的需求**,特邀请您[参与本次问卷调查](https://wj.qq.com/s2/25022971/d8b4/)。
10
+ >
15
11
 
16
- ## 1 普通集成
12
+ > 您的反馈我们会**高度重视**,本问卷填写**仅需要 30 秒**!诚邀您的参与。
13
+ >
17
14
 
18
- ### 1.1 step1:create vue3 project
19
15
 
20
- if you don't have a vue3 project, you can use vite create a vue3 project. otherwise, you can skip this step.
16
+ > **推荐使用更高效的 AI 集成助手**
17
+ >
21
18
 
22
- requirement: vue3: ^3.0.0, nodejs: ^22.0.0.
19
+ > 我们为您提供了全新的 AI 集成方式,只需要简单描述您的需求,即可**自动生成集成代码**,大幅提升开发效率。
20
+ >
23
21
 
24
- if it is a new project, guide the user to use vite to create a vue3 project manually, and then continue with step 1.2. if it is an existing project, skip this step and continue with step 1.2.
22
+ > [点击这里,立即体验 AI 集成](https://cloud.tencent.com/document/product/269/124481)
23
+ >
25
24
 
26
- ```bash
27
- pnpm create vite@latest
28
- # skip some settings
29
- cd ${your-vue-project-name}
30
- pnpm install
25
+
26
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100033438418/38ff95e4c9ec11f0a93d52540044a08e.png)
27
+
28
+
29
+ ## 关键概念
30
+
31
+ chat-uikit-vue3 主要分为 ConversationList、Chat、MessageList、ChatHeader、MessageInput、ChatSetting、Search、Contact 等核心 UI 组件,每个 UI 组件负责展示不同的内容。
32
+ 1. ConversationList 提供会话列表组件。
33
+
34
+ 2. Chat 提供会话的容器组件。
35
+
36
+ 3. MessageList 提供会话的消息列表组件。
37
+
38
+ 4. ChatHeader 提供会话的头部信息组件。
39
+
40
+ 5. MessageInput 提供输入框组件。
41
+
42
+ 6. ChatSetting 提供单聊和群聊的管理组件。
43
+
44
+ 7. Search 提供云端搜索组件。
45
+
46
+ 8. Contact 提供联系人组件。
47
+
48
+
49
+ ## 前提条件
50
+ - Vue.js@^3.0.0
51
+
52
+ - TypeScript@^5.0.0
53
+
54
+ - Node.js(Node.js ≥ 20.0.0,建议使用目前的 LTS v22 版本)
55
+
56
+
57
+ ## 创建项目
58
+
59
+ 使用 Vite 创建一个新的名称为 **chat-example** 的 Vue3 项目。
60
+
61
+ > **说明:**
62
+ >
63
+
64
+ > 高版本 Vite 需要使用最新的 Node.js 版本。
65
+ >
66
+
67
+
68
+
69
+ 【shell】
70
+ ``` bash
71
+ npm create vite@latest
72
+ ```
73
+
74
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027116646/f67b7f3a886611f0b321525400e889b2.png)
75
+
76
+
77
+ ## 下载并导入组件
78
+
79
+ 创建项目完成后,切换到项目所在目录。
80
+
81
+
82
+ 【shell】
83
+ ``` bash
84
+ cd chat-example
85
+ npm install
31
86
  ```
32
87
 
33
- ### 1.2 step2: install chat-uikit-vue3
88
+ ### 步骤1:安装依赖
89
+
90
+
91
+ 【shell】
92
+ ``` bash
93
+ npm i @tencentcloud/chat-uikit-vue3
94
+ ```
95
+
96
+ ### 步骤2:引入组件
97
+
98
+ > **注意:**
99
+ >
100
+ > - 以下代码中未填入 `SDKAppID`、`userID` 和 `userSig`,需在 [步骤3](https://write.woa.com/#e0579535-1fc9-4344-8878-ed25ced85819) 中获取相关信息后进行替换。
101
+ > - 为了尊重版权,下图所示的**默认小黄脸表情包版权属于腾讯云**,您可以通过升级至 [IM 企业版套餐](https://buy.cloud.tencent.com/avc) 免费使用该表情包。
102
+
103
+ > ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027116646/d9f2ac13886711f0bd05525400454e06.png)
104
+ >
34
105
 
35
- use npm or pnpm to install @tencentcloud/chat-uikit-vue3@latest @tencentcloud/call-uikit-vue@latest
36
106
 
37
- ### 1.3 step3: add main content to your project
107
+ #### 2.1 搭建主界面
38
108
 
39
- ```vue
109
+ 例如:在 `src/App.vue` 页面中写入以下代码:
110
+ ``` typescript
40
111
  <template>
41
- <UIKitProvider language="zh-CN">
112
+ <UIKitProvider language="zh-CN" theme="light">
42
113
  <div class="chat-layout">
43
- <div class="sidebar" style="width: 300px;">
44
- <div class="tab-header">
45
- <button
46
- :class="['tab-button', { active: activeTab === 'conversations' }]"
47
- @click="activeTab = 'conversations'"
48
- >
49
- 会话
50
- </button>
51
- <button
52
- :class="['tab-button', { active: activeTab === 'contacts' }]"
53
- @click="activeTab = 'contacts'"
54
- >
55
- 联系人
56
- </button>
57
- </div>
58
-
59
- <div class="tab-content">
60
- <ConversationList v-if="activeTab === 'conversations'" />
61
- <ContactList v-else />
62
- </div>
114
+ <!-- 左侧导航 -->
115
+ <SideTab :active-tab="activeTab" @tab-change="handleTabChange" />
116
+
117
+ <!-- 中间列表 -->
118
+ <div class="conversation-list-panel">
119
+ <ConversationList v-show="activeTab === 'conversations'" />
120
+ <ContactList v-show="activeTab === 'contacts'" />
63
121
  </div>
64
122
 
65
- <Chat style="flex: 1;" v-if="activeTab === 'conversations'">
66
- <ChatHeader />
123
+ <!-- 右侧聊天 -->
124
+ <Chat
125
+ v-show="activeTab === 'conversations'"
126
+ class="chat-content-panel"
127
+ :PlaceholderEmpty="EmptyChatTpl"
128
+ >
129
+ <ChatHeader>
130
+ <template #ChatHeaderRight>
131
+ <button class="icon-button" @click="isChatSettingShow = !isChatSettingShow">
132
+ <IconMenu size="20" />
133
+ </button>
134
+ </template>
135
+ </ChatHeader>
67
136
  <MessageList />
68
- <MessageInput />
137
+ <MessageInput class="message-input-container">
138
+ <template #headerToolbar>
139
+ <div class="message-toolbar">
140
+ <div class="message-toolbar-actions">
141
+ <EmojiPicker />
142
+ <FilePicker />
143
+ <VideoPicker />
144
+ <ImagePicker />
145
+ <!-- 参考文档开通音视频通话服务 -->
146
+ <!-- <AudioCallPicker />
147
+ <VideoCallPicker /> -->
148
+ </div>
149
+ <button class="icon-button" @click="isSearchInChatShow = !isSearchInChatShow">
150
+ <IconSearch size="20" />
151
+ </button>
152
+ </div>
153
+ </template>
154
+ </MessageInput>
155
+
156
+ <!-- 聊天设置侧边栏 -->
157
+ <div v-show="isChatSettingShow" class="chat-sidebar" :class="{ dark: theme === 'dark' }">
158
+ <div class="chat-sidebar-header">
159
+ <span class="chat-sidebar-title">设置</span>
160
+ <button class="icon-button" @click="isChatSettingShow = false">✕</button>
161
+ </div>
162
+ <ChatSetting />
163
+ </div>
164
+
165
+ <!-- 会话内搜索侧边栏 -->
166
+ <div v-show="isSearchInChatShow" class="chat-sidebar" :class="{ dark: theme === 'dark' }">
167
+ <div class="chat-sidebar-header">
168
+ <span class="chat-sidebar-title">群搜索</span>
169
+ <button class="icon-button" @click="isSearchInChatShow = false">✕</button>
170
+ </div>
171
+ <Search :variant="VariantType.EMBEDDED" />
172
+ </div>
69
173
  </Chat>
70
- <ContactInfo v-else style="flex: 1;" @send-message="handleSendMessage" @enter-group="handleSendMessage" />
174
+
175
+ <!-- 联系人详情 -->
176
+ <ContactInfo
177
+ v-show="activeTab === 'contacts'"
178
+ class="contact-detail-panel"
179
+ @send-message="handleSendMessage"
180
+ />
71
181
  </div>
72
- <Teleport to="body">
73
- <TUICallKit style="position: fixed; z-index: 1000;"/>
74
- </Teleport>
75
182
  </UIKitProvider>
76
183
  </template>
77
184
 
78
185
  <script setup lang="ts">
79
- import { ref } from 'vue';
186
+ import { ref, h, watch } from 'vue';
80
187
  import {
81
- ConversationList,
82
- Chat,
83
- MessageList,
84
- MessageInput,
85
- ChatHeader,
86
- ContactList,
87
- ContactInfo,
88
- UIKitProvider,
89
- useLoginState,
90
- useConversationListState,
188
+ Chat, Search, ChatHeader, MessageList, MessageInput, ContactList, ContactInfo, ChatSetting, UIKitProvider, ConversationList, useUIKit, useLoginState, useConversationListState, EmojiPicker, FilePicker, VideoPicker, ImagePicker, VariantType, AudioCallPicker, VideoCallPicker,
91
189
  } from '@tencentcloud/chat-uikit-vue3';
92
- import { TUICallKit } from '@tencentcloud/call-uikit-vue';
93
-
94
- const userID = ''; // TODO: Replace with your userID
95
- const SDKAppID = 0; // TODO: Replace with your SDKAppID (Notice: SDKAppID is of type number)
96
- const userSig = ''; // TODO: Replace with your userSig
190
+ import { IconMenu, IconSearch, TUIToast } from '@tencentcloud/uikit-base-component-vue3';
191
+ import SideTab from './components/SideTab.vue';
97
192
 
193
+ const { theme } = useUIKit();
98
194
  const { login } = useLoginState();
99
- const { setActiveConversation } = useConversationListState();
195
+ const { setActiveConversation, activeConversation } = useConversationListState();
100
196
 
101
197
  const activeTab = ref<'conversations' | 'contacts'>('conversations');
198
+ const isChatSettingShow = ref(false);
199
+ const isSearchInChatShow = ref(false);
102
200
 
201
+ // 切换会话时关闭会话内侧边栏
202
+ watch(() => activeConversation.value?.conversationID, (newVal, oldVal) => {
203
+ if (newVal !== oldVal) {
204
+ isChatSettingShow.value = false;
205
+ isSearchInChatShow.value = false;
206
+ }
207
+ });
208
+
209
+ // 登录
103
210
  login({
104
- sdkAppId : SDKAppID,
105
- userId: userID,
106
- userSig: userSig,
211
+ sdkAppId: 0, // SDKAppID, number 类型
212
+ userId: '', // UserID, string 类型
213
+ userSig: '', // userSig, string 类型
107
214
  })
108
215
  .then(() => {
109
- // 打开默认会话
110
- setActiveConversation('C2Cadministrator');
216
+ const userID = 'administrator';
217
+ const conversationID = `C2C${userID}`;
218
+ setActiveConversation(conversationID);
111
219
  })
112
- .catch(() => {});
220
+ .catch((err) => {
221
+ TUIToast.error({
222
+ message: err.message,
223
+ duration: 5000,
224
+ });
225
+ });
226
+
227
+ const handleTabChange = (tab: 'conversations' | 'contacts') => {
228
+ activeTab.value = tab;
229
+ };
230
+
113
231
  const handleSendMessage = () => {
114
232
  activeTab.value = 'conversations';
115
- }
233
+ };
234
+
235
+ // 空会话占位组件
236
+ const EmptyChatTpl = h('div', { class: 'empty-placeholder' }, [
237
+ h('div', { class: 'empty-icon' }, '💬'),
238
+ h('div', { class: 'empty-title' }, '暂无会话'),
239
+ h('div', { class: 'empty-subtitle' }, '选择一个会话开始聊天'),
240
+ ]);
116
241
  </script>
117
242
 
243
+ <style scoped>
244
+ .chat-layout{width:calc(100vw - 64px);height:calc(100vh - 64px);max-width:1600px;max-height:900px;display:flex;border-radius:16px;box-shadow:0 20px 60px rgba(0,0,0,0.3),0 0 0 1px rgba(255,255,255,0.1);overflow:hidden;backdrop-filter:blur(10px);}.conversation-list-panel{width:300px;display:flex;flex-direction:column;border-right:1px solid var(--stroke-color-primary);overflow:hidden;}.chat-content-panel{flex:1;}.contact-detail-panel{flex:1;}.icon-button{padding:4px 6px;display:flex;align-items:center;justify-content:center;border:none;background:transparent;border-radius:4px;font-size:20px;color:var(--text-color-primary);cursor:pointer;transition:background-color 0.2s;outline:none;}.icon-button:focus{outline:none;}.icon-button:hover{background-color:var(--button-color-secondary-hover);}.icon-button:active{background-color:var(--button-color-secondary-active);}.message-toolbar{display:flex;justify-content:space-between;align-items:center;}.message-toolbar-actions{display:flex;align-items:center;gap:4px;}.chat-sidebar{position:absolute;right:0;top:0;bottom:0;min-width:300px;max-width:400px;display:flex;flex-direction:column;background-color:var(--bg-color-operate);box-shadow:var(--shadow-color) 0 0 10px;overflow:auto;z-index:1000;}.chat-sidebar.dark{box-shadow:-4px 0 16px rgba(0,0,0,0.4),-1px 0 0 rgba(255,255,255,0.1);}.chat-sidebar-header{position:sticky;top:0;display:flex;align-items:center;justify-content:space-between;padding:12px 16px;background-color:var(--bg-color-operate);border-bottom:1px solid var(--stroke-color-primary);z-index:10;}.chat-sidebar-title{font-size:16px;font-weight:500;color:var(--text-color-primary);}.empty-placeholder{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;background-color:var(--bg-color-operate);border-left:1px solid rgba(0,0,0,0.08);color:#adb5bd;}.empty-icon{font-size:64px;opacity:0.3;}.empty-title{font-size:16px;font-weight:600;color:#6c757d;}.empty-subtitle{font-size:14px;color:#868e96;}img[alt="empty"]{display:none;}.message-input-container{border-top:1px solid var(--stroke-color-primary);}.call-kit{position:fixed;top:50%;left:50%;z-index:999;transform:translate(-50%,-50%);max-width:800px;max-height:600px;}
245
+ </style>
246
+
118
247
  <style>
119
- #app{margin:0;padding:0;text-align:left;}.chat-layout{width:100vw;height:100vh;display:flex;}.sidebar{display:flex;flex-direction:column;border-right:1px solid #e5e7eb;}.tab-header{display:flex;border-bottom:1px solid #e5e7eb;}.tab-button{flex:1;padding:12px 16px;background:none;border:none;cursor:pointer;font-size:14px;color:#6b7280;transition:all 0.2s;}.tab-button.active{color:#3b82f6;background-color:#eff6ff;border-bottom:2px solid #3b82f6;}.tab-content{flex:1;overflow:hidden;}
248
+ #app{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%) !important;width:100vw !important;height:100vh !important;text-align:start !important;max-width:none !important;display:flex !important;align-items:center !important;justify-content:center !important}
120
249
  </style>
121
250
  ```
122
251
 
123
- ### 1.4 step4: start your project
124
- ```bash
125
- pnpm run dev
126
- ```
252
+ #### 2.2 引入侧边导航
253
+
254
+ 在 `src/component` 文件夹中新建一个 `SideTab.vue` 的文件,并写入以下内容:
255
+ ``` typescript
256
+ <template>
257
+ <div class="side-tab" :class="{ dark: isDark }">
258
+ <!-- 用户头像 -->
259
+ <div class="avatar-wrapper">
260
+ <Avatar class="avatar" :src="loginUserInfo?.avatarUrl" />
261
+ <div class="tooltip">
262
+ <div class="tooltip-name">{{ loginUserInfo?.userName || '未命名' }}</div>
263
+ <div class="tooltip-id">ID: {{ loginUserInfo?.userId }}</div>
264
+ </div>
265
+ </div>
266
+ <!-- Tab 切换 -->
267
+ <div class="tabs">
268
+ <div
269
+ class="tab-item"
270
+ :class="{ active: props.activeTab === 'conversations' }"
271
+ @click="handleTabChange('conversations')"
272
+ title="会话"
273
+ >
274
+ <IconChatNew size="24" />
275
+ </div>
276
+ <div
277
+ class="tab-item"
278
+ :class="{ active: props.activeTab === 'contacts' }"
279
+ @click="handleTabChange('contacts')"
280
+ title="联系人"
281
+ >
282
+ <IconContacts size="24" />
283
+ </div>
284
+ </div>
285
+ </div>
286
+ </template>
127
287
 
128
- ## 2. 最佳实践
129
288
 
130
- 以下提到的组件通过 MCP Tools get_component_detail ${componenetname.tolowercase()} 获取。
131
- 以下提到的 state 通过 MCP Tools get_state_detail ${statename.tolowercase()} 获取。
289
+ <script lang="ts" setup>
290
+ import { computed } from 'vue';
291
+ import { useLoginState, useUIKit, Avatar } from '@tencentcloud/chat-uikit-vue3';
292
+ import { IconChatNew, IconContacts } from '@tencentcloud/uikit-base-component-vue3';
132
293
 
133
- ### 2.1 最佳实践-普通集成
294
+ const { theme } = useUIKit();
295
+ const { loginUserInfo } = useLoginState();
134
296
 
135
- 普通集成参考 1.3 节中的的代码示例。
297
+ const isDark = computed(() => theme.value === 'dark' || theme.value === 'serious');
136
298
 
137
- 重点:
138
- 1. 如果需要集成 ChatSetting 组件,请阅读 ChatHeader 的 ChatHeaderRight 插槽说明。
299
+ interface Props {
300
+ activeTab?: 'conversations' | 'contacts';
301
+ }
139
302
 
140
- ### 2.2 最佳实践-集成通话功能
303
+ const props = withDefaults(defineProps<Props>(), {
304
+ activeTab: 'conversations'
305
+ });
141
306
 
142
- 集成通话功能需要在普通集成或仅集成聊天基础上,添加通话功能的代码。
307
+ const emit = defineEmits<{
308
+ tabChange: [tab: 'conversations' | 'contacts'];
309
+ }>();
143
310
 
144
- 引入 TUICallKit 组件:
145
- ```vue
146
- <script setup lang="ts">
147
- import { TUICallKit } from '@tencentcloud/call-uikit-vue';
311
+ const handleTabChange = (tab: 'conversations' | 'contacts') => {
312
+ emit('tabChange', tab);
313
+ };
148
314
  </script>
315
+
316
+ <style scoped>
317
+ .side-tab{width:72px;height:100vh;background:var(--bg-color-function);display:flex;flex-direction:column;align-items:center;padding:20px 0;transition:background 0.3s;}.avatar-wrapper{position:relative;margin-bottom:24px;cursor:pointer;}.avatar-wrapper:hover:deep(.avatar){transform:scale(1.05);box-shadow:0 4px 12px rgba(0,0,0,0.15);}.tooltip{position:absolute;left:60px;top:50%;transform:translateY(-50%);padding:8px 12px;background:rgba(0,0,0,0.85);color:#fff;border-radius:6px;white-space:nowrap;opacity:0;visibility:hidden;pointer-events:none;transition:all 0.3s;z-index:1000;}.tooltip::before{content:'';position:absolute;left:-6px;top:50%;transform:translateY(-50%);border:6px solid transparent;border-right-color:rgba(0,0,0,0.85);}.avatar-wrapper:hover .tooltip{opacity:1;visibility:visible;}.tooltip-name{font-size:14px;font-weight:500;margin-bottom:4px;}.tooltip-id{font-size:12px;opacity:0.8;}.tabs{display:flex;flex-direction:column;gap:16px;}.tab-item{width:48px;height:48px;display:flex;align-items:center;justify-content:center;border-radius:12px;cursor:pointer;transition:all 0.3s;color:var(--text-color-primary);}.tab-item:hover{background:rgba(0,0,0,0.05);}.tab-item.active{background:var(--button-color-primary-default);color:var(--text-color-button);}.side-tab.dark{background:#1a1a1a;}.side-tab.dark .avatar-wrapper:hover:deep(.avatar){box-shadow:0 4px 12px rgba(255,255,255,0.2);}.side-tab.dark .tooltip{background:rgba(255,255,255,0.95);color:#1a1a1a;}.side-tab.dark .tooltip::before{border-right-color:rgba(255,255,255,0.95);}.side-tab.dark .tab-item:hover{background:rgba(255,255,255,0.1);}.side-tab.dark .tab-item.active{background:#1890ff;color:#fff;}
318
+ </style>
319
+ ```
320
+
321
+ ### 步骤3:获取 SDKAppID、userID 和 userSig
322
+
323
+ 在上一步的 `src/App.vue`文件中的 login 函数,填入登录信息 SDKAppID、userID 和 userSig。
324
+ ``` java
325
+ // 登录
326
+ login({
327
+ sdkAppId : , // SDKAppID, number 类型
328
+ userId: '', // UserID, string 类型
329
+ userSig: '', // userSig, string 类型
330
+ });
331
+ ```
332
+ <table>
333
+ <tr>
334
+ <td rowspan="1" colSpan="1" >参数</td>
335
+
336
+ <td rowspan="1" colSpan="1" >类型</td>
337
+
338
+ <td rowspan="1" colSpan="1" >说明</td>
339
+ </tr>
340
+
341
+ <tr>
342
+ <td rowspan="1" colSpan="1" >SDKAppID</td>
343
+
344
+ <td rowspan="1" colSpan="1" >Number</td>
345
+
346
+ <td rowspan="1" colSpan="1" >SDKAppID 是腾讯云 IM 客户应用的唯一标识。您可以在 [即时通信 IM 控制台](https://console.cloud.tencent.com/im) 创建新应用,获取 SDKAppID 。<br>**说明:**<br>SDKAppID 是腾讯云 IM 客户应用的唯一标识。我们建议每一个独立的 App 都申请一个新的 SDKAppID。不同 SDKAppID 之间的消息是天然隔离的,不能互通。<br></td>
347
+ </tr>
348
+
349
+ <tr>
350
+ <td rowspan="1" colSpan="1" >userID</td>
351
+
352
+ <td rowspan="1" colSpan="1" >String</td>
353
+
354
+ <td rowspan="1" colSpan="1" >用户的唯一标识符,由您定义,只能包含大小写字母(a-z,A-Z)、数字(0-9)、下划线和连字符。</td>
355
+ </tr>
356
+
357
+ <tr>
358
+ <td rowspan="1" colSpan="1" >userSig</td>
359
+
360
+ <td rowspan="1" colSpan="1" >String</td>
361
+
362
+ <td rowspan="1" colSpan="1" >用户登录即时通信 IM 的密码,其本质是对 UserID 等信息加密后得到的密文。<br>**说明:**<br>开发环境:快速跑通 Demo,可以通过 [即时通信 IM 控制台](https://console.cloud.tencent.com/im) 获取 UserSig。<br>生产环境:将 UserSig 的计算代码集成到您的服务端,并提供面向项目的接口, 正确的 UserSig 签发方式请参见 [服务端生成 UserSig](https://cloud.tencent.com/document/product/269/32688)。<br></td>
363
+ </tr>
364
+ </table>
365
+
366
+
367
+ > **注意:**
368
+ >
369
+
370
+ > 本文示例代码采用在[即时通信 IM 控制台](https://console.cloud.tencent.com/im) 获取 UserSig 的方案,**该方法仅适合本地跑通功能调试**。 正确的 UserSig 签发方式请参见[服务端生成 UserSig](https://cloud.tencent.com/document/product/269/32688)。
371
+ >
372
+
373
+ - SDKAppID:在 [即时通信 IM 控制台 > 应用管理](https://console.cloud.tencent.com/im) 单击**创建新应用**,获取 SDKAppID。
374
+
375
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027116646/748bfda2886c11f088af5254005ef0f7.png)
376
+
377
+ - userID:单击 [即时通信 IM 控制台 > 消息服务 Chat > 账号管理](https://console.cloud.tencent.com/im/account-management),切换至目标应用所在账号,您可以创建 2~3 个账号用于体验单聊、群聊的功能。
378
+
379
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027116646/b9a2b2aa886d11f0ae9d5254001c06ec.png)
380
+
381
+ - userSig:单击 [即时通信 IM 控制台 > 开发工具 > UserSig生成校验](https://console.cloud.tencent.com/im/tool-usersig),切换至目标应用所在账号,填写创建的 UserID,即可生成 UserSig。
382
+
383
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027116646/ea68ff91886e11f0ae9d5254001c06ec.png)
384
+
385
+
386
+ ## 运行和测试
387
+
388
+ 使用以下命令运行项目
389
+
390
+
391
+ 【shell】
392
+ ``` bash
393
+ npm run dev
149
394
  ```
150
395
 
151
- 在合适的位置添加 TUICallKit 组件:
152
- ```vue
153
- <Teleport to="body">
154
- <TUICallKit style="position: fixed; z-index: 1000;"/>
155
- </Teleport>
396
+ > **注意:**
397
+ >
398
+ > 1. 请确保 [步骤3](https://write.woa.com/#step3) 代码中 SDKAppID、userID 和 userSig 均已成功替换,如未替换将会导致项目表现异常。
399
+ > 2. userID 和 userSig 为一一对应关系。
400
+ > 3. 如遇到项目启动失败,请检查 开发环境要求 是否满足。
401
+
402
+
403
+ ## 集成更多高级特性
404
+
405
+ ### 音视频通话
406
+
407
+ > **说明:**
408
+ >
409
+
410
+ > TUICallKit 是腾讯云推出一款音视频通话 UI 组件,通过集成该组件,您只需要编写几行代码就可以在聊天应用中体验音视频通话功能。
411
+ >
412
+
413
+ > 更多详细信息可参考:[音视频通话-开通服务](https://write.woa.com/document/140130594134605824)。
414
+ >
415
+
416
+ 1. 安装 `@tencentcloud/call-uikit-vue` 依赖。
417
+
418
+ ``` bash
419
+ npm install @tencentcloud/call-uikit-vue
420
+ ```
421
+ 2. 从 `@tencentcloud/call-uikit-vue` 导出 `TUICallKit`,并挂载到 DOM 节点上。
422
+
423
+
424
+ 在 `src/App.vue` 文件中继续补充下面的代码:
425
+
426
+ ``` typescript
427
+ // src/App.vue
428
+ <template>
429
+ <UIKitProvider language="zh-CN" theme="light">
430
+ <!-- 挂载音视频通话核心组件 -->
431
+ <TUICallKit class="call-kit" />
432
+ ...
433
+ </UIKitProvider>
434
+ <template>
435
+
436
+ <script setup lang="ts">
437
+ // 导入音视频通话核心组件
438
+ import { TUICallKit } from '@tencentcloud/call-uikit-vue';
439
+ </script>
440
+ ```
441
+ 3. 打开 `<MessageInput />` 组件中 `#headerToolbar` 插槽内的注释。
442
+
443
+ ``` java
444
+ <MessageInput class="message-input-container">
445
+ <template #headerToolbar>
446
+ <div class="message-toolbar">
447
+ <div class="message-toolbar-actions">
448
+ <EmojiPicker />
449
+ <FilePicker />
450
+ <VideoPicker />
451
+ <ImagePicker />
452
+ <AudioCallPicker />
453
+ <VideoCallPicker />
454
+ </div>
455
+ <button class="icon-button" @click="isSearchInChatShow = !isSearchInChatShow">
456
+ <IconSearch size="20" />
457
+ </button>
458
+ </div>
459
+ </template>
460
+ </MessageInput>
461
+ ```
462
+ 4. 拨打语音通话。
463
+
464
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100033438418/ce88eb5ac9f911f0a7775254005ef0f7.png)
465
+
466
+
467
+ ### 云端搜索
468
+
469
+ > **说明:**
470
+ >
471
+
472
+ > 搜索,在客服、社交、在线教育、在线医疗、OA 等场景下是刚需功能,可帮助用户快速查找群组、用户、消息,提升产品使用体验和用户粘性。
473
+ >
474
+
475
+ > 由于 Web 平台本地存储特殊性等原因,Vue **无法实现本地搜索**,为了更好的满足对于搜索能力的需求,推出了**云端搜索能力**。**云端搜索功能支持全局搜索和会话内搜索,同时支持搜索群组、用户和消息。**
476
+ >
477
+
478
+ >
479
+ >
480
+
481
+ > 此功能属于增值服务,需要您购买云端搜索插件,请点击 [购买](https://console.cloud.tencent.com/im/plugin/TUICloudSearch)。
482
+ >
483
+
484
+
485
+ 云端搜索在“步骤 2”中已经默认集成,如果需要关闭云端搜索功能,请参考以下代码:
486
+ 1. 设置 `ConversationList` 的 `enableSearch` 属性为 `false`
487
+
488
+ ``` typescript
489
+ <template>
490
+ <ConversationList v-show="activeTab === 'conversations'" :enable-search="false" />
491
+ </template>
492
+ ```
493
+ 2. 注释会话内搜索侧边栏相关的代码
494
+
495
+ ``` typescript
496
+ <template>
497
+ <Chat>
498
+ <!-- <div v-show="isSearchInChatShow" class="chat-sidebar" :class="{ dark: theme === 'dark' }">
499
+ <div class="chat-sidebar-header">
500
+ <span class="chat-sidebar-title">搜索</span>
501
+ <button class="icon-button" @click="isSearchInChatShow = false">✕</button>
502
+ </div>
503
+ <Search :variant="VariantType.EMBEDDED" />
504
+ </div> -->
505
+ </Chat>
506
+ </template>
507
+ ```
508
+
509
+ ## 常见问题
510
+
511
+ ### 什么是 UserSig?如何生成 UserSig?
512
+
513
+ UserSig 是用户登录即时通信 IM 的密码,其本质是对 UserID 等信息加密后得到的密文。UserSig 签发方式是将 UserSig 的计算代码集成到您的服务端,并提供面向项目的接口,在需要 UserSig 时由您的项目向业务服务器发起请求获取动态 UserSig。更多详情请参见 [服务端生成 UserSig](https://cloud.tencent.com/document/product/269/32688)。
514
+
515
+ > **注意:**
516
+ >
517
+
518
+ > 本文示例代码采用在 [即时通信 IM 控制台](https://console.cloud.tencent.com/im) 获取 UserSig 的方案,**该方法仅适合本地跑通功能调试**。 正确的 UserSig 签发方式请参见 [服务端生成 UserSig](https://cloud.tencent.com/document/product/269/32688)。
519
+ >
520
+
521
+
522
+ ### 我能不能使用第三方组件库,例如 Element-Plus?
523
+
524
+ 核心组件之间的粘连代码可以使用其他组件库,这一点在示例代码中也可以看到,例如您可以将 `<ChatSetting />` 封装成全屏抽屉组件。但是核心组件内部已经存在的组件暂时不支持修改。
525
+ ``` java
526
+ const isChatSettingShow = ref(false);
527
+
528
+ <el-drawer
529
+ v-model="isChatSettingShow"
530
+ title="设置"
531
+ >
532
+ <ChatSetting />
533
+ </el-drawer>
156
534
  ```
157
535
 
158
- 重点:
159
- 1. 需要在 ChatHeader 组件的 ChatHeaderRight 插槽中添加通话按钮。
160
- 2. 点击通话按钮调用以下方法:
161
- 2.1 阅读 ConversationListState 文档,通过 activeConversation 判断当前是单聊还是群聊。
162
- 2.2 如果是单聊,通过 `import { TUICallKitServer, TUICallType } from '@tencentcloud/call-uikit-vue';` 引入 TUICallKitService 服务。通过 TUICallKitService 的 `calls` 方法发起通话。
163
- ```ts
164
- try {
165
- await TUICallKitServer.calls({
166
- userIDList: [activeConversation.value.userProfile.userID],
167
- type: TUICallType.VIDEO_CALL, // or TUICallType.AUDIO_CALL
168
- });
169
- } catch (error: any) {
170
- console.error(`[TUICallKit] Failed to call the groupCall API. Reason:${error}`);
171
- }
172
- ```
173
- 2.3 如果是群聊,需要阅读 UserPicker 组件文档,建议结合 Dialog 组件,弹出 UserPicker 组件。
174
- 阅读 GroupSettingState 文档,结合 GroupSettingState 的 `getGroupMemberList`、`allMembers` 等属性,获取群成员列表。
175
- ```ts
176
- try {
177
- await TUICallKitServer.calls({
178
- userIDList: selectedItems.map((item: any) => item.key),
179
- type: TUICallType.VIDEO_CALL, // or TUICallType.AUDIO_CALL
180
- });
181
- } catch (error: any) {
182
- console.error(`[TUICallKit] Failed to call the groupCall API. Reason:${error}`);
183
- }
184
- ```
185
-
186
- 建议:结合 UserPicker 的 reachEnd 事件分页拉取群成员,并使用节流函数控制 `getGroupMemberList` 的调用频率。
536
+ ## 参考信息
537
+
538
+ ### 官网文档
539
+ - [自定义组件 - UIKitProvider](https://write.woa.com/document/187032638782849024)
540
+
541
+ - [自定义组件 - Chat](https://write.woa.com/document/187778215983329280)
542
+
543
+ - [自定义组件 - ChatHeader](https://write.woa.com/document/187852524064485376)
544
+
545
+ - [自定义组件 - ConversationList](https://write.woa.com/document/186960319111872512)
546
+
547
+ - [自定义组件 - MessageList](https://write.woa.com/document/187036342928752640)
548
+
549
+ - [自定义组件 - MessageInput](https://write.woa.com/document/187058763983568896)
550
+
551
+ - [自定义组件 - ChatSetting](https://write.woa.com/document/187321409859108864)
552
+
553
+ - [自定义组件 - ContactList](https://write.woa.com/document/187595466274463744)
554
+
555
+ - [自定义组件 - Search](https://write.woa.com/document/187595449195040768)
556
+
557
+
558
+ ### NPM 包
559
+
560
+ [chat-uikit-vue3 npm](https://www.npmjs.com/package/@tencentcloud/chat-uikit-vue3)
561
+
562
+ ### GitHub
563
+
564
+ [GitHub Demo](https://github.com/Tencent-RTC/TUIKit_Vue3/tree/main/demos/rtcube-vite-vue3)
565
+
566
+ ## 联系我们
567
+
568
+ 如遇任何问题,可联系 [官网售后](https://cloud.tencent.com/act/event/connect-service#/) 反馈,享有专业工程师的支持,解决您的难题。