group-info.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. let chatIdx = this.$store.getters.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.$store.commit("removeGroup", this.groupId);
  113. },100)
  114. }
  115. })
  116. });
  117. }
  118. });
  119. },
  120. onDissolveGroup() {
  121. console.log(this.group.name)
  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.$store.commit("removeGroup", this.groupId);
  142. },100)
  143. }
  144. })
  145. });
  146. }
  147. });
  148. },
  149. loadGroupInfo() {
  150. this.$http({
  151. url: `/group/find/${this.groupId}`,
  152. method: 'GET'
  153. }).then((group) => {
  154. this.group = group;
  155. // 更新聊天页面的群聊信息
  156. this.$store.commit("updateChatFromGroup", group);
  157. // 更新聊天列表的群聊信息
  158. this.$store.commit("updateGroup", group);
  159. });
  160. },
  161. loadGroupMembers() {
  162. console.log("loadGroupMembers")
  163. this.$http({
  164. url: `/group/members/${this.groupId}`,
  165. method: "GET"
  166. }).then((members) => {
  167. this.groupMembers = members.filter(m => !m.quit);
  168. })
  169. }
  170. },
  171. computed: {
  172. ownerName() {
  173. let member = this.groupMembers.find((m) => m.userId == this.group.ownerId);
  174. return member && member.aliasName;
  175. },
  176. isOwner() {
  177. return this.group.ownerId == this.$store.state.userStore.userInfo.id;
  178. }
  179. },
  180. onLoad(options) {
  181. this.groupId = options.id;
  182. // 查询群聊信息
  183. this.loadGroupInfo(options.id);
  184. // 查询群聊成员
  185. this.loadGroupMembers(options.id)
  186. }
  187. }
  188. </script>
  189. <style lang="scss" scoped>
  190. .group-info {
  191. .group-members {
  192. padding: 30rpx;
  193. background: white;
  194. .member-items {
  195. display: flex;
  196. flex-wrap: wrap;
  197. .member-item {
  198. width: 120rpx;
  199. display: flex;
  200. flex-direction: column;
  201. margin: 8rpx 2rpx;
  202. position: relative;
  203. align-items: center;
  204. padding-right: 5px;
  205. background-color: #fafafa;
  206. white-space: nowrap;
  207. .member-name {
  208. width: 100%;
  209. flex: 1;
  210. font-size: 14px;
  211. overflow: hidden;
  212. text-align: center;
  213. white-space: nowrap;
  214. }
  215. }
  216. .invite-btn {
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. width: 100rpx;
  221. height: 100rpx;
  222. margin: 10rpx;
  223. border: #686868 dashed 2px;
  224. border-radius: 10%;
  225. }
  226. }
  227. .member-more {
  228. padding: 20rpx;
  229. text-align: center;
  230. font-size: 16px;
  231. }
  232. }
  233. .group-detail {
  234. margin-top: 30rpx;
  235. padding: 30rpx;
  236. background: white;
  237. .detail-text{
  238. font-size: 28rpx;
  239. font-weight: 600;
  240. }
  241. .group-edit {
  242. padding: 20rpx;
  243. text-align: center;
  244. font-size: 30rpx;
  245. }
  246. }
  247. .btn-group {
  248. margin-top: 30rpx;
  249. padding: 30rpx;
  250. background: white;
  251. .btn {
  252. margin: 10rpx;
  253. }
  254. }
  255. }
  256. </style>