chat.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div id="chat">
  3. <el-row>
  4. <el-col :span="24" class="chat">
  5. <el-col :span="24" class="top">
  6. <el-col :span="24" v-for="(i, index) in chatList" :key="index">
  7. <span v-if="isSender(i, index)">
  8. <el-col :span="24" class="sender">
  9. <p>[{{ i.send_time }}]{{ i.sender_name }}</p>
  10. <p>{{ i.content }}</p>
  11. </el-col>
  12. </span>
  13. <span v-else>
  14. <el-col :span="24" class="receiver">
  15. <p>{{ i.sender_name }}[{{ i.send_time }}]</p>
  16. <p>{{ i.content }}</p>
  17. </el-col>
  18. </span>
  19. </el-col>
  20. </el-col>
  21. <el-col :span="24" class="down">
  22. <el-col :span="20">
  23. <el-input v-model="contInput"></el-input>
  24. </el-col>
  25. <el-col :span="4">
  26. <el-button type="primary" size="mini" @click="speak">发送</el-button>
  27. </el-col>
  28. </el-col>
  29. </el-col>
  30. </el-row>
  31. </div>
  32. </template>
  33. <script>
  34. import { mapState, createNamespacedHelpers } from 'vuex';
  35. export default {
  36. name: 'chat',
  37. props: {
  38. chatList: { type: Array },
  39. },
  40. components: {},
  41. data: function() {
  42. return {
  43. contInput: '',
  44. };
  45. },
  46. created() {},
  47. methods: {
  48. // 当前用户为发言人
  49. isSender(data) {
  50. return this.user.userid == data.sender_id;
  51. },
  52. // 发言提交
  53. speak() {
  54. this.$emit('speak', this.contInput);
  55. this.contInput = '';
  56. },
  57. },
  58. computed: {
  59. ...mapState(['user']),
  60. pageTitle() {
  61. return `${this.$route.meta.title}`;
  62. },
  63. },
  64. metaInfo() {
  65. return { title: this.$route.meta.title };
  66. },
  67. };
  68. </script>
  69. <style lang="less" scoped>
  70. p {
  71. padding: 0;
  72. margin: 0;
  73. }
  74. .chat {
  75. position: relative;
  76. min-height: 620px;
  77. .top {
  78. padding: 10px;
  79. height: 580px;
  80. overflow: auto;
  81. // 发言人
  82. .sender {
  83. float: right;
  84. width: 100;
  85. text-align: right;
  86. p:first-child {
  87. font-size: 18px;
  88. font-weight: bold;
  89. }
  90. }
  91. // 接收人
  92. .receiver {
  93. float: left;
  94. width: 100;
  95. text-align: left;
  96. p:first-child {
  97. font-size: 18px;
  98. font-weight: bold;
  99. }
  100. }
  101. }
  102. .down {
  103. position: absolute;
  104. bottom: 0;
  105. /deep/.el-button {
  106. width: 100%;
  107. height: 40px;
  108. padding: 0;
  109. font-size: 18px;
  110. }
  111. }
  112. }
  113. </style>