group-info.vue 6.6 KB

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