group-info.vue 6.4 KB

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