index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="page_container">
  3. <custom-nav-bar :title="getTitle">
  4. <view class="nav_right_action" slot="more">
  5. <text v-show="!updateLoading" @click="comfirmUpdate">保存</text>
  6. <u-loading-icon v-show="updateLoading" />
  7. </view>
  8. </custom-nav-bar>
  9. <view class="content_row">
  10. <u-input
  11. v-model="content"
  12. disabledColor="transparent"
  13. maxlength="16"
  14. placeholder="请输入内容"
  15. clearable
  16. >
  17. </u-input>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import IMSDK from "openim-uniapp-polyfill";
  23. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  24. import MyAvatar from "../../../components/MyAvatar/index.vue";
  25. export default {
  26. components: {
  27. CustomNavBar,
  28. MyAvatar,
  29. },
  30. data() {
  31. return {
  32. sourceInfo: {},
  33. content: "",
  34. updateLoading: false,
  35. };
  36. },
  37. computed: {
  38. isGroup() {
  39. return this.sourceInfo.nickname === undefined;
  40. },
  41. isGroupMember() {
  42. return this.sourceInfo.roleLevel !== undefined;
  43. },
  44. getTitle() {
  45. return this.isGroup ? "修改群聊名称" : "我在本群的昵称";
  46. },
  47. getSubTitle() {
  48. return this.isGroup
  49. ? "修改群名称后,将在群内通知其他成员"
  50. : "昵称修改后,只会在此群内显示,群内成员都可以看见。";
  51. },
  52. },
  53. onLoad(options) {
  54. const { sourceInfo } = options;
  55. this.sourceInfo = JSON.parse(sourceInfo);
  56. this.content = this.sourceInfo.nickname ?? this.sourceInfo.groupName;
  57. },
  58. methods: {
  59. comfirmUpdate() {
  60. this.updateLoading = true;
  61. let func;
  62. if (!this.isGroup) {
  63. func = IMSDK.asyncApi(
  64. IMSDK.IMMethods.SetGroupMemberInfo,
  65. IMSDK.uuid(),
  66. {
  67. groupID: this.sourceInfo.groupID,
  68. userID: this.sourceInfo.userID,
  69. nickname: this.content,
  70. },
  71. );
  72. } else {
  73. func = IMSDK.asyncApi(IMSDK.IMMethods.SetGroupInfo, IMSDK.uuid(), {
  74. groupID: this.sourceInfo.groupID,
  75. groupName: this.content,
  76. });
  77. }
  78. func
  79. .then(() => {
  80. uni.$u.toast("修改成功");
  81. setTimeout(() => uni.navigateBack(), 250);
  82. })
  83. .catch(() => uni.$u.toast("修改失败"))
  84. .finally(() => (this.updateLoading = false));
  85. },
  86. },
  87. };
  88. </script>
  89. <style lang="scss" scoped>
  90. .page_container {
  91. @include colBox(false);
  92. height: 100vh;
  93. .nav_right_action {
  94. margin-right: 36rpx;
  95. }
  96. .content_row {
  97. margin-top: 96rpx;
  98. margin: 72rpx 44rpx 0;
  99. .u-input {
  100. background-color: #e8eaef;
  101. }
  102. .u-button {
  103. height: 60rpx;
  104. }
  105. }
  106. }
  107. </style>