index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <view>
  3. <view class="group-information-box" @show="getgroupProfile">
  4. <view class="group-box">
  5. <text class="group-ID">群ID:{{ conversation.groupProfile.groupID }}</text>
  6. <view @tap="showMoreHandler">
  7. <text class="group-member">聊天成员:{{ conversation.groupProfile.memberCount }}人</text>
  8. <image v-if="notShow" class=" icon-right" src="/static/static/assets/down.svg"></image>
  9. <image v-if="isShow" class=" icon-right" src="/static/static/assets/up.svg"></image>
  10. </view>
  11. </view>
  12. <view v-show="!hidden" class="showdetail">
  13. <view v-for="(item, index) in groupmemberprofile" :key="index" class="box" v-if="index < 3" :data-value="item">
  14. <image
  15. class="profile-box"
  16. :src="item.avatar || 'https://sdk-web-1252463788.cos.ap-hongkong.myqcloud.com/component/TUIKit/assets/avatar_21.png'"
  17. ></image>
  18. <text class="nick-box">{{ item.nick || item.userID }}</text>
  19. </view>
  20. <view class="box" v-if="showMore">
  21. <image class="profile-box" src="/static/static/assets/show.svg" @tap="showMoreMember"></image>
  22. <text class="nick-box">更多</text>
  23. </view>
  24. <view class="left-box">
  25. <view class="box-group" v-if="addShow">
  26. <image class="addmember" src="/static/static/assets/addgroup.svg" @tap="addMember"></image>
  27. <text class="addmember-text">添加成员</text>
  28. </view>
  29. <view class="box-group-quit">
  30. <image class="quitgroup" src="/static/static/assets/quitgroup.svg" @tap.stop="quitGroup"></image>
  31. <text class="quitgroup-text">退出群聊</text>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="pop-container">
  37. <view class="popup-mask" v-if="popupToggle" @tap.stop="handleEditToggle">
  38. <view class="pop-main">
  39. <view class="pop-main-header">
  40. <text class="group-member-text">群成员</text>
  41. <text class="close" @tap.stop="close">关闭</text>
  42. </view>
  43. <view class="image-list">
  44. <view v-for="(item, index) in groupmemberprofile" :key="index" class="image-nick-box" :data-value="item">
  45. <image
  46. class="image-box"
  47. :src="item.avatar || 'https://sdk-web-1252463788.cos.ap-hongkong.myqcloud.com/component/TUIKit/assets/avatar_21.png'"
  48. ></image>
  49. <text class="groupmembername">{{ item.nick || item.userID }}</text>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="pop-container">
  56. <view class="quitpop-mask" v-if="quitpopupToggle">
  57. <view class="quitpop">
  58. <view class=" quit-box">
  59. <view class="text-box"><text class="confirmQuitgroup-text">退出群聊后会同步删除历史聊天记录,是否要退出群聊?</text></view>
  60. <view class="text-box-qiut" @tap.stop="quitgroupConfirm"><text class="quitgroup-confirm">退出</text></view>
  61. <view class="text-box-cancle" @tap="quitgroupAbandon"><text class="quitgroup-abandon">取消</text></view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="mask" v-if="addpopupToggle">
  67. <view class="popup">
  68. <view class="popup-main">
  69. <text>添加群成员</text>
  70. <input class="input-box" type="number" placeholder="请输入userID" @input="binduserIDInput" placeholder-style="color:#BBBBBB;" />
  71. </view>
  72. <view class="popup-footer">
  73. <button class=" popup-footer-button submit" @tap.stop="submit">确认</button>
  74. <button class="popup-footer-button cancel" @tap.stop="close">取消</button>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </template>
  80. <script>
  81. import logger from '../../../utils/logger';
  82. export default {
  83. data() {
  84. return {
  85. userID: '',
  86. // conversation: {},
  87. newgroup: {},
  88. groupmemberprofile: {},
  89. groupmemberavatar: [],
  90. groupmembernick: [],
  91. hidden: true,
  92. notShow: true,
  93. isShow: false,
  94. showMore: false,
  95. addShow: false,
  96. popupToggle: false,
  97. quitpopupToggle: false,
  98. addpopupToggle: false
  99. };
  100. },
  101. components: {},
  102. props: {
  103. conversation: {
  104. type: Object
  105. }
  106. },
  107. watch: {
  108. conversation: {
  109. handler: function(newVal) {
  110. if (newVal.type === 'GROUP');
  111. this.conversation=newVal;
  112. // this.setData({
  113. // conversation: newVal
  114. // });
  115. },
  116. immediate: true,
  117. deep: true
  118. }
  119. },
  120. beforeMount() {},
  121. methods: {
  122. showMoreHandler() {
  123. uni.$TUIKit
  124. .getGroupMemberList({
  125. groupID: this.conversation.groupProfile.groupID,
  126. count: 50,
  127. offset: 0
  128. }) // 从0开始拉取30个群成员
  129. .then(imResponse => {
  130. logger.log(`| TUI-group-profile | getGroupMemberList | getGroupMemberList-length: ${imResponse.data.memberList.length}`);
  131. if (this.conversation.groupProfile.type === 'Private') {
  132. this.setData({
  133. addShow: true
  134. });
  135. }
  136. if (imResponse.data.memberList.length > 3) {
  137. this.setData({
  138. showMore: true
  139. });
  140. }
  141. this.setData({
  142. groupmemberprofile: imResponse.data.memberList,
  143. hidden: !this.hidden,
  144. notShow: !this.notShow,
  145. isShow: !this.isShow
  146. });
  147. });
  148. },
  149. showless() {
  150. this.setData({
  151. isShow: false,
  152. notShow: true,
  153. hidden: true
  154. });
  155. },
  156. showMoreMember() {
  157. this.setData({
  158. popupToggle: true // quitpopupToggle: false
  159. });
  160. },
  161. close() {
  162. this.setData({
  163. popupToggle: false,
  164. addpopupToggle: false,
  165. quitpopupToggle: false
  166. });
  167. },
  168. quitGroup() {
  169. this.setData({
  170. quitpopupToggle: true,
  171. popupToggle: false
  172. });
  173. },
  174. quitgroupConfirm() {
  175. uni.$TUIKit
  176. .quitGroup(this.conversation.groupProfile.groupID)
  177. .then(imResponse => {
  178. console.log(imResponse.data.groupID); // 退出成功的群 ID
  179. uni.navigateBack({
  180. delta: 1
  181. });
  182. })
  183. .catch(imError => {
  184. uni.showToast({
  185. title: '该群不允许群主主动退出',
  186. icon: 'none'
  187. });
  188. console.warn('quitGroup error:', imError); // 退出群组失败的相关信息
  189. });
  190. },
  191. quitgroupAbandon() {
  192. console.log(22222);
  193. this.setData({
  194. quitpopupToggle: false
  195. });
  196. },
  197. addMember() {
  198. this.setData({
  199. addpopupToggle: true
  200. });
  201. },
  202. binduserIDInput(e) {
  203. const id = e.detail.value;
  204. this.setData({
  205. userID: id
  206. });
  207. },
  208. submit() {
  209. console.log(this.userID);
  210. uni.$TUIKit
  211. .addGroupMember({
  212. groupID: this.conversation.groupProfile.groupID,
  213. userIDList: [this.userID]
  214. })
  215. .then(imResponse => {
  216. if (imResponse.data.successUserIDList.length > 0) {
  217. uni.showToast({
  218. title: '添加成功',
  219. duration: 800
  220. });
  221. this.userID = '';
  222. this.addMemberModalVisible = false;
  223. this.setData({
  224. addpopupToggle: false
  225. });
  226. }
  227. if (imResponse.data.existedUserIDList.length > 0) {
  228. uni.showToast({
  229. title: '该用户已在群中',
  230. duration: 800,
  231. icon: 'none'
  232. });
  233. }
  234. })
  235. .catch(imError => {
  236. console.warn('addGroupMember error:', imError); // 错误信息
  237. uni.showToast({
  238. title: '添加失败,请确保该用户存在',
  239. duration: 800,
  240. icon: 'none'
  241. });
  242. });
  243. },
  244. handleEditToggle() {
  245. console.log('占位:函数 handleEditToggle 未声明');
  246. },
  247. getgroupProfile() {
  248. console.log('占位:函数 getgroupProfile 未声明');
  249. }
  250. }
  251. };
  252. </script>
  253. <style>
  254. @import './index.css';
  255. </style>