join.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="TUI-Create-conversation-container">
  3. <view class="tui-navigatorbar">
  4. <image class="tui-navigatorbar-back" @tap="goBack" src="/static/static/assets/ic_back_white.svg"></image>
  5. <view class="conversation-title">加入群聊</view>
  6. </view>
  7. <view class="tui-search-area">
  8. <view class="tui-search-bar">
  9. <image class="tui-searchcion" src="/static/static/assets/serach-icon.svg"></image>
  10. <input
  11. class="tui-search-bar-input"
  12. :value="groupID"
  13. placeholder="请输入群ID"
  14. @input="groupIDInput"
  15. @confirm="searchGroupByID"
  16. @blur="searchGroupByID"
  17. />
  18. </view>
  19. </view>
  20. <view class="tui-person-to-invite" v-if="searchGroup.groupID">
  21. <image
  22. @tap="handleChoose"
  23. class="tui-normal-choose"
  24. :src="isChoose ? '/static/static/assets/single-choice-hover.svg' : '/static/static/assets/single-choice-normal.svg'"
  25. ></image>
  26. <view class="tui-person-profile">
  27. <image class="tui-person-profile-avatar" :src="groupAvatar || '/static/static/assets/gruopavatar.svg'"></image>
  28. <view>
  29. <view class="tui-person-profile-nick">{{ searchGroup.name }}</view>
  30. <view class="tui-person-profile-userID">群ID:{{ searchGroup.groupID }}</view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="tui-confirm-btn" @tap="bindConfirmJoin">确认加入</view>
  35. </view>
  36. </template>
  37. <script>
  38. import logger from '../../../utils/logger';
  39. export default {
  40. data() {
  41. return {
  42. groupID: '',
  43. searchGroup: {
  44. groupID: '',
  45. name: ''
  46. },
  47. isChoose: false,
  48. groupAvatar: ''
  49. };
  50. },
  51. components: {},
  52. props: {},
  53. methods: {
  54. goBack() {
  55. uni.navigateBack({
  56. delta: 1
  57. });
  58. },
  59. groupIDInput(e) {
  60. this.setData({
  61. groupID: e.detail.value
  62. });
  63. },
  64. searchGroupByID() {
  65. uni.$TUIKit
  66. .searchGroupByID(this.groupID)
  67. .then(imResponse => {
  68. if (imResponse.data.group.groupID !== '') {
  69. this.setData({
  70. searchGroup: imResponse.data.group,
  71. groupAvatar: imResponse.data.group.avatar
  72. });
  73. }
  74. })
  75. .catch(imError => {
  76. uni.hideLoading();
  77. if (imError.code === 10007) {
  78. uni.showToast({
  79. title: '讨论组类型群不允许申请加群',
  80. icon: 'none'
  81. });
  82. } else {
  83. uni.showToast({
  84. title: '未找到该群组',
  85. icon: 'none'
  86. });
  87. }
  88. });
  89. },
  90. handleChoose() {
  91. this.isChoose = !this.isChoose;
  92. this.setData({
  93. searchGroup: this.searchGroup
  94. });
  95. },
  96. bindConfirmJoin() {
  97. logger.log(`TUI-Group | join-group | bindConfirmJoin | groupID: ${this.groupID}`);
  98. uni.$TUIKit
  99. .joinGroup({
  100. groupID: this.groupID,
  101. type: this.searchGroup.type
  102. })
  103. .then(imResponse => {
  104. switch (imResponse.data.status) {
  105. case uni.$TUIKitTIM.TYPES.JOIN_STATUS_WAIT_APPROVAL:
  106. // 等待管理员同意
  107. break;
  108. case uni.$TUIKitTIM.TYPES.JOIN_STATUS_SUCCESS:
  109. // 加群成功
  110. console.log(imResponse.data.group); // 加入的群组资料
  111. break;
  112. case uni.$TUIKitTIM.TYPES.JOIN_STATUS_ALREADY_IN_GROUP:
  113. // 已经在群中
  114. break;
  115. default:
  116. break;
  117. }
  118. })
  119. .catch(imError => {
  120. console.warn('joinGroup error:', imError); // 申请加群失败的相关信息
  121. });
  122. if (this.isChoose) {
  123. uni.navigateTo({
  124. url: `../../TUI-Chat/chat?conversationID=GROUP${this.searchGroup.groupID}`
  125. });
  126. } else {
  127. uni.showToast({
  128. title: '请选择相关群聊',
  129. icon: 'error'
  130. });
  131. }
  132. }
  133. }
  134. };
  135. </script>
  136. <style>
  137. @import './join.css';
  138. </style>