|
@@ -0,0 +1,140 @@
|
|
|
|
+<template>
|
|
|
|
+ <div class="app-container">
|
|
|
|
+ <aside class="sidebar">
|
|
|
|
+ <header>
|
|
|
|
+ <h1>Contact List</h1>
|
|
|
|
+ </header>
|
|
|
|
+ <ul>
|
|
|
|
+ <li v-for="contact in contacts" :key="contact.id" @click="selectContact(contact)">
|
|
|
|
+ {{ contact.name }}
|
|
|
|
+ </li>
|
|
|
|
+ </ul>
|
|
|
|
+ </aside>
|
|
|
|
+ <main class="chat-area">
|
|
|
|
+ <div v-for="message in messages" :key="message.id" :class="['message', {'sent': message.sender === 'me', 'received': message.sender !== 'me'}]">
|
|
|
|
+ <p>{{ message.content }}</p>
|
|
|
|
+ </div>
|
|
|
|
+ <footer>
|
|
|
|
+ <form @submit.prevent="sendMessage">
|
|
|
|
+ <input type="text" v-model="newMessage" placeholder="Type a message...">
|
|
|
|
+ <button type="submit">Send</button>
|
|
|
|
+ <label for="file-upload" class="file-label">
|
|
|
|
+ <i class="anticon anticon-upload"></i>
|
|
|
|
+ </label>
|
|
|
|
+ <input id="file-upload" type="file" @change="handleFileUpload">
|
|
|
|
+ </form>
|
|
|
|
+ </footer>
|
|
|
|
+ </main>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import { defineComponent } from 'vue';
|
|
|
|
+import { Button, Input, Upload } from 'ant-design-vue';
|
|
|
|
+
|
|
|
|
+export default defineComponent({
|
|
|
|
+ components: {
|
|
|
|
+ 'a-button': Button,
|
|
|
|
+ 'a-input': Input,
|
|
|
|
+ 'a-upload': Upload,
|
|
|
|
+ },
|
|
|
|
+ data() {
|
|
|
|
+ return {
|
|
|
|
+ contacts: [
|
|
|
|
+ { id: 1, name: 'Alice' },
|
|
|
|
+ { id: 2, name: 'Bob' },
|
|
|
|
+ ],
|
|
|
|
+ selectedContact: null,
|
|
|
|
+ messages: [],
|
|
|
|
+ newMessage: '',
|
|
|
|
+ file: null,
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ selectContact(contact) {
|
|
|
|
+ this.selectedContact = contact;
|
|
|
|
+ },
|
|
|
|
+ sendMessage() {
|
|
|
|
+ if (this.newMessage.trim()) {
|
|
|
|
+ this.messages.push({ id: this.messages.length + 1, sender: 'me', content: this.newMessage });
|
|
|
|
+ this.newMessage = '';
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ handleFileUpload(event) {
|
|
|
|
+ this.file = event.target.files[0];
|
|
|
|
+ if (this.file) {
|
|
|
|
+ const reader = new FileReader();
|
|
|
|
+ reader.onload = (e) => {
|
|
|
|
+ this.messages.push({ id: this.messages.length + 1, sender: 'me', content: `File: ${e.target.result.split(',')[1]}` });
|
|
|
|
+ };
|
|
|
|
+ reader.readAsDataURL(this.file);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+});
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style scoped>
|
|
|
|
+.app-container {
|
|
|
|
+ display: flex;
|
|
|
|
+ height: 100vh;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.sidebar {
|
|
|
|
+ width: 250px;
|
|
|
|
+ background-color: #08002E;
|
|
|
|
+ color: white;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.chat-area {
|
|
|
|
+ flex-grow: 1;
|
|
|
|
+ background-color: #f0f0f0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.message {
|
|
|
|
+ padding: 10px;
|
|
|
|
+ margin: 5px 0;
|
|
|
|
+ border-radius: 10px;
|
|
|
|
+ word-wrap: break-word;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.sent {
|
|
|
|
+ align-self: flex-end;
|
|
|
|
+ background-color: #9b59b6;
|
|
|
|
+ color: white;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.received {
|
|
|
|
+ align-self: flex-start;
|
|
|
|
+ background-color: #ecf0f1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+footer form {
|
|
|
|
+ display: flex;
|
|
|
|
+ justify-content: space-between;
|
|
|
|
+ align-items: center;
|
|
|
|
+ padding: 10px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+footer input {
|
|
|
|
+ flex-grow: 1;
|
|
|
|
+ border-radius: 10px;
|
|
|
|
+ padding: 10px;
|
|
|
|
+ margin-right: 10px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+footer button {
|
|
|
|
+ background-color: #9b59b6;
|
|
|
|
+ color: white;
|
|
|
|
+ border: none;
|
|
|
|
+ border-radius: 10px;
|
|
|
|
+ padding: 10px 20px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.file-label {
|
|
|
|
+ background-color: #9b59b6;
|
|
|
|
+ border-radius: 50%;
|
|
|
|
+ padding: 10px;
|
|
|
|
+ cursor: pointer;
|
|
|
|
+}
|
|
|
|
+</style>
|