index.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="chat-room">
  3. <scroll-view id="scrollview" class="room" :scroll-top="scrollTop" scroll-y="true" >
  4. <view class="chat-container">
  5. <view class="item" v-for="(item,index) in chats" :key="index"
  6. :class="item.type==='mine'?'lf':''">
  7. <view class="avatar">
  8. <!-- #ifdef MP-WEIXIN -->
  9. <open-data type="userAvatarUrl" class="avatar-tag" v-if="item.type==='mine'"></open-data>
  10. <image src="/static/components/avatar.png" class="avatar-tag" mode="widthFix" v-if="item.type!=='mine'"></image>
  11. <text class="username">{{item.user}}</text>
  12. <!-- #endif -->
  13. <!-- #ifndef MP-WEIXIN -->
  14. <image src="/static/components/avatar.png" class="avatar-tag" mode="widthFix"></image>
  15. <text class="username">{{item.user}}</text>
  16. <!-- #endif -->
  17. </view>
  18. <view class="msgbox">
  19. <text class="msg">{{item.msg}}</text>
  20. </view>
  21. </view>
  22. </view>
  23. </scroll-view>
  24. <view class="send">
  25. <textarea
  26. maxlength="-1"
  27. class="sendInput"
  28. type="text"
  29. v-model="sendMsg"
  30. cursor-spacing="20"
  31. @confirm="sendMessage"
  32. confirm-type="发送"
  33. auto-height
  34. ></textarea>
  35. <button size="mini" class="sendBt"
  36. @click="sendMessage"
  37. v-if="sendMsg.length>0"
  38. >
  39. <text>发送</text>
  40. </button>
  41. <button size="mini" class="sendBt"
  42. @click="callIM"
  43. v-if="sendMsg.length<1"
  44. >
  45. <text>呼叫</text>
  46. </button>
  47. <!-- <button class="moreHandle" v-if="sendMsg.length<1" >+</button> -->
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. name:"IM-chat",
  54. props:{
  55. chats:{
  56. type:[Array],
  57. default:()=>[]
  58. }
  59. },
  60. watch:{
  61. chats(){
  62. if(this.chats.length>1){
  63. this.scrollToBottom();
  64. }
  65. }
  66. },
  67. data() {
  68. return {
  69. scrollTop: 0,
  70. sendMsg:''
  71. }
  72. },
  73. methods: {
  74. sendMessage(){
  75. this.$emit('send',this.sendMsg);
  76. this.sendMsg="";
  77. },
  78. callIM(){
  79. this.$emit('call');
  80. },
  81. scrollToBottom: function () {
  82. const query = uni.createSelectorQuery().in(this);
  83. query.selectAll('.chat-container').boundingClientRect(data => {
  84. this.scrollTop=data[0].height;
  85. }).exec();
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. @import url('./index.css')
  92. </style>