NewChatPage.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <a-layout style="height: 100vh;">
  3. <a-layout-sider width="250" style="background: #08002E;">
  4. <a-layout-header style="background: #5A008F; color: white; font-size: 18px; font-weight: bold; text-align: center;">
  5. Chat Application
  6. </a-layout-header>
  7. <a-list :data-source="contacts" :bordered="false">
  8. <a-list-item v-for="contact in contacts" :key="contact.id" @click="selectContact(contact)" :style="{ cursor: 'pointer', padding: '10px' }">
  9. {{ contact.name }}
  10. </a-list-item>
  11. </a-list>
  12. </a-layout-sider>
  13. <a-layout>
  14. <a-layout-content style="background: #f0f0f0; padding: 16px;">
  15. <a-list :data-source="messages" :bordered="false">
  16. <a-list-item v-for="message in messages" :key="message.id" :style="{ textAlign: message.sender === 'user' ? 'right' : 'left' }">
  17. <a-card :style="{ backgroundColor: message.sender === 'user' ? '#5A008F' : '#e0e0e0', color: message.sender === 'user' ? 'white' : 'black', borderRadius: '15px', maxWidth: '70%', margin: '10px' }">
  18. {{ message.text }}
  19. </a-card>
  20. </a-list-item>
  21. </a-list>
  22. </a-layout-content>
  23. <a-layout-footer style="padding: 16px;">
  24. <a-row :gutter="16">
  25. <a-col :span="18">
  26. <a-input v-model:value="inputMessage" placeholder="Type a message...">
  27. <template #suffix>
  28. <a-upload :before-upload="handleUpload">
  29. <template #icon>
  30. <UploadOutlined />
  31. </template>
  32. <a-button shape="circle" style="background: #5A008F; color: white;"></a-button>
  33. </a-upload>
  34. {{ uploadedFileName }}
  35. </template>
  36. </a-input>
  37. </a-col>
  38. <a-col :span="6">
  39. <a-button type="primary" @click="sendMessage" style="background: #5A008F; color: white; font-weight: bold;">Send</a-button>
  40. </a-col>
  41. </a-row>
  42. </a-layout-footer>
  43. </a-layout>
  44. </a-layout>
  45. </template>
  46. <script>
  47. import { UploadOutlined } from '@ant-design/icons-vue';
  48. export default {
  49. components: {
  50. UploadOutlined
  51. },
  52. data() {
  53. return {
  54. contacts: [
  55. { id: 1, name: 'Alice' },
  56. { id: 2, name: 'Bob' },
  57. { id: 3, name: 'Charlie' }
  58. ],
  59. messages: [],
  60. selectedContact: null,
  61. inputMessage: '',
  62. uploadedFileName: ''
  63. };
  64. },
  65. methods: {
  66. selectContact(contact) {
  67. this.selectedContact = contact;
  68. this.messages = [];
  69. },
  70. sendMessage() {
  71. if (this.inputMessage.trim()) {
  72. this.messages.push({ id: Date.now(), sender: 'user', text: this.inputMessage });
  73. this.inputMessage = '';
  74. }
  75. },
  76. handleUpload(file) {
  77. this.uploadedFileName = file.name;
  78. return false; // Prevent file upload
  79. }
  80. }
  81. };
  82. </script>
  83. <style scoped>
  84. .ant-layout-sider {
  85. height: 100%;
  86. }
  87. .ant-layout-content {
  88. height: calc(100% - 64px); /* Subtract header and footer height */
  89. overflow-y: auto;
  90. }
  91. .ant-list-item {
  92. cursor: pointer;
  93. }
  94. .ant-card {
  95. word-wrap: break-word;
  96. }
  97. </style>