index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. </view>
  21. </template>
  22. <script>
  23. import IMSDK, { GroupJoinSource } from "openim-uniapp-polyfill";
  24. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  25. import { navigateToDesignatedConversation } from "../../../util/imCommon";
  26. export default {
  27. components: {
  28. CustomNavBar,
  29. },
  30. data() {
  31. return {
  32. reason: "",
  33. sourceID: "",
  34. isGroup: false,
  35. isScan: false,
  36. notNeedVerification: false,
  37. sessionType: 0,
  38. };
  39. },
  40. onLoad(options) {
  41. const { isGroup, sourceID, isScan, notNeedVerification, sessionType } =
  42. options;
  43. this.isGroup = JSON.parse(isGroup);
  44. this.isScan = JSON.parse(isScan);
  45. this.sourceID = sourceID;
  46. this.notNeedVerification = JSON.parse(notNeedVerification);
  47. this.sessionType = sessionType ?? 0;
  48. },
  49. methods: {
  50. sendRequest() {
  51. let func;
  52. if (this.isGroup) {
  53. const joinSource = this.isScan
  54. ? GroupJoinSource.QrCode
  55. : GroupJoinSource.Search;
  56. func = IMSDK.asyncApi(IMSDK.IMMethods.JoinGroup, IMSDK.uuid(), {
  57. groupID: this.sourceID,
  58. reqMsg: this.reason,
  59. joinSource,
  60. });
  61. } else {
  62. func = IMSDK.asyncApi(IMSDK.IMMethods.AddFriend, IMSDK.uuid(), {
  63. toUserID: this.sourceID,
  64. reqMsg: this.reason,
  65. });
  66. }
  67. func
  68. .then(() => {
  69. uni.$u.toast(this.notNeedVerification ? "你已加入该群" : "发送成功");
  70. setTimeout(() => {
  71. if (this.notNeedVerification) {
  72. navigateToDesignatedConversation(
  73. this.sourceID,
  74. Number(this.sessionType),
  75. ).catch(() => this.showToast("获取会话信息失败"));
  76. } else {
  77. uni.navigateBack();
  78. }
  79. }, 1000);
  80. })
  81. .catch((err) => {
  82. console.log(err);
  83. uni.$u.toast("发送失败");
  84. });
  85. },
  86. showToast(message) {
  87. this.$refs.uToast.show({
  88. message,
  89. });
  90. },
  91. },
  92. };
  93. </script>
  94. <style lang="scss">
  95. .request_join_container {
  96. @include colBox(false);
  97. height: 100vh;
  98. background-color: #f6f6f6;
  99. .top_right_btn {
  100. margin-right: 44rpx;
  101. .u-button {
  102. height: 48rpx;
  103. }
  104. }
  105. .title {
  106. font-size: 28rpx;
  107. color: #999;
  108. margin: 24rpx 44rpx;
  109. }
  110. .input_container {
  111. /deep/.u-textarea {
  112. padding: 24rpx 44rpx !important;
  113. }
  114. }
  115. }
  116. </style>