group-info.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="page group-info">
  3. <nav-bar back>群聊信息</nav-bar>
  4. <view v-if="!group.quit" class="group-members">
  5. <view class="member-items">
  6. <view v-for="(member, idx) in groupMembers" :key="idx">
  7. <view class="member-item" v-if="idx < 9">
  8. <head-image :id="member.userId" :name="member.showNickName" :url="member.headImage" size="small"
  9. :online="member.online"></head-image>
  10. <view class="member-name">
  11. <text>{{ member.showNickName }}</text>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="invite-btn" @click="onInviteMember()">
  16. <uni-icons type="plusempty" size="20" color="#888888"></uni-icons>
  17. </view>
  18. </view>
  19. <view class="member-more" @click="onShowMoreMmeber()">{{ `查看全部群成员${groupMembers.length}人` }}></view>
  20. </view>
  21. <view class="group-detail">
  22. <uni-section title="群聊名称">
  23. <template v-slot:right>
  24. <text class="detail-text">{{ group.name }}</text>
  25. </template>
  26. </uni-section>
  27. <uni-section title="群主">
  28. <template v-slot:right>
  29. <text class="detail-text">{{ ownerName }}</text>
  30. </template>
  31. </uni-section>
  32. <uni-section title="群名备注">
  33. <template v-slot:right>
  34. <text class="detail-text"> {{ group.remarkGroupName }}</text>
  35. </template>
  36. </uni-section>
  37. <uni-section title="我在本群的昵称">
  38. <template v-slot:right>
  39. <text class="detail-text"> {{ group.showNickName }}</text>
  40. </template>
  41. </uni-section>
  42. <uni-section v-if="group.notice" title="群公告">
  43. <uni-notice-bar :text="group.notice" />
  44. </uni-section>
  45. <view v-if="!group.quit" class="group-edit" @click="onEditGroup()">修改群聊资料 > </view>
  46. </view>
  47. <bar-group v-if="!group.quit">
  48. <btn-bar type="primary" title="发送消息" @tap="onSendMessage()"></btn-bar>
  49. <btn-bar v-if="!isOwner" type="danger" title="退出群聊" @tap="onQuitGroup()"></btn-bar>
  50. <btn-bar v-if="isOwner" type="danger" title="解散群聊" @tap="onDissolveGroup()"></btn-bar>
  51. </bar-group>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. groupId: null,
  59. group: {},
  60. groupMembers: []
  61. }
  62. },
  63. methods: {
  64. onFocusSearch() { },
  65. onInviteMember() {
  66. uni.navigateTo({
  67. url: `/pages/group/group-invite?id=${this.groupId}`
  68. })
  69. },
  70. onShowMoreMmeber() {
  71. uni.navigateTo({
  72. url: `/pages/group/group-member?id=${this.groupId}`
  73. })
  74. },
  75. onEditGroup() {
  76. uni.navigateTo({
  77. url: `/pages/group/group-edit?id=${this.groupId}`
  78. })
  79. },
  80. onSendMessage() {
  81. let chat = {
  82. type: 'GROUP',
  83. targetId: this.group.id,
  84. showName: this.group.showGroupName,
  85. headImage: this.group.headImage,
  86. };
  87. this.chatStore.openChat(chat);
  88. let chatIdx = this.chatStore.findChatIdx(chat);
  89. uni.navigateTo({
  90. url: "/pages/chat/chat-box?chatIdx=" + chatIdx
  91. })
  92. },
  93. onQuitGroup() {
  94. uni.showModal({
  95. title: '确认退出?',
  96. content: `退出群聊后将不再接受群里的消息,确认退出吗?`,
  97. success: (res) => {
  98. if (res.cancel)
  99. return;
  100. this.$http({
  101. url: `/group/quit/${this.groupId}`,
  102. method: 'DELETE'
  103. }).then(() => {
  104. uni.showModal({
  105. title: `退出成功`,
  106. content: `您已退出群聊'${this.group.name}'`,
  107. showCancel: false,
  108. success: () => {
  109. setTimeout(() => {
  110. uni.switchTab({
  111. url: "/pages/group/group"
  112. });
  113. this.groupStore.removeGroup(this.groupId);
  114. this.chatStore.removeGroupChat(this.groupId);
  115. }, 100)
  116. }
  117. })
  118. });
  119. }
  120. });
  121. },
  122. onDissolveGroup() {
  123. uni.showModal({
  124. title: '确认解散?',
  125. content: `确认要解散群聊'${this.group.name}'吗?`,
  126. success: (res) => {
  127. if (res.cancel)
  128. return;
  129. this.$http({
  130. url: `/group/delete/${this.groupId}`,
  131. method: 'delete'
  132. }).then(() => {
  133. uni.showModal({
  134. title: `解散成功`,
  135. content: `群聊'${this.group.name}'已解散`,
  136. showCancel: false,
  137. success: () => {
  138. setTimeout(() => {
  139. uni.switchTab({
  140. url: "/pages/group/group"
  141. });
  142. this.groupStore.removeGroup(this.groupId);
  143. this.chatStore.removeGroupChat(this.groupId);
  144. }, 100)
  145. }
  146. })
  147. });
  148. }
  149. });
  150. },
  151. loadGroupInfo() {
  152. this.$http({
  153. url: `/group/find/${this.groupId}`,
  154. method: 'GET'
  155. }).then((group) => {
  156. this.group = group;
  157. // 更新聊天页面的群聊信息
  158. this.chatStore.updateChatFromGroup(group);
  159. // 更新聊天列表的群聊信息
  160. this.groupStore.updateGroup(group);
  161. });
  162. },
  163. loadGroupMembers() {
  164. console.log("loadGroupMembers")
  165. this.$http({
  166. url: `/group/members/${this.groupId}`,
  167. method: "GET"
  168. }).then((members) => {
  169. this.groupMembers = members.filter(m => !m.quit);
  170. })
  171. }
  172. },
  173. computed: {
  174. ownerName() {
  175. let member = this.groupMembers.find((m) => m.userId == this.group.ownerId);
  176. return member && member.showNickName;
  177. },
  178. isOwner() {
  179. return this.group.ownerId == this.userStore.userInfo.id;
  180. }
  181. },
  182. onLoad(options) {
  183. this.groupId = options.id;
  184. // 查询群聊信息
  185. this.loadGroupInfo(options.id);
  186. // 查询群聊成员
  187. this.loadGroupMembers(options.id)
  188. }
  189. }
  190. </script>
  191. <style lang="scss" scoped>
  192. .group-info {
  193. .group-members {
  194. padding: 30rpx;
  195. background: white;
  196. .member-items {
  197. display: flex;
  198. flex-wrap: wrap;
  199. .member-item {
  200. width: 120rpx;
  201. display: flex;
  202. flex-direction: column;
  203. margin: 8rpx 2rpx;
  204. position: relative;
  205. align-items: center;
  206. padding-right: 5px;
  207. white-space: nowrap;
  208. .member-name {
  209. width: 100%;
  210. flex: 1;
  211. overflow: hidden;
  212. text-align: center;
  213. white-space: nowrap;
  214. padding-top: 8rpx;
  215. font-size: $im-font-size-smaller;
  216. }
  217. }
  218. .invite-btn {
  219. display: flex;
  220. justify-content: center;
  221. align-items: center;
  222. width: 86rpx;
  223. height: 86rpx;
  224. margin: 10rpx;
  225. border: $im-border solid 2rpx;
  226. border-radius: 10%;
  227. }
  228. }
  229. .member-more {
  230. padding-top: 24rpx;
  231. text-align: center;
  232. font-size: $im-font-size-small;
  233. color: $im-text-color-lighter;
  234. }
  235. }
  236. .group-detail {
  237. margin-top: 30rpx;
  238. padding: 20rpx 20rpx;
  239. background: white;
  240. .detail-text {
  241. font-size: $im-font-size;
  242. }
  243. .group-edit {
  244. padding-top: 30rpx;
  245. text-align: center;
  246. font-size: $im-font-size-small;
  247. color: $im-text-color-lighter;
  248. }
  249. }
  250. }
  251. </style>