index.vue 7.6 KB

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