index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="request_join_container">
  3. <custom-nav-bar :title="isGroup ? '群聊验证' : '好友验证'">
  4. <view class="top_right_btn" slot="more">
  5. <u-button @click="sendRequest" text="发送" type="primary"></u-button>
  6. </view>
  7. </custom-nav-bar>
  8. <text class="title">{{ `发送${isGroup ? "入群" : "好友"}申请` }}</text>
  9. <view class="input_container">
  10. <u--textarea
  11. height="120"
  12. v-model="reason"
  13. border="none"
  14. placeholder="请输入内容"
  15. maxlength="20"
  16. count
  17. >
  18. </u--textarea>
  19. </view>
  20. <SelectProject @agreeFun="agreeFun" :selectProjectShow="selectProjectShow" :application="application" />
  21. </view>
  22. </template>
  23. <script>
  24. import SelectProject from "@/pages_im/components/SelectProject.vue"
  25. import IMSDK, { GroupJoinSource } from "openim-uniapp-polyfill";
  26. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  27. import { navigateToDesignatedConversation } from "../../../util/imCommon";
  28. export default {
  29. components: {
  30. CustomNavBar,
  31. SelectProject,
  32. },
  33. data() {
  34. return {
  35. reason: "",
  36. sourceID: "",
  37. isGroup: false,
  38. isScan: false,
  39. notNeedVerification: false,
  40. sessionType: 0,
  41. selectProjectShow: false,
  42. application:{fromUserID:null}
  43. };
  44. },
  45. onLoad(options) {
  46. const { isGroup, sourceID, isScan, notNeedVerification, sessionType } =
  47. options;
  48. this.isGroup = JSON.parse(isGroup);
  49. this.isScan = JSON.parse(isScan);
  50. this.sourceID = sourceID;
  51. this.application.fromUserID = sourceID
  52. this.notNeedVerification = JSON.parse(notNeedVerification);
  53. this.sessionType = sessionType ?? 0;
  54. },
  55. methods: {
  56. agreeFun(){
  57. this.selectProjectShow = false;
  58. this.sendRequestFun()
  59. },
  60. sendRequest(){
  61. const companyUserId = uni.getStorageSync('companyUserId')
  62. if (companyUserId) {
  63. this.selectProjectShow = true
  64. return
  65. }
  66. this.sendRequestFun()
  67. },
  68. sendRequestFun() {
  69. let func;
  70. if (this.isGroup) {
  71. const joinSource = this.isScan
  72. ? GroupJoinSource.QrCode
  73. : GroupJoinSource.Search;
  74. func = IMSDK.asyncApi(IMSDK.IMMethods.JoinGroup, IMSDK.uuid(), {
  75. groupID: this.sourceID,
  76. reqMsg: this.reason,
  77. joinSource,
  78. });
  79. } else {
  80. func = IMSDK.asyncApi(IMSDK.IMMethods.AddFriend, IMSDK.uuid(), {
  81. toUserID: this.sourceID,
  82. reqMsg: this.reason,
  83. });
  84. }
  85. func
  86. .then(() => {
  87. uni.$u.toast(this.notNeedVerification ? "你已加入该群" : "发送成功");
  88. setTimeout(() => {
  89. if (this.notNeedVerification) {
  90. navigateToDesignatedConversation(
  91. this.sourceID,
  92. Number(this.sessionType),
  93. ).catch(() => this.showToast("获取会话信息失败"));
  94. } else {
  95. uni.navigateBack();
  96. }
  97. }, 1000);
  98. })
  99. .catch((err) => {
  100. console.log(err);
  101. uni.$u.toast("发送失败");
  102. });
  103. },
  104. showToast(message) {
  105. this.$refs.uToast.show({
  106. message,
  107. });
  108. },
  109. },
  110. };
  111. </script>
  112. <style lang="scss">
  113. .request_join_container {
  114. @include colBox(false);
  115. height: 100vh;
  116. background-color: #f6f6f6;
  117. .top_right_btn {
  118. margin-right: 44rpx;
  119. .u-button {
  120. height: 48rpx;
  121. }
  122. }
  123. .title {
  124. font-size: 28rpx;
  125. color: #999;
  126. margin: 24rpx 44rpx;
  127. }
  128. .input_container {
  129. /deep/.u-textarea {
  130. padding: 24rpx 44rpx !important;
  131. }
  132. }
  133. }
  134. </style>