jhimlive.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="jhim-container">
  3. <view class="jhim-message-box">
  4. <view class="jhim-message" v-for="(item, index) in msgs.slice(0,5)" :key="index">
  5. <image class="jhim-message-avatar" :src="item.avatar" />
  6. <text class="jhim-message-text" >{{item.name}}:{{item.text}}</text>
  7. </view>
  8. </view>
  9. <view v-if="ready" class="jhim-input-box">
  10. <input
  11. class="jhim-input"
  12. placeholder="说点什么..."
  13. placeholder-style="color:#fff"
  14. v-model="input"
  15. confirm-type="send" @confirm="btnImSend" />
  16. </view>
  17. <view v-else class="jhim-logining"><text class="jhim-logining-text">登录中...</text></view>
  18. </view>
  19. </template>
  20. <script>
  21. import Jhim from "./jhim";
  22. const LOGTAG = '--JHIM--:';
  23. export default {
  24. name: 'jhim',
  25. data() {
  26. return {
  27. input: '',
  28. msgs: [],
  29. ready: false,
  30. };
  31. },
  32. props: {
  33. sdkAppID: Number,
  34. secretKey: String,
  35. userId: String,
  36. roomId: String,
  37. name: String,
  38. avatar: String,
  39. },
  40. methods: {
  41. enterRoom() {
  42. this.jhim = this.jhim||(Jhim.jhim)||(new Jhim(this.userId, this.sdkAppID, this.secretKey));
  43. this.jhim.on('onIMMessageReceived', event=>{
  44. this.msgs = this.msgs.concat(event);
  45. }).on('onIMGroupTipElem', res=>{
  46. this.$emit('onMemberCount', this.memberCount = res.memberCount);
  47. }).on('onIMSDKNotReady', event=>{
  48. this.ready = false;
  49. }).on('onIMSDKReady', event=>{
  50. this.ready = true;
  51. })
  52. this.jhim.login(this.name, this.avatar).then(()=>this.jhim.createGroup(this.roomId));
  53. },
  54. exitRoom() {
  55. if(this.isAuthor) {
  56. this.jhim.dismissGroup().then(()=>this.jhim.logout());
  57. }else {
  58. this.jhim.exitGroup().then(()=>this.jhim.logout());
  59. }
  60. },
  61. btnImSend() {
  62. this.jhim.sendGroupText(this.input).then(msg=>{
  63. this.input = '';
  64. this.msgs.push(msg);
  65. });
  66. }
  67. }
  68. };
  69. </script>
  70. <style scoped>
  71. /* .jhim-container {
  72. } */
  73. .jhim-message-box {
  74. background-color:rgba(0, 0, 0, 0.4);
  75. border-radius: 1000px;
  76. padding: 5;
  77. }
  78. .jhim-message {
  79. display: flex;
  80. flex-direction: row;
  81. align-items: center;
  82. }
  83. .jhim-message-avatar {
  84. width: 24rpx;
  85. height: 24rpx;
  86. margin-left: 5px;
  87. }
  88. .jhim-message-text {
  89. color: #fff;
  90. font-size: 24rpx;
  91. }
  92. .jhim-input-box {
  93. padding: 5px;
  94. }
  95. .jhim-input {
  96. color: #fff;
  97. font-size: 24rpx;
  98. }
  99. .jhim-logining {
  100. padding: 5px;
  101. }
  102. .jhim-logining-text {
  103. color: #fff;
  104. font-size: 24rpx;
  105. }
  106. </style>