memberOperate.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <view class="TUI-Create-conversation-container">
  3. <view class="tui-search-area">
  4. <view class="tui-search-bar" v-if="type === 'add'">
  5. <!-- <image class="tui-searchcion" src="/static/static/assets/serach-icon.svg"></image> -->
  6. <input class="tui-search-bar-input" :value="inputUserID" placeholder="请输入用户ID" @input="handleUserIdInput"
  7. @confirm="handleGetUserProfileInfo" @blur="handleGetUserProfileInfo" />
  8. </view>
  9. <view class="tui-showID">我的 ID:{{ userID }}</view>
  10. </view>
  11. <!-- 用户列表 -->
  12. <view class="tui-person-list-container" :class="{ delete: type === 'remove' }" v-if="chooseUserList.length > 0">
  13. <view class="tui-person-to-invite" :class="{ isExist: item.isExist }" v-for="(item, index) in chooseUserList"
  14. :key="index" @click="handleChoose(item)">
  15. <view class="tui-person-choose-container">
  16. <image class="tui-normal-choose" v-if="item.isChoose" src="../../assets/icon/selected.svg"></image>
  17. <view class="tui-normal-unchoose" :class="{ isExist: item.isExist && type === 'add' }" v-else></view>
  18. </view>
  19. <view class="tui-person-profile">
  20. <image class="tui-person-profile-avatar"
  21. :src="item.avatar || 'https://sdk-web-1252463788.cos.ap-hongkong.myqcloud.com/component/TUIKit/assets/avatar_21.png'">
  22. </image>
  23. <view>
  24. <view class="tui-person-profile-nick">{{ item.nick }}</view>
  25. <view class="tui-person-profile-userID">用户ID:{{ item.userID }}</view>
  26. </view>
  27. </view>
  28. <view class="exist-tips" v-if="item.isExist && type === 'add'">(已在群聊中)</view>
  29. </view>
  30. </view>
  31. <view class="tui-confirm-btn-container">
  32. <view class="tui-confirm-btn" @tap="handleConfirmOperate">确认</view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { defineComponent, watchEffect, reactive, toRefs } from 'vue';
  38. import store from '../../TUICore/store';
  39. import { onLoad } from '@dcloudio/uni-app';
  40. export default defineComponent({
  41. name: 'Create',
  42. props: {},
  43. setup(props, context) {
  44. const TUIGroupServer = uni.$TUIKit.TUIGroupServer;
  45. const { userInfo } = store.state.timStore;
  46. const data = reactive({
  47. userID: userInfo?.userID || '',
  48. inputUserID: '',
  49. chooseUserList: [],
  50. title: '发起会话',
  51. type: '',
  52. groupID: '',
  53. });
  54. // 获取页面参数
  55. onLoad((options) => {
  56. data.title = options?.title || '发起会话';
  57. data.type = options?.type || '';
  58. data.groupID = options?.groupID || '';
  59. uni.setNavigationBarTitle({ title: options?.type === 'add' ? '添加成员' : '删除成员' });
  60. // 获取群用户列表
  61. const params = {
  62. groupID: data.groupID,
  63. count: 100,
  64. offset: 0,
  65. };
  66. uni.$TUIKit.getGroupMemberList(params).then((res) => {
  67. if (res.code === 0) {
  68. data.chooseUserList = (res.data.memberList || []).map(obj => ({
  69. ...obj,
  70. isShow: true,
  71. isExist: true,
  72. }));
  73. }
  74. });
  75. });
  76. // 输入查询 inputUserID 变动
  77. const handleUserIdInput = (e) => {
  78. data.inputUserID = e.detail.value;
  79. };
  80. // 获取用户信息
  81. const handleGetUserProfileInfo = () => {
  82. if (!data.inputUserID) return;
  83. const userIDList = [data.inputUserID];
  84. uni.showLoading({ title: '加载中' });
  85. uni.$TUIKit.getUserProfile({userIDList})
  86. .then(imRes => {
  87. uni.hideLoading();
  88. if (imRes.data.length > 0) {
  89. const userInfo = {
  90. ...imRes.data[0],
  91. isChoose: false,
  92. isShow: true,
  93. };
  94. if (data.chooseUserList.filter(obj => userInfo.userID === obj.userID).length === 0) {
  95. data.chooseUserList.push(userInfo);
  96. } else {
  97. data.chooseUserList = data.chooseUserList.map(obj => {
  98. return obj.userID === userInfo.userID ? { ...obj, isShow: true } : obj;
  99. });
  100. }
  101. } else {
  102. uni.showToast({
  103. title: '搜索用户不存在',
  104. icon: 'error'
  105. });
  106. data.inputUserID = '';
  107. }
  108. })
  109. .catch(err => {
  110. uni.hideLoading();
  111. });
  112. };
  113. // 用户选择切换
  114. const handleChoose = (item) => {
  115. if (item.isExist && data.type === 'add') return;
  116. const list = data.chooseUserList.map(obj => {
  117. if (item.userID == obj.userID) {
  118. return {
  119. ...obj,
  120. isChoose: !obj.isChoose,
  121. };
  122. } else {
  123. return obj;
  124. }
  125. });
  126. data.chooseUserList = list;
  127. };
  128. // 确认操作
  129. const handleConfirmOperate = async () => {
  130. const { type, groupID } = data;
  131. if (type === 'add') {
  132. const userIDList = data.chooseUserList.filter(obj => obj.isChoose && !obj.isExist).map(obj => obj.userID);
  133. await uni.$TUIKit.addGroupMember({
  134. groupID,
  135. userIDList,
  136. });
  137. uni.navigateBack();
  138. }
  139. if (type === 'remove') {
  140. const userIDList = data.chooseUserList.filter(obj => obj.isChoose).map(obj => obj.userID);
  141. uni.$TUIKit.deleteGroupMember({
  142. groupID,
  143. userIDList,
  144. }).catch((error) => {
  145. if(error.code == 10004)
  146. uni.showToast({
  147. title: '不能删除自己',
  148. icon: 'error'
  149. })
  150. })
  151. uni.navigateBack();
  152. }
  153. };
  154. return {
  155. ...toRefs(data),
  156. handleUserIdInput,
  157. handleGetUserProfileInfo,
  158. handleChoose,
  159. handleConfirmOperate,
  160. };
  161. }
  162. });
  163. </script>
  164. <style lang="scss" scoped>
  165. .TUI-Create-conversation-container {
  166. width: 100%;
  167. height: 100%;
  168. background-color: #F4F5F9;
  169. overflow: hidden;
  170. }
  171. .tui-search-area {
  172. position: fixed;
  173. width: 750rpx;
  174. background-color: #EBF0F6;
  175. z-index: 100;
  176. }
  177. .tui-showID {
  178. padding-left: 80rpx;
  179. line-height: 40rpx;
  180. font-size: 28rpx;
  181. color: black;
  182. height: 50rpx;
  183. padding-top: 8rpx;
  184. }
  185. .tui-search-bar {
  186. display: flex;
  187. flex-wrap: nowrap;
  188. align-items: center;
  189. margin-left: 40rpx;
  190. margin-top: 32rpx;
  191. width: 670rpx;
  192. height: 80rpx;
  193. background: #FFFFFF;
  194. border-radius: 40rpx;
  195. border-radius: 40rpx;
  196. }
  197. .tui-searchcion {
  198. display: inline-block;
  199. margin-left: 24rpx;
  200. width: 48rpx;
  201. height: 48rpx;
  202. }
  203. .tui-search-bar-input {
  204. // margin-left: 24rpx;
  205. line-height: 40rpx;
  206. font-size: 28rpx;
  207. padding: 0 36rpx;
  208. width: 100%;
  209. display: inline-block;
  210. }
  211. .tui-person-list-container {
  212. position: absolute;
  213. top: 100px;
  214. display: flex;
  215. flex-direction: column;
  216. width: 100%;
  217. /* height: 150rpx; */
  218. background-color: #FFFFFF;
  219. padding-left: 16px;
  220. align-items: center;
  221. overflow: hidden;
  222. padding-bottom: 100rpx;
  223. &.delete {
  224. top: 30px;
  225. }
  226. }
  227. .tui-person-to-invite {
  228. display: flex;
  229. flex-wrap: nowrap;
  230. width: 750rpx;
  231. height: 150rpx;
  232. background-color: #FFFFFF;
  233. padding-left: 16px;
  234. align-items: center;
  235. border-bottom: 1rpx solid #DBDBDB;
  236. .exist-tips {
  237. width: 200rpx;
  238. }
  239. }
  240. .tui-person-to-invite:last-child {
  241. border-bottom: 0rpx solid #DBDBDB;
  242. }
  243. .tui-person-choose-container {
  244. width: 22px;
  245. height: 22px;
  246. display: flex;
  247. align-items: center;
  248. margin-right: 17px;
  249. }
  250. .tui-normal-unchoose {
  251. width: 100%;
  252. height: 100%;
  253. border-radius: 50%;
  254. border: 1px solid #DDDDDD;
  255. &.isExist {
  256. width: 100%;
  257. height: 100%;
  258. background: #FFFFFF;
  259. border: 1px solid #DDDDDD;
  260. border-radius: 50%;
  261. }
  262. }
  263. .tui-normal-choose {
  264. width: 100%;
  265. height: 100%;
  266. }
  267. .tui-person-profile {
  268. width: 622rpx;
  269. display: flex;
  270. align-items: center;
  271. flex: 1;
  272. }
  273. .tui-person-profile-avatar {
  274. width: 96rpx;
  275. height: 96rpx;
  276. margin-right: 24rpx;
  277. border-radius: 10rpx;
  278. }
  279. .tui-person-profile-nick {
  280. color: #333333;
  281. line-height: 50rpx;
  282. font-size: 36rpx;
  283. margin-bottom: 4rpx;
  284. }
  285. .tui-person-profile-userID {
  286. color: #999999;
  287. line-height: 40rpx;
  288. font-size: 28rpx;
  289. }
  290. .tui-confirm-btn-container {
  291. position: fixed;
  292. display: flex;
  293. justify-content: center;
  294. align-items: center;
  295. bottom: 0rpx;
  296. width: 100%;
  297. height: 96rpx;
  298. background-color: #FFFFFF;
  299. line-height: 44rpx;
  300. font-size: 32rpx;
  301. .tui-confirm-btn {
  302. width: 670rpx;
  303. height: 42px;
  304. background: #006EFF;
  305. color: #FFFFFF;
  306. border-radius: 42rpx;
  307. line-height: 44rpx;
  308. display: flex;
  309. justify-content: center;
  310. align-items: center;
  311. }
  312. }
  313. </style>