index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <div class="chat-container">
  3. <div class="header">
  4. <div class="toggle-buttons">
  5. <button :class="['toggle-btn', { active: selectedPlatform === 'whatsapp' }]" @click="selectPlatform('whatsapp')">
  6. <img src="@/assets/onlineChat/whatsapp-icon.png" alt="" />
  7. WhatsApp
  8. </button>
  9. <button :class="['toggle-btn', { active: selectedPlatform === 'facebook' }]" @click="selectPlatform('facebook')">
  10. <img src="@/assets/onlineChat/facebook-icon.png" alt="" />
  11. Facebook
  12. </button>
  13. </div>
  14. </div>
  15. <!-- 主体内容区 -->
  16. <div class="main-content">
  17. <!-- 左侧面板 -->
  18. <div class="left-panel">
  19. <!-- 聊天列表 -->
  20. <div class="chat-list">
  21. <div
  22. v-for="chat in filteredChats"
  23. :key="chat.id"
  24. :class="['chat-item', { active: selectedChatId === chat.id }]"
  25. @click="selectChat(chat.id)"
  26. >
  27. <a-avatar :src="chat.avatar" />
  28. <div class="chat-info">
  29. <div class="chat-header">
  30. <span class="name">{{ chat.name }}</span>
  31. <span class="time">{{ chat.lastMessageTime }}</span>
  32. </div>
  33. <div class="last-message">{{ chat.lastMessage }}</div>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. <!-- 右侧对话详情 -->
  39. <div class="chat-detail" v-if="selectedChatId">
  40. <!-- 对话头部信息 -->
  41. <div class="chat-header">
  42. <div class="chat-user-info">
  43. <a-avatar :src="currentChat.avatar" />
  44. <span class="user-name">{{ currentChat.name }}</span>
  45. </div>
  46. </div>
  47. <!-- 聊天记录区域 -->
  48. <div class="chat-messages">
  49. <div v-for="message in currentChatMessages" :key="message.id" :class="['message', message.type]">
  50. <a-avatar :src="message.avatar" />
  51. <div class="message-content">
  52. <div class="message-info">
  53. <span class="sender">{{ message.sender }}</span>
  54. <span class="time">{{ message.time }}</span>
  55. </div>
  56. <div class="message-text">{{ message.content }}</div>
  57. </div>
  58. </div>
  59. </div>
  60. <!-- 回复输入框 -->
  61. <div class="chat-input">
  62. <a-textarea v-model:value="replyMessage" placeholder="请输入消息..." :auto-size="{ minRows: 2, maxRows: 5 }" />
  63. <a-button type="primary" @click="sendMessage">发送</a-button>
  64. </div>
  65. </div>
  66. <!-- 未选择对话时的提示 -->
  67. <div class="no-chat-selected" v-else>
  68. <MessageOutlined style="font-size: 48px" />
  69. <p>快来选择联系人进入会话吧</p>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import { DownOutlined, MessageOutlined, SearchOutlined } from '@ant-design/icons-vue';
  76. export default {
  77. components: {
  78. DownOutlined,
  79. SearchOutlined,
  80. MessageOutlined,
  81. },
  82. data() {
  83. return {
  84. selectedPlatform: 'whatsapp', // 默认选中WhatsApp
  85. showAccountDropdown: false,
  86. currentAccount: {
  87. id: 1,
  88. avatar: '@/assets/onlineChat/whatsapp-icon.png',
  89. name: 'Adweb AI',
  90. },
  91. accounts: [
  92. {
  93. id: 1,
  94. avatar: '@/assets/onlineChat/whatsapp-icon.png',
  95. name: 'Adweb AI',
  96. },
  97. {
  98. id: 2,
  99. avatar: '@/assets/onlineChat/whatsapp-icon.png',
  100. name: 'Adweb AI 2',
  101. },
  102. ],
  103. searchKeyword: '',
  104. currentTab: 'all',
  105. selectedChatId: null,
  106. chats: [
  107. {
  108. id: 1,
  109. name: 'John Doe',
  110. avatar: '/path/to/avatar1.jpg',
  111. lastMessage: 'Hello, how are you?',
  112. lastMessageTime: '10:30',
  113. },
  114. {
  115. id: 2,
  116. name: 'Jane Smith',
  117. avatar: '/path/to/avatar2.jpg',
  118. lastMessage: 'See you tomorrow!',
  119. lastMessageTime: '09:15',
  120. },
  121. ],
  122. messages: {
  123. 1: [
  124. {
  125. id: 1,
  126. type: 'received',
  127. sender: 'John Doe',
  128. avatar: '/path/to/avatar1.jpg',
  129. content: 'Hello, how are you?',
  130. time: '10:30',
  131. },
  132. {
  133. id: 2,
  134. type: 'sent',
  135. sender: 'Me',
  136. avatar: '/path/to/my-avatar.jpg',
  137. content: "I'm good, thanks!",
  138. time: '10:31',
  139. },
  140. ],
  141. 2: [
  142. // messages for chat 2
  143. ],
  144. },
  145. replyMessage: '',
  146. };
  147. },
  148. computed: {
  149. filteredChats() {
  150. return this.chats.filter((chat) => chat.name.toLowerCase().includes(this.searchKeyword.toLowerCase()));
  151. },
  152. currentChatMessages() {
  153. return this.messages[this.selectedChatId] || [];
  154. },
  155. currentChat() {
  156. return this.chats.find((chat) => chat.id === this.selectedChatId) || {};
  157. },
  158. },
  159. methods: {
  160. selectPlatform(platform) {
  161. this.selectedPlatform = platform;
  162. },
  163. selectChat(chatId) {
  164. this.selectedChatId = chatId;
  165. },
  166. switchAccount(account) {
  167. this.currentAccount = account;
  168. this.showAccountDropdown = false;
  169. },
  170. sendMessage() {
  171. if (!this.replyMessage.trim()) return;
  172. const newMessage = {
  173. id: Date.now(),
  174. type: 'sent',
  175. sender: 'Me',
  176. avatar: this.currentAccount.avatar,
  177. content: this.replyMessage,
  178. time: new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }),
  179. };
  180. if (!this.messages[this.selectedChatId]) {
  181. this.messages[this.selectedChatId] = [];
  182. }
  183. this.messages[this.selectedChatId].push(newMessage);
  184. this.replyMessage = '';
  185. },
  186. },
  187. };
  188. </script>
  189. <style scoped>
  190. .chat-container {
  191. padding: 20px;
  192. }
  193. .header {
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. margin-bottom: 20px;
  198. }
  199. .toggle-buttons {
  200. display: flex;
  201. gap: 10px;
  202. }
  203. .toggle-btn {
  204. padding: 8px 16px;
  205. border: 1px solid #dcdfe6;
  206. background-color: #fff;
  207. border-radius: 20px;
  208. cursor: pointer;
  209. transition: all 0.3s;
  210. display: flex;
  211. align-items: center;
  212. gap: 8px;
  213. }
  214. .toggle-btn:hover {
  215. background-color: #f5f7fa;
  216. }
  217. .toggle-btn.active {
  218. background-color: #409eff;
  219. color: #fff;
  220. border-color: #409eff;
  221. }
  222. /* 图标样式 */
  223. .icon-whatsapp,
  224. .icon-whatsapp-business,
  225. .icon-facebook {
  226. display: inline-block;
  227. width: 20px;
  228. height: 20px;
  229. background-size: contain;
  230. background-repeat: no-repeat;
  231. }
  232. .social-management-btn {
  233. padding: 8px 16px;
  234. border: 1px solid #dcdfe6;
  235. background-color: #fff;
  236. border-radius: 20px;
  237. cursor: pointer;
  238. transition: all 0.3s;
  239. display: flex;
  240. align-items: center;
  241. gap: 8px;
  242. }
  243. .social-management-btn:hover {
  244. background-color: #f5f7fa;
  245. }
  246. .main-content {
  247. display: flex;
  248. height: calc(100vh - 220px);
  249. margin-top: 20px;
  250. background: #fff;
  251. border-radius: 4px;
  252. border: 1px solid #e4e7ed;
  253. }
  254. .left-panel {
  255. width: 300px;
  256. border-right: 1px solid #e4e7ed;
  257. display: flex;
  258. flex-direction: column;
  259. }
  260. .current-account {
  261. padding: 16px;
  262. border-bottom: 1px solid #e4e7ed;
  263. display: flex;
  264. align-items: center;
  265. gap: 8px;
  266. cursor: pointer;
  267. position: relative;
  268. }
  269. .current-account .avatar {
  270. width: 32px;
  271. height: 32px;
  272. border-radius: 50%;
  273. }
  274. .chat-list {
  275. flex: 1;
  276. overflow-y: auto;
  277. }
  278. .chat-item {
  279. display: flex;
  280. padding: 12px 16px;
  281. cursor: pointer;
  282. transition: background-color 0.3s;
  283. }
  284. .chat-item:hover {
  285. background-color: #f5f7fa;
  286. }
  287. .chat-item.active {
  288. background-color: #ecf5ff;
  289. }
  290. .chat-info {
  291. margin-left: 12px;
  292. flex: 1;
  293. }
  294. .chat-header {
  295. display: flex;
  296. justify-content: space-between;
  297. margin-bottom: 4px;
  298. }
  299. .chat-header .time {
  300. font-size: 12px;
  301. color: #909399;
  302. }
  303. .last-message {
  304. font-size: 13px;
  305. color: #606266;
  306. overflow: hidden;
  307. text-overflow: ellipsis;
  308. white-space: nowrap;
  309. }
  310. .chat-detail {
  311. flex: 1;
  312. display: flex;
  313. flex-direction: column;
  314. height: 100%;
  315. }
  316. .chat-header {
  317. padding: 16px 20px;
  318. border-bottom: 1px solid #e4e7ed;
  319. }
  320. .chat-user-info {
  321. display: flex;
  322. align-items: center;
  323. gap: 12px;
  324. }
  325. .user-name {
  326. font-size: 16px;
  327. font-weight: 500;
  328. }
  329. .chat-messages {
  330. flex: 1;
  331. padding: 20px;
  332. overflow-y: auto;
  333. }
  334. .chat-input {
  335. padding: 16px 20px;
  336. border-top: 1px solid #e4e7ed;
  337. display: flex;
  338. gap: 12px;
  339. align-items: flex-end;
  340. }
  341. .chat-input .ant-textarea-wrapper {
  342. flex: 1;
  343. }
  344. .chat-input .ant-btn {
  345. height: 40px;
  346. padding: 0 24px;
  347. }
  348. .message {
  349. display: flex;
  350. margin-bottom: 20px;
  351. }
  352. .message.sent {
  353. flex-direction: row-reverse;
  354. }
  355. .message-content {
  356. margin: 0 12px;
  357. max-width: 60%;
  358. }
  359. .message.sent .message-content {
  360. text-align: right;
  361. }
  362. .message-info {
  363. margin-bottom: 4px;
  364. }
  365. .message-text {
  366. padding: 12px;
  367. background: #f5f7fa;
  368. border-radius: 4px;
  369. }
  370. .message.sent .message-text {
  371. background: #409eff;
  372. color: white;
  373. }
  374. .no-chat-selected {
  375. flex: 1;
  376. display: flex;
  377. flex-direction: column;
  378. align-items: center;
  379. justify-content: center;
  380. color: #909399;
  381. }
  382. .no-chat-selected .anticon {
  383. font-size: 48px;
  384. margin-bottom: 16px;
  385. color: #bfbfbf;
  386. }
  387. /* 调整一些样式以匹配 Ant Design 风格 */
  388. .search-box .ant-input-affix-wrapper {
  389. border-radius: 4px;
  390. }
  391. .chat-item .ant-avatar {
  392. width: 40px;
  393. height: 40px;
  394. }
  395. .dropdown-icon {
  396. font-size: 12px;
  397. color: #909399;
  398. transition: transform 0.3s;
  399. }
  400. .dropdown-icon.is-open {
  401. transform: rotate(180deg);
  402. }
  403. .account-dropdown {
  404. position: absolute;
  405. top: 100%;
  406. left: 0;
  407. right: 0;
  408. background: #fff;
  409. border: 1px solid #e4e7ed;
  410. border-radius: 4px;
  411. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  412. z-index: 10;
  413. }
  414. .account-option {
  415. display: flex;
  416. align-items: center;
  417. gap: 8px;
  418. padding: 8px 16px;
  419. cursor: pointer;
  420. }
  421. .account-option:hover {
  422. background-color: #f5f7fa;
  423. }
  424. </style>