Guest User

Untitled

a guest
Dec 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. <template>
  2. <div style="background-color: #f5f5f5; height: 100vh; overflow: auto">
  3. <div
  4. class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm"
  5. >
  6. <h5 class="my-0 mr-md-auto font-weight-normal "><b>Network App - Messenger</b></h5>
  7. <nav class="my-2 my-md-0 mr-md-3">
  8. <a-button
  9. type="danger"
  10. size="large"
  11. style="margin:0px 5px 0px 0px"
  12. @click="toAuthorization"
  13. >Log out
  14. <a-icon type="poweroff" />
  15. </a-button>
  16. <a-button size="large" type="primary" @click="showDrawer">
  17. Online
  18. <a-icon type="team" />
  19. </a-button>
  20. <a-drawer
  21. title="These users are online now:"
  22. placement="right"
  23. :closable="false"
  24. @close="closeDrawer"
  25. :visible="drawerVisible"
  26. >
  27. <p v-for="user in usersList" :key="user">
  28. <a-icon type="check-circle" theme="twoTone" v-if="user" />
  29. {{ user }}
  30. </p>
  31. </a-drawer>
  32. </nav>
  33. </div>
  34.  
  35. <div class="container">
  36. <div class="py-5 "></div>
  37. <div class="row">
  38. <div class="col-6" style="margin: 0px 100px 0px -100px" >
  39. <h3 class="text-center"><b>You</b></h3>
  40.  
  41. <p class="d-block mb-2" style="font-size: 18px">
  42. <span style=" text-decoration: underline">Nickname:</span>
  43. <b>{{ this.$route.params.name }} </b>
  44. </p>
  45. <label
  46. for="message"
  47. style="font-size: 18px; text-decoration: underline"
  48. >
  49. Your message:
  50. </label>
  51. <textarea
  52. name="message"
  53. v-model="message"
  54. class="form-control"
  55. placeholder="Enter your message"
  56. @keydown.enter.exact.prevent
  57. @keyup.enter.exact="send"
  58. @keydown.enter.shift.exact="newline"
  59. ></textarea>
  60. <br />
  61. <button @click="send" class="btn btn-danger">Send</button>
  62. </div>
  63. <div class="col-6">
  64. <h3 class="text-center"><b>All messages</b></h3>
  65. <div
  66.  
  67. style="font-size:20px"
  68. v-for="message in messages"
  69. v-bind:key="message.id"
  70. >
  71. <p
  72.  
  73. class="alert alert-primary"
  74. style="border-radius:20px"
  75. role="alert"
  76. >
  77.  
  78. <b>{{ message.user }}</b>
  79. : {{ message.newMess }}
  80. </p>
  81. </div>
  82.  
  83. </div>
  84. </div>
  85. <br />
  86. <br />
  87. <br />
  88. <br />
  89. <br />
  90. <br />
  91. </div>
  92.  
  93.  
  94. </div>
  95. </template>
  96.  
  97. <script>
  98. import VueCryptojs from 'vue-cryptojs'
  99. import io from "socket.io-client";
  100. import { Drawer, Button, Icon } from "ant-design-vue";
  101.  
  102. export default {
  103. components: {
  104. Drawer,
  105. Button,
  106. Icon
  107. },
  108.  
  109. data() {
  110. return {
  111. readyConnect: false,
  112. readyDisconnect: false,
  113. usersList: [],
  114. messages: [],
  115. name: "",
  116. message: "",
  117. connect: "",
  118. disconnect:"",
  119. drawerVisible: false,
  120. connectionList: [],
  121.  
  122. };
  123. },
  124.  
  125. created() {
  126. this.client = io.connect("http://"+ this.$route.params.address + ":" + this.$route.params.port + "/")
  127. this.client.emit("join", this.$route.params.name);
  128. this.client.emit('add', this.$route.params.name);
  129. this.client.on("add mess", data => {
  130.  
  131. this.messages.push({
  132. user: data.name ,
  133. newMess: this.CryptoJS.AES.decrypt(data.mess,'secretMess').toString(this.CryptoJS.enc.Utf8)
  134. });
  135. }),
  136. this.client.on("online", data => {
  137. this.usersList = data;
  138. })
  139.  
  140. },
  141.  
  142. methods: {
  143. send: function() {
  144. if (this.message.length ) {
  145.  
  146.  
  147. this.client.emit("send mess", {
  148. mess: this.CryptoJS.AES.encrypt(this.message, 'secretMess').toString(),
  149. name: this.$route.params.name,
  150. });
  151. }
  152.  
  153. this.message = "";
  154. },
  155. toAuthorization: function() {
  156. this.$router.push({ path: "/" });
  157. this.client.close()
  158. },
  159.  
  160. showDrawer: function() {
  161. this.drawerVisible = true;
  162. },
  163.  
  164. closeDrawer: function() {
  165. this.drawerVisible = false;
  166. },
  167.  
  168. showUser: function(userName) {}
  169. },
  170. mounted() {}
  171. };
  172. </script>
  173.  
  174. <style></style>
Advertisement
Add Comment
Please, Sign In to add comment