group-info.vue 6.8 KB

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