chat-aggregate.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>龙虾引擎 - 聚合聊天</title>
  7. <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
  8. <style>
  9. *{margin:0;padding:0;box-sizing:border-box}
  10. body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;background:#0a0a1a;color:#e0e0e0;height:100vh;overflow:hidden}
  11. .main{display:flex;height:100vh}
  12. /* 左侧账户列表 */
  13. .account-panel{width:80px;background:#0d0d1f;border-right:1px solid #1a1a3e;display:flex;flex-direction:column;padding:12px 0}
  14. .account-item{width:56px;height:56px;border-radius:50%;margin:0 auto 8px;cursor:pointer;position:relative;border:2px solid transparent;transition:.2s;display:flex;align-items:center;justify-content:center;font-size:24px}
  15. .account-item:hover{border-color:#e94560;transform:scale(1.05)}
  16. .account-item.active{border-color:#e94560;background:#e9456022}
  17. .account-item .badge{position:absolute;top:-2px;right:-2px;background:#e94560;color:#fff;border-radius:10px;padding:1px 5px;font-size:10px}
  18. .account-item.disabled{opacity:.4;cursor:not-allowed}
  19. /* 会话列表 */
  20. .session-panel{width:280px;background:#1a1a2e;border-right:1px solid #2a2a4a;display:flex;flex-direction:column}
  21. .session-header{padding:12px 16px;border-bottom:1px solid #2a2a4a}
  22. .session-header h3{font-size:14px;color:#e94560}
  23. .session-header .search{margin-top:8px}
  24. .session-header input{width:100%;padding:6px 10px;background:#0a0a1a;border:1px solid #2a2a4a;border-radius:4px;color:#e0e0e0;font-size:12px}
  25. .session-list{flex:1;overflow-y:auto;padding:8px}
  26. .session-item{display:flex;padding:10px;cursor:pointer;border-radius:6px;margin-bottom:4px;transition:.2s}
  27. .session-item:hover{background:#2a2a4a}
  28. .session-item.active{background:#0f3460}
  29. .session-avatar{width:40px;height:40px;border-radius:50%;background:linear-gradient(135deg,#e94560,#f59e0b);display:flex;align-items:center;justify-content:center;font-size:16px;flex-shrink:0}
  30. .session-info{flex:1;min-width:0;margin-left:10px}
  31. .session-info .name{font-size:13px;color:#e0e0e0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
  32. .session-info .msg{font-size:12px;color:#888;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:2px}
  33. .session-time{font-size:11px;color:#666;text-align:right}
  34. .session-item.unread .name{font-weight:600;color:#fff}
  35. .session-item.unread .badge{background:#e94560;color:#fff;border-radius:10px;padding:1px 5px;font-size:10px}
  36. /* 聊天区域 */
  37. .chat-panel{flex:1;display:flex;flex-direction:column;background:#0a0a1a}
  38. .chat-header{padding:12px 20px;background:#1a1a2e;border-bottom:1px solid #2a2a4a;display:flex;align-items:center;justify-content:space-between}
  39. .chat-title .name{font-size:15px;color:#e0e0e0}
  40. .chat-title .type{font-size:11px;color:#888;margin-left:8px}
  41. .chat-actions{display:flex;gap:8px}
  42. .chat-actions button{padding:6px 12px;background:#0f3460;border:none;border-radius:4px;color:#e0e0e0;font-size:12px;cursor:pointer}
  43. .chat-actions button:hover{background:#1a4a80}
  44. /* 消息列表 */
  45. .message-list{flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column}
  46. .message-item{display:flex;margin-bottom:12px;max-width:80%}
  47. .message-item.sent{align-self:flex-end}
  48. .message-item.sent .msg-bubble{background:#e94560;color:#fff;border-radius:12px 12px 0 12px}
  49. .message-item.received{align-self:flex-start}
  50. .message-item.received .msg-bubble{background:#1a1a2e;color:#e0e0e0;border-radius:12px 12px 12px 0;border:1px solid #2a2a4a}
  51. .msg-avatar{width:32px;height:32px;border-radius:50%;background:linear-gradient(135deg,#3b82f6,#22c55e);display:flex;align-items:center;justify-content:center;font-size:12px;flex-shrink:0}
  52. .message-item.sent .msg-avatar{order:2;margin-left:8px}
  53. .message-item.received .msg-avatar{order:1;margin-right:8px}
  54. .msg-content{display:flex;flex-direction:column}
  55. .message-item.sent .msg-content{order:1}
  56. .message-item.received .msg-content{order:2}
  57. .msg-bubble{padding:10px 14px;max-width:max-content}
  58. .msg-text{font-size:13px;line-height:1.5}
  59. .msg-time{font-size:10px;color:#666;margin-top:4px;text-align:right}
  60. .message-item.sent .msg-time{color:#fff8}
  61. /* 输入区域 */
  62. .chat-input{padding:12px 20px;background:#1a1a2e;border-top:1px solid #2a2a4a}
  63. .input-row{display:flex;gap:10px}
  64. .input-row textarea{flex:1;padding:10px 14px;background:#0a0a1a;border:1px solid #2a2a4a;border-radius:8px;color:#e0e0e0;font-size:13px;resize:none;min-height:44px;max-height:120px;font-family:inherit}
  65. .input-row textarea:focus{outline:none;border-color:#e94560}
  66. .input-row button{padding:10px 24px;background:#e94560;color:#fff;border:none;border-radius:8px;cursor:pointer;font-size:13px;font-weight:500;flex-shrink:0}
  67. .input-row button:hover{background:#d63850}
  68. .input-row button:disabled{opacity:.5;cursor:not-allowed}
  69. /* 客户信息面板 */
  70. .customer-panel{width:280px;background:#1a1a2e;border-left:1px solid #2a2a4a;display:flex;flex-direction:column}
  71. .customer-header{padding:16px;border-bottom:1px solid #2a2a4a;text-align:center}
  72. .customer-avatar{width:64px;height:64px;border-radius:50%;background:linear-gradient(135deg,#e94560,#f59e0b);display:flex;align-items:center;justify-content:center;font-size:24px;margin:0 auto}
  73. .customer-name{font-size:15px;color:#e0e0e0;margin-top:8px}
  74. .customer-id{font-size:11px;color:#666}
  75. .customer-tabs{display:flex;border-bottom:1px solid #2a2a4a}
  76. .customer-tabs .tab{flex:1;padding:8px;text-align:center;font-size:12px;color:#888;cursor:pointer;border-bottom:2px solid transparent}
  77. .customer-tabs .tab.active{border-color:#e94560;color:#e94560}
  78. .customer-detail{flex:1;overflow-y:auto;padding:12px}
  79. .detail-section{margin-bottom:16px}
  80. .detail-section h4{font-size:12px;color:#888;margin-bottom:8px}
  81. .detail-row{display:flex;justify-content:space-between;padding:4px 0;font-size:12px}
  82. .detail-row .label{color:#888}
  83. .detail-row .value{color:#e0e0e0}
  84. .tag-list{display:flex;flex-wrap:gap;gap:4px}
  85. .tag{display:inline-block;padding:3px 8px;background:#0f3460;color:#ccc;border-radius:4px;font-size:11px}
  86. .record-item{padding:8px;border-bottom:1px solid #1a1a3e}
  87. .record-item .time{font-size:11px;color:#666}
  88. .record-item .desc{font-size:12px;color:#e0e0e0;margin-top:2px}
  89. /* 渠道图标 */
  90. .channel-qw{background:linear-gradient(135deg,#1890ff,#096dd9)}
  91. .channel-wx{background:linear-gradient(135deg,#07c160,#10b981)}
  92. .channel-im{background:linear-gradient(135deg,#6366f1,#8b5cf6)}
  93. .channel-whatsapp{background:linear-gradient(135deg,#25d366,#10b981)}
  94. .channel-other{background:linear-gradient(135deg,#6b7280,#9ca3af)}
  95. /* 滚动条 */
  96. ::-webkit-scrollbar{width:6px}
  97. ::-webkit-scrollbar-track{background:#0a0a1a}
  98. ::-webkit-scrollbar-thumb{background:#2a2a4a;border-radius:3px}
  99. ::-webkit-scrollbar-thumb:hover{background:#3a3a5a}
  100. </style>
  101. </head>
  102. <body>
  103. <div id="app" class="main">
  104. <!-- 左侧账户列表 -->
  105. <div class="account-panel">
  106. <div v-for="acc in accounts" :key="acc.id"
  107. :class="['account-item', acc.active ? 'active' : '', acc.connected ? '' : 'disabled']"
  108. @click="selectAccount(acc)" :title="acc.name">
  109. <span>{{acc.icon}}</span>
  110. <span v-if="acc.unread>0" class="badge">{{acc.unread}}</span>
  111. </div>
  112. </div>
  113. <!-- 会话列表 -->
  114. <div class="session-panel">
  115. <div class="session-header">
  116. <h3>🗨️ 聊天列表</h3>
  117. <div class="search">
  118. <input v-model="searchKey" placeholder="搜索联系人..." @keyup="filterSessions">
  119. </div>
  120. </div>
  121. <div class="session-list">
  122. <div v-for="sess in filteredSessions" :key="sess.sessionId"
  123. :class="['session-item', sess.sessionId === currentSession?.sessionId ? 'active' : '', sess.unread > 0 ? 'unread' : '']"
  124. @click="selectSession(sess)">
  125. <div class="session-avatar">{{sess.avatar||'?'}}</div>
  126. <div class="session-info">
  127. <div class="name">{{sess.name}}</div>
  128. <div class="msg">{{sess.lastMsg||'暂无消息'}}</div>
  129. </div>
  130. <div style="text-align:right;margin-left:8px">
  131. <div class="session-time">{{sess.lastTime||''}}</div>
  132. <span v-if="sess.unread>0" class="badge">{{sess.unread}}</span>
  133. </div>
  134. </div>
  135. <div v-if="filteredSessions.length===0" style="text-align:center;padding:40px;color:#666;font-size:13px">
  136. 暂无会话记录
  137. </div>
  138. </div>
  139. </div>
  140. <!-- 聊天区域 -->
  141. <div class="chat-panel">
  142. <div v-if="currentSession" class="chat-header">
  143. <div class="chat-title">
  144. <span class="name">{{currentSession.name}}</span>
  145. <span class="type">{{channelName(currentSession.channelType)}}</span>
  146. </div>
  147. <div class="chat-actions">
  148. <button @click="toggleControlMode">{{currentSession.controlMode === 'ai' ? '🤖 AI接管中' : '👤 人工接管'}}</button>
  149. <button @click="showCustomerInfo=true">👤 客户信息</button>
  150. </div>
  151. </div>
  152. <div v-else class="chat-header">
  153. <div class="chat-title">
  154. <span class="name">请选择一个会话</span>
  155. </div>
  156. </div>
  157. <div class="message-list" ref="messageList">
  158. <div v-for="(msg, idx) in messages" :key="idx" :class="['message-item', msg.sendType === 1 ? 'received' : 'sent']">
  159. <div class="msg-avatar">{{msg.sendType === 1 ? '👤' : '🤖'}}</div>
  160. <div class="msg-content">
  161. <div class="msg-bubble">
  162. <div class="msg-text">{{msg.content}}</div>
  163. </div>
  164. <div class="msg-time">{{msg.time}}</div>
  165. </div>
  166. </div>
  167. <div v-if="messages.length===0" style="text-align:center;padding:60px;color:#666">
  168. <div style="font-size:48px;margin-bottom:12px">💬</div>
  169. <p>开始与客户聊天</p>
  170. </div>
  171. </div>
  172. <div class="chat-input">
  173. <div class="input-row">
  174. <textarea v-model="inputMsg" placeholder="输入消息..." @keyup.enter="sendMessage"></textarea>
  175. <button @click="sendMessage" :disabled="!inputMsg.trim()">发送</button>
  176. </div>
  177. </div>
  178. </div>
  179. <!-- 客户信息面板 -->
  180. <div class="customer-panel" v-if="showCustomerInfo">
  181. <div class="customer-header">
  182. <div class="customer-avatar">{{currentSession?.avatar||'?'}}</div>
  183. <div class="customer-name">{{currentSession?.name||'-'}}</div>
  184. <div class="customer-id">{{currentSession?.channelSourceId||'-'}}</div>
  185. </div>
  186. <div class="customer-tabs">
  187. <div :class="['tab', customerTab==='basic'?'active':'']" @click="customerTab='basic'">基本信息</div>
  188. <div :class="['tab', customerTab==='tags'?'active':'']" @click="customerTab='tags'">标签</div>
  189. <div :class="['tab', customerTab==='records'?'active':'']" @click="customerTab='records'">访问记录</div>
  190. </div>
  191. <div class="customer-detail">
  192. <div v-if="customerTab==='basic'" class="detail-section">
  193. <h4>📋 基本信息</h4>
  194. <div class="detail-row"><span class="label">渠道</span><span class="value">{{channelName(currentSession?.channelType)}}</span></div>
  195. <div class="detail-row"><span class="label">来源ID</span><span class="value">{{currentSession?.channelSourceId||'-'}}</span></div>
  196. <div class="detail-row"><span class="label">联系人ID</span><span class="value">{{currentSession?.contactId||'-'}}</span></div>
  197. <div class="detail-row"><span class="label">会话ID</span><span class="value">{{currentSession?.sessionId||'-'}}</span></div>
  198. <div class="detail-row"><span class="label">创建时间</span><span class="value">{{currentSession?.createTime||'-'}}</span></div>
  199. </div>
  200. <div v-if="customerTab==='tags'" class="detail-section">
  201. <h4>🏷️ 客户标签</h4>
  202. <div class="tag-list">
  203. <span v-for="tag in customerTags" :key="tag" class="tag">{{tag}}</span>
  204. </div>
  205. <div v-if="customerTags.length===0" style="color:#666;font-size:12px">暂无标签</div>
  206. </div>
  207. <div v-if="customerTab==='records'" class="detail-section">
  208. <h4>📊 访问记录</h4>
  209. <div v-for="record in visitRecords" :key="record.time" class="record-item">
  210. <div class="time">{{record.time}}</div>
  211. <div class="desc">{{record.desc}}</div>
  212. </div>
  213. <div v-if="visitRecords.length===0" style="color:#666;font-size:12px">暂无访问记录</div>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. <script>
  219. const {createApp, ref, computed, watch, nextTick, onMounted} = Vue;
  220. createApp({
  221. setup(){
  222. const searchKey = ref('');
  223. const inputMsg = ref('');
  224. const showCustomerInfo = ref(true);
  225. const customerTab = ref('basic');
  226. const messageList = ref(null);
  227. const loading = ref(false);
  228. // API请求工具函数
  229. const request = async (url, options = {}) => {
  230. const defaultOptions = {
  231. headers: {
  232. 'Content-Type': 'application/json',
  233. },
  234. };
  235. const response = await fetch(url, { ...defaultOptions, ...options });
  236. if (!response.ok) {
  237. throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  238. }
  239. return await response.json();
  240. };
  241. // 账户列表
  242. const accounts = ref([]);
  243. // 会话列表
  244. const sessions = ref([]);
  245. // 当前会话
  246. const currentSession = ref(null);
  247. // 消息列表
  248. const messages = ref([]);
  249. // 客户标签
  250. const customerTags = ref([]);
  251. // 访问记录
  252. const visitRecords = ref([]);
  253. // 当前登录用户的企微账户
  254. const currentAccount = ref(null);
  255. // 过滤后的会话
  256. const filteredSessions = computed(()=>{
  257. if(!searchKey.value) return sessions.value;
  258. const key = searchKey.value.toLowerCase();
  259. return sessions.value.filter(s=>{
  260. const name = s.nickName || s.name || '';
  261. return name.toLowerCase().includes(key);
  262. });
  263. });
  264. // 加载账户列表
  265. const loadAccounts = async () => {
  266. try {
  267. // 先获取当前登录用户绑定的企微账户
  268. const res = await request('/qw/user/getMyQwUserList');
  269. if (res.code === 200 || res.code === 0) {
  270. const qwAccounts = (res.data || []).map((acc, idx) => ({
  271. id: acc.id || `qw_${idx}`,
  272. name: acc.qwUserName || '企微账户',
  273. icon: '💼',
  274. active: idx === 0,
  275. connected: true,
  276. unread: 0,
  277. type: 'QW',
  278. corpId: acc.corpId,
  279. qwUserId: acc.qwUserId
  280. }));
  281. // 添加个微账户占位(后续扩展)
  282. const wxAccounts = []; // 暂时为空,后续实现个微账户绑定
  283. accounts.value = [...qwAccounts, ...wxAccounts];
  284. if (accounts.value.length > 0) {
  285. currentAccount.value = accounts.value[0];
  286. }
  287. }
  288. } catch (error) {
  289. console.error('加载账户失败:', error);
  290. // 降级显示模拟账户
  291. accounts.value = [
  292. {id:'qw', name:'企业微信', icon:'💼', active:true, connected:true, unread:0, type:'QW'},
  293. {id:'wx', name:'个人微信', icon:'💬', active:false, connected:false, unread:0, type:'WX'},
  294. ];
  295. currentAccount.value = accounts.value[0];
  296. }
  297. };
  298. // 加载会话列表
  299. const loadSessions = async () => {
  300. try {
  301. // 先尝试加载chat会话
  302. const chatRes = await request('/chat/chatSession/list?pageNum=1&pageSize=100');
  303. if (chatRes.code === 200 || chatRes.rows) {
  304. const chatSessions = (chatRes.rows || []).map(s => ({
  305. sessionId: s.sessionId,
  306. name: s.nickName || s.userName || '客户',
  307. avatar: (s.nickName || s.userName || '客').charAt(0),
  308. channelType: 'CHAT',
  309. channelSourceId: s.userId,
  310. contactId: s.userId,
  311. lastMsg: '',
  312. lastTime: s.createTime || '',
  313. unread: 0,
  314. createTime: s.createTime,
  315. status: s.status
  316. }));
  317. // 再尝试加载企微外部联系人作为会话
  318. const qwRes = await request('/qw/externalContact/list?pageNum=1&pageSize=100');
  319. if (qwRes.code === 200 || qwRes.rows) {
  320. const qwSessions = (qwRes.rows || []).map(c => ({
  321. sessionId: `qw_${c.id}`,
  322. name: c.name || c.remark || '企微客户',
  323. avatar: (c.name || c.remark || '客').charAt(0),
  324. channelType: 'QW',
  325. channelSourceId: c.externalUserId,
  326. contactId: c.id,
  327. lastMsg: '',
  328. lastTime: c.createTime || '',
  329. unread: 0,
  330. createTime: c.createTime,
  331. tagIds: c.tagIds,
  332. customerId: c.customerId,
  333. remarkMobiles: c.remarkMobiles
  334. }));
  335. sessions.value = [...qwSessions, ...chatSessions];
  336. } else {
  337. sessions.value = chatSessions;
  338. }
  339. }
  340. } catch (error) {
  341. console.error('加载会话失败:', error);
  342. sessions.value = [];
  343. }
  344. if (sessions.value.length > 0 && !currentSession.value) {
  345. selectSession(sessions.value[0]);
  346. }
  347. };
  348. // 选择账户
  349. const selectAccount = (acc)=>{
  350. if(!acc.connected) return;
  351. accounts.value.forEach(a=>a.active = false);
  352. acc.active = true;
  353. currentAccount.value = acc;
  354. loadSessions();
  355. };
  356. // 选择会话
  357. const selectSession = async (sess)=>{
  358. currentSession.value = sess;
  359. // 清除未读
  360. sess.unread = 0;
  361. // 加载消息
  362. await loadMessages(sess);
  363. // 加载客户标签和信息
  364. await loadCustomerInfo(sess);
  365. };
  366. // 加载消息
  367. const loadMessages = async (session) => {
  368. messages.value = [];
  369. try {
  370. if (session.channelType === 'CHAT') {
  371. // 加载chat会话消息
  372. const chatDetailRes = await request(`/chat/chatSession/${session.sessionId}`);
  373. if (chatDetailRes.code === 200 || chatDetailRes.data) {
  374. const msgRes = await request(`/chat/chatMsg/list?sessionId=${session.sessionId}&pageNum=1&pageSize=100`);
  375. if (msgRes.rows) {
  376. messages.value = msgRes.rows.map(m => ({
  377. content: m.content,
  378. sendType: m.sendType,
  379. time: m.createTime || new Date().toLocaleTimeString('zh-CN',{hour:'2-digit',minute:'2-digit'})
  380. }));
  381. }
  382. }
  383. } else if (session.channelType === 'QW') {
  384. // TODO: 加载企微聊天记录
  385. messages.value = [];
  386. }
  387. } catch (error) {
  388. console.error('加载消息失败:', error);
  389. messages.value = [];
  390. }
  391. nextTick(()=>{
  392. if(messageList.value){
  393. messageList.value.scrollTop = messageList.value.scrollHeight;
  394. }
  395. });
  396. };
  397. // 加载客户信息
  398. const loadCustomerInfo = async (session) => {
  399. customerTags.value = [];
  400. visitRecords.value = [];
  401. try {
  402. if (session.tagIds && session.tagIds !== '[]') {
  403. // 解析标签ID并加载标签名称
  404. const tagIds = JSON.parse(session.tagIds);
  405. if (tagIds.length > 0) {
  406. const tagRes = await request(`/qw/tag/list?tagIds=${tagIds.join(',')}`);
  407. if (tagRes.rows) {
  408. customerTags.value = tagRes.rows.map(t => t.tagName || t.name);
  409. }
  410. }
  411. }
  412. // 加载CRM客户信息
  413. if (session.customerId) {
  414. const crmRes = await request(`/crm/customer/${session.customerId}`);
  415. if (crmRes.data) {
  416. // 补充客户基本信息
  417. if (crmRes.data.phone) {
  418. visitRecords.value.push({
  419. time: new Date().toLocaleDateString('zh-CN'),
  420. desc: `手机号: ${crmRes.data.phone}`
  421. });
  422. }
  423. if (crmRes.data.email) {
  424. visitRecords.value.push({
  425. time: new Date().toLocaleDateString('zh-CN'),
  426. desc: `邮箱: ${crmRes.data.email}`
  427. });
  428. }
  429. }
  430. }
  431. // 加载fastGpt聊天摘要
  432. try {
  433. const chatRes = await request('/fastGpt/fastGptChatSession/list?pageNum=1&pageSize=10');
  434. if (chatRes.rows) {
  435. const relatedChat = chatRes.rows.find(c =>
  436. c.externalUserId === session.channelSourceId ||
  437. c.userId === session.contactId
  438. );
  439. if (relatedChat) {
  440. visitRecords.value.push({
  441. time: relatedChat.createTime || new Date().toLocaleDateString('zh-CN'),
  442. desc: `最近聊天: ${relatedChat.lastMsg || '暂无消息'}`
  443. });
  444. }
  445. }
  446. } catch (err) {
  447. console.error('加载聊天摘要失败:', err);
  448. }
  449. } catch (error) {
  450. console.error('加载客户信息失败:', error);
  451. }
  452. };
  453. // 发送消息
  454. const sendMessage = async ()=>{
  455. if(!inputMsg.value.trim() || !currentSession.value) return;
  456. const msg = {
  457. content: inputMsg.value,
  458. sendType: 2,
  459. time: new Date().toLocaleTimeString('zh-CN',{hour:'2-digit',minute:'2-digit'})
  460. };
  461. messages.value.push(msg);
  462. const contentToSend = inputMsg.value;
  463. inputMsg.value = '';
  464. nextTick(()=>{
  465. if(messageList.value){
  466. messageList.value.scrollTop = messageList.value.scrollHeight;
  467. }
  468. });
  469. // 调用发送消息接口
  470. try {
  471. if (currentSession.value.channelType === 'QW') {
  472. // 企微发送消息
  473. await request('/qw/msg/send', {
  474. method: 'POST',
  475. body: JSON.stringify({
  476. externalUserId: currentSession.value.channelSourceId,
  477. content: contentToSend,
  478. qwUserId: currentAccount.value?.qwUserId
  479. })
  480. });
  481. } else if (currentSession.value.channelType === 'CHAT') {
  482. // Chat会话发送消息
  483. await request('/chat/chatMsg', {
  484. method: 'POST',
  485. body: JSON.stringify({
  486. sessionId: currentSession.value.sessionId,
  487. content: contentToSend,
  488. sendType: 2
  489. })
  490. });
  491. }
  492. } catch (error) {
  493. console.error('发送消息失败:', error);
  494. }
  495. };
  496. // 切换控制模式
  497. const toggleControlMode = ()=>{
  498. if(currentSession.value){
  499. currentSession.value.controlMode = currentSession.value.controlMode === 'ai' ? 'human' : 'ai';
  500. }
  501. };
  502. // 渠道名称
  503. const channelName = (type)=>{
  504. const names = {QW:'企业微信', WX:'个人微信', IM:'系统IM', WHATSAPP:'WhatsApp', OTHER:'其他渠道', CHAT:'在线咨询'};
  505. return names[type] || type;
  506. };
  507. // 初始化
  508. onMounted(async () => {
  509. await loadAccounts();
  510. await loadSessions();
  511. });
  512. return {
  513. searchKey, inputMsg, showCustomerInfo, customerTab, messageList, loading,
  514. accounts, sessions, currentSession, messages, customerTags, visitRecords,
  515. filteredSessions,
  516. selectAccount, selectSession, sendMessage, toggleControlMode, channelName
  517. };
  518. }
  519. }).mount('#app');
  520. </script>
  521. </body>
  522. </html>