group-info.vue 6.5 KB

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