group-info.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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.showGroupName}}</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. chatStore: this.useChatStore(),
  58. groupStore: this.useGroupStore(),
  59. userStore: this.useUserStore(),
  60. groupId: null,
  61. group:{},
  62. groupMembers: []
  63. }
  64. },
  65. methods: {
  66. onFocusSearch() {},
  67. onInviteMember() {
  68. uni.navigateTo({
  69. url: `/pages/group/group-invite?id=${this.groupId}`
  70. })
  71. },
  72. onShowMoreMmeber() {
  73. uni.navigateTo({
  74. url: `/pages/group/group-member?id=${this.groupId}`
  75. })
  76. },
  77. onEditGroup() {
  78. uni.navigateTo({
  79. url: `/pages/group/group-edit?id=${this.groupId}`
  80. })
  81. },
  82. onSendMessage() {
  83. let chat = {
  84. type: 'GROUP',
  85. targetId: this.group.id,
  86. showName: this.group.showGroupName,
  87. headImage: this.group.headImage,
  88. };
  89. this.chatStore.openChat(chat);
  90. let chatIdx = this.chatStore.findChatIdx(chat);
  91. uni.navigateTo({
  92. url: "/pages/chat/chat-box?chatIdx=" + chatIdx
  93. })
  94. },
  95. onQuitGroup() {
  96. uni.showModal({
  97. title: '确认退出?',
  98. content: `退出群聊后将不再接受群里的消息,确认退出吗?`,
  99. success: (res) => {
  100. if (res.cancel)
  101. return;
  102. this.$http({
  103. url: `/group/quit/${this.groupId}`,
  104. method: 'DELETE'
  105. }).then(() => {
  106. uni.showModal({
  107. title: `退出成功`,
  108. content: `您已退出群聊'${this.group.name}'`,
  109. showCancel: false,
  110. success: () => {
  111. setTimeout(()=>{
  112. uni.switchTab({
  113. url:"/pages/group/group"
  114. });
  115. this.groupStore.removeGroup(this.groupId);
  116. this.chatStore.removeGroupChat(this.groupId);
  117. },100)
  118. }
  119. })
  120. });
  121. }
  122. });
  123. },
  124. onDissolveGroup() {
  125. uni.showModal({
  126. title: '确认解散?',
  127. content: `确认要解散群聊'${this.group.name}'吗?`,
  128. success: (res) => {
  129. if (res.cancel)
  130. return;
  131. this.$http({
  132. url: `/group/delete/${this.groupId}`,
  133. method: 'delete'
  134. }).then(() => {
  135. uni.showModal({
  136. title: `解散成功`,
  137. content: `群聊'${this.group.name}'已解散`,
  138. showCancel: false,
  139. success: () => {
  140. setTimeout(()=>{
  141. uni.switchTab({
  142. url:"/pages/group/group"
  143. });
  144. this.groupStore.removeGroup(this.groupId);
  145. this.chatStore.removeGroupChat(this.groupId);
  146. },100)
  147. }
  148. })
  149. });
  150. }
  151. });
  152. },
  153. loadGroupInfo() {
  154. this.$http({
  155. url: `/group/find/${this.groupId}`,
  156. method: 'GET'
  157. }).then((group) => {
  158. this.group = group;
  159. // 更新聊天页面的群聊信息
  160. this.chatStore.updateChatFromGroup(group);
  161. // 更新聊天列表的群聊信息
  162. this.groupStore.updateGroup(group);
  163. });
  164. },
  165. loadGroupMembers() {
  166. console.log("loadGroupMembers")
  167. this.$http({
  168. url: `/group/members/${this.groupId}`,
  169. method: "GET"
  170. }).then((members) => {
  171. this.groupMembers = members.filter(m => !m.quit);
  172. })
  173. }
  174. },
  175. computed: {
  176. ownerName() {
  177. let member = this.groupMembers.find((m) => m.userId == this.group.ownerId);
  178. return member && member.showNickName;
  179. },
  180. isOwner() {
  181. return this.group.ownerId == this.userStore.userInfo.id;
  182. }
  183. },
  184. onLoad(options) {
  185. this.groupId = options.id;
  186. // 查询群聊信息
  187. this.loadGroupInfo(options.id);
  188. // 查询群聊成员
  189. this.loadGroupMembers(options.id)
  190. }
  191. }
  192. </script>
  193. <style lang="scss" scoped>
  194. .group-info {
  195. .group-members {
  196. padding: 30rpx;
  197. background: white;
  198. .member-items {
  199. display: flex;
  200. flex-wrap: wrap;
  201. .member-item {
  202. width: 120rpx;
  203. display: flex;
  204. flex-direction: column;
  205. margin: 8rpx 2rpx;
  206. position: relative;
  207. align-items: center;
  208. padding-right: 5px;
  209. background-color: #fafafa;
  210. white-space: nowrap;
  211. .member-name {
  212. width: 100%;
  213. flex: 1;
  214. font-size: 14px;
  215. overflow: hidden;
  216. text-align: center;
  217. white-space: nowrap;
  218. }
  219. }
  220. .invite-btn {
  221. display: flex;
  222. justify-content: center;
  223. align-items: center;
  224. width: 100rpx;
  225. height: 100rpx;
  226. margin: 10rpx;
  227. border: #686868 dashed 2px;
  228. border-radius: 10%;
  229. }
  230. }
  231. .member-more {
  232. padding: 20rpx;
  233. text-align: center;
  234. font-size: 16px;
  235. }
  236. }
  237. .group-detail {
  238. margin-top: 30rpx;
  239. padding: 30rpx;
  240. background: white;
  241. .detail-text{
  242. font-size: 28rpx;
  243. font-weight: 600;
  244. }
  245. .group-edit {
  246. padding: 20rpx;
  247. text-align: center;
  248. font-size: 30rpx;
  249. }
  250. }
  251. .btn-group {
  252. margin-top: 30rpx;
  253. padding: 30rpx;
  254. background: white;
  255. .btn {
  256. margin: 10rpx;
  257. }
  258. }
  259. }
  260. </style>