index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view class="group_card_container">
  3. <custom-nav-bar title="" />
  4. <u-toast ref="uToast"></u-toast>
  5. <view class="main">
  6. <view class="base_info">
  7. <my-avatar :src="sourceGroupInfo.faceURL" :isGroup="true" size="48" />
  8. <view>
  9. <view class="group_name">
  10. <text>{{ sourceGroupInfo.groupName }}</text>
  11. <text v-if="!!sourceGroupInfo.memberCount"
  12. >({{ sourceGroupInfo.memberCount }})</text
  13. >
  14. </view>
  15. <view class="create_time">
  16. <u-icon name="clock" color="#999" size="14"></u-icon>
  17. <text>{{ getCreateTime }}</text>
  18. </view>
  19. </view>
  20. </view>
  21. <view
  22. v-if="!!sourceGroupInfo.memberCount"
  23. @click="toMemberList"
  24. class="member_row info_row"
  25. >
  26. <view class="member_desc">
  27. <text>群成员</text>
  28. <text class="member_count">{{
  29. `${sourceGroupInfo.memberCount}人`
  30. }}</text>
  31. <u-icon name="arrow-right" color="#999" size="18"></u-icon>
  32. </view>
  33. <view class="member_list">
  34. <my-avatar
  35. v-for="member in getRenderMemberList"
  36. :key="member.userID"
  37. class="member_item"
  38. size="42"
  39. :src="member.faceURL"
  40. :desc="member.nickname"
  41. ></my-avatar>
  42. <u-avatar
  43. bgColor="#5496EB"
  44. icon="more-dot-fill"
  45. shape="square"
  46. size="42"
  47. ></u-avatar>
  48. </view>
  49. </view>
  50. <view class="info_row">
  51. <user-info-row-item lable="群ID号" :content="sourceGroupInfo.groupID" />
  52. </view>
  53. </view>
  54. <view class="action_row">
  55. <u-button type="primary" v-if="!isJoinedGroup" @click="joinGroup"
  56. >申请加入该群</u-button
  57. >
  58. <u-button type="primary" v-else @click="chatingInGroup">发消息</u-button>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. import { GroupMemberListTypes } from "../../../constant";
  64. import { navigateToDesignatedConversation } from "../../../util/imCommon";
  65. import IMSDK, {
  66. GroupVerificationType,
  67. SessionType,
  68. } from "openim-uniapp-polyfill";
  69. import dayjs from "dayjs";
  70. import MyAvatar from "../../../components/MyAvatar/index.vue";
  71. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  72. import UserInfoRowItem from "../userCard/components/UserInfoRowItem.vue";
  73. const userIcon = "https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/contact_my_friend.png";
  74. export default {
  75. components: {
  76. CustomNavBar,
  77. MyAvatar,
  78. UserInfoRowItem,
  79. },
  80. data() {
  81. return {
  82. sourceID: "",
  83. isScan: false,
  84. sourceGroupInfo: {},
  85. groupMemberList: [],
  86. };
  87. },
  88. computed: {
  89. isJoinedGroup() {
  90. return (
  91. this.$store.getters.storeGroupList.findIndex(
  92. (group) => group.groupID === this.sourceID,
  93. ) !== -1
  94. );
  95. },
  96. getCreateTime() {
  97. return dayjs(this.sourceGroupInfo.createTime).format("YYYY-MM-DD");
  98. },
  99. getRenderMemberList() {
  100. if (this.isJoinedGroup) {
  101. this.groupMemberList;
  102. return this.groupMemberList;
  103. }
  104. const memberCount = this.sourceGroupInfo.memberCount ?? 0;
  105. return new Array(memberCount >= 6 ? 6 : memberCount)
  106. .fill(1)
  107. .map((_, idx) => ({
  108. userID: idx,
  109. faceURL: userIcon,
  110. }));
  111. },
  112. },
  113. onLoad(options) {
  114. const { sourceID, sourceInfo, isScan } = options;
  115. this.isScan = !!isScan;
  116. if (sourceID) {
  117. this.sourceID = sourceID;
  118. this.getSourceGroupInfo();
  119. } else {
  120. const info = JSON.parse(sourceInfo);
  121. this.sourceID = info.groupID;
  122. this.sourceGroupInfo = {
  123. ...info,
  124. };
  125. }
  126. this.getGroupMemberList();
  127. },
  128. methods: {
  129. toMemberList() {
  130. if (this.isJoinedGroup) {
  131. this.$store.dispatch("conversation/getCurrentGroup", this.sourceID);
  132. this.$store.dispatch(
  133. "conversation/getCurrentMemberInGroup",
  134. this.sourceID,
  135. );
  136. uni.navigateTo({
  137. url: `/pages_im/pages/conversation/groupMemberList/index?type=${GroupMemberListTypes.Preview}&groupID=${this.sourceID}`,
  138. });
  139. }
  140. },
  141. joinGroup() {
  142. uni.$u.route("/pages_im/pages/common/sendAddRequest/index", {
  143. isGroup: true,
  144. sourceID: this.sourceID,
  145. isScan: this.isScan,
  146. notNeedVerification:
  147. this.sourceGroupInfo.needVerification ===
  148. GroupVerificationType.AllNot,
  149. sessionType: SessionType.WorkingGroup,
  150. });
  151. },
  152. chatingInGroup() {
  153. navigateToDesignatedConversation(
  154. this.sourceID,
  155. SessionType.WorkingGroup,
  156. ).catch(() => this.showToast("获取会话信息失败"));
  157. },
  158. async getSourceGroupInfo() {
  159. let info = null;
  160. if (this.isJoinedGroup) {
  161. info = this.$store.getters.storeGroupList.find(
  162. (group) => group.groupID === this.sourceID,
  163. );
  164. } else {
  165. try {
  166. const { data } = await IMSDK.asyncApi(
  167. IMSDK.IMMethods.GetSpecifiedGroupsInfo,
  168. IMSDK.uuid(),
  169. [this.sourceID],
  170. );
  171. info = data[0] ?? {};
  172. } catch (e) {
  173. info = {};
  174. }
  175. }
  176. this.sourceGroupInfo = {
  177. ...info,
  178. };
  179. },
  180. getGroupMemberList() {
  181. if (this.isJoinedGroup) {
  182. IMSDK.asyncApi(IMSDK.IMMethods.GetGroupMemberList, IMSDK.uuid(), {
  183. groupID: this.sourceID,
  184. filter: 0,
  185. offset: 0,
  186. count: 6,
  187. }).then(({ data }) => {
  188. this.groupMemberList = [...data];
  189. });
  190. }
  191. },
  192. showToast(message) {
  193. this.$refs.uToast.show({
  194. message,
  195. });
  196. },
  197. },
  198. };
  199. </script>
  200. <style lang="scss" scoped>
  201. .group_card_container {
  202. @include colBox(false);
  203. height: 100vh;
  204. background-color: #f6f6f6;
  205. .main {
  206. display: flex;
  207. flex-direction: column;
  208. flex: 1;
  209. }
  210. .base_info {
  211. @include vCenterBox();
  212. background-color: #fff;
  213. padding: 44rpx;
  214. margin-bottom: 18rpx;
  215. .u-avatar {
  216. margin-right: 24rpx;
  217. }
  218. .group_name {
  219. display: flex;
  220. margin-bottom: 12rpx;
  221. }
  222. .create_time {
  223. @include vCenterBox();
  224. justify-content: center;
  225. color: #adadad;
  226. font-size: 26rpx;
  227. .u-icon {
  228. margin-right: 12rpx;
  229. }
  230. }
  231. }
  232. .member_row {
  233. padding: 24rpx 44rpx;
  234. .member_desc {
  235. margin-bottom: 24rpx;
  236. position: relative;
  237. .member_count {
  238. font-size: 28rpx;
  239. color: #adadad;
  240. margin-left: 24rpx;
  241. }
  242. .u-icon {
  243. position: absolute;
  244. right: 0;
  245. top: 0;
  246. }
  247. }
  248. .member_list {
  249. display: flex;
  250. .member_item {
  251. margin-right: 12rpx;
  252. &:nth-child(7) {
  253. margin-right: 0;
  254. }
  255. }
  256. }
  257. }
  258. .info_row {
  259. background-color: #fff;
  260. margin-bottom: 24rpx;
  261. /deep/ .content {
  262. color: #adadad;
  263. }
  264. }
  265. .action_row {
  266. background-color: #fff;
  267. padding: 44rpx 44rpx;
  268. }
  269. .online_state {
  270. @include vCenterBox();
  271. margin-left: 24rpx;
  272. font-size: 24rpx;
  273. color: #999;
  274. .dot {
  275. background-color: #10cc64;
  276. width: 12rpx;
  277. height: 12rpx;
  278. border-radius: 50%;
  279. margin-right: 12rpx;
  280. }
  281. }
  282. }
  283. </style>