index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view class="single_settings_container">
  3. <custom-nav-bar title="好友设置" />
  4. <view class="row_wrap">
  5. <view class="setting_row info_row">
  6. <view @click="toUserCard" class="user_info">
  7. <my-avatar :src="storeCurrentConversation.faceURL" :desc="storeCurrentConversation.showName" size="46" />
  8. </view>
  9. <view @click="invite2group" class="action">
  10. <image style="width: 46px; height: 46px" src="../../../static/images/single_setting_add.png" alt="" />
  11. </view>
  12. </view>
  13. <view class="setting_row">
  14. <search-action-row />
  15. </view>
  16. <view class="setting_row">
  17. <setting-item title="置顶联系人" :loading="switchLoading.pin" @switch="changePin" :switchValue="storeCurrentConversation.isPinned" is_switch :border="false" />
  18. <!-- <setting-item
  19. title="消息免打扰"
  20. :loading="switchLoading.opt"
  21. @switch="changeOpt($event, 2)"
  22. :switchValue="storeCurrentConversation.recvMsgOpt === 2"
  23. is_switch
  24. :border="false"
  25. /> -->
  26. </view>
  27. <view class="setting_row">
  28. <!-- <setting-item
  29. title="阅后即焚"
  30. :loading="switchLoading.readLimit"
  31. @switch="changeReadLimit"
  32. :switchValue="storeCurrentConversation.isPrivateChat"
  33. is_switch
  34. :border="false"
  35. />
  36. <setting-item v-if="storeCurrentConversation.isPrivateChat" title="时间设置" @click="chooseReadLimitTime" :border="false">
  37. <text style="color: #999">{{ storeCurrentConversation.burnDuration || 30 }}s</text>
  38. </setting-item>
  39. <setting-item
  40. title="定期销毁消息记录"
  41. :loading="switchLoading.readLimit"
  42. @switch="changeMsgDestruct"
  43. :switchValue="storeCurrentConversation.isMsgDestruct"
  44. is_switch
  45. :border="false"
  46. /> -->
  47. <setting-item v-if="storeCurrentConversation.isMsgDestruct" title="定期销毁时间设置" @click="chooseMsgDestructTime" :border="false">
  48. <text style="color: #999">{{ parseTime(storeCurrentConversation.msgDestructTime) }}</text>
  49. </setting-item>
  50. <!-- <setting-item title="好友消息设置" :border="false" /> -->
  51. </view>
  52. <view class="setting_row">
  53. <setting-item @click="toSetBg" title="设置聊天背景" :border="false" />
  54. <setting-item @click="toSetFontSize" title="字体大小" :border="false" />
  55. <setting-item @click="toFeedBack" title="举报" :border="false" />
  56. </view>
  57. <view class="setting_row" style="margin-bottom: 10vh">
  58. <setting-item @click="() => (showConfirm = true)" title="清空聊天记录" :border="false" />
  59. </view>
  60. <u-modal content="确定要清空聊天记录吗?" asyncClose :show="showConfirm" showCancelButton @confirm="confirmClear" @cancel="() => (showConfirm = false)"></u-modal>
  61. <u-picker :show="showMsgDestructTime" ref="uPicker" :columns="columns" @confirm="confirmMsgDestructTime" @cancel="() => (showMsgDestructTime = false)"></u-picker>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import { mapGetters } from 'vuex';
  67. import IMSDK, { MessageReceiveOptType } from 'openim-uniapp-polyfill';
  68. import CustomNavBar from '../../../components/CustomNavBar/index.vue';
  69. import MyAvatar from '../../../components/MyAvatar/index.vue';
  70. import SettingItem from '../../../components/SettingItem/index.vue';
  71. import SearchActionRow from './components/SearchActionRow.vue';
  72. export default {
  73. components: {
  74. CustomNavBar,
  75. MyAvatar,
  76. SettingItem,
  77. SearchActionRow
  78. },
  79. props: {},
  80. data() {
  81. return {
  82. switchLoading: {
  83. pin: false,
  84. opt: false,
  85. readLimit: false,
  86. msgDestruct: false
  87. },
  88. showConfirm: false,
  89. showMsgDestructTime: false,
  90. columns: [
  91. [1, 2, 3, 4, 5, 6, 7],
  92. ['天', '周', '月']
  93. ]
  94. };
  95. },
  96. computed: {
  97. ...mapGetters(['storeCurrentConversation']),
  98. parseTime() {
  99. return function (seconds) {
  100. const dayInSeconds = 86400;
  101. if (seconds <= 7 * dayInSeconds) {
  102. const days = Math.ceil(seconds / dayInSeconds);
  103. return `${days}天`;
  104. } else if (seconds <= 7 * 7 * dayInSeconds) {
  105. const weeks = Math.ceil(seconds / (7 * dayInSeconds));
  106. return `${weeks}周`;
  107. } else {
  108. const months = Math.ceil(seconds / (30 * dayInSeconds));
  109. return `${months}月`;
  110. }
  111. };
  112. }
  113. },
  114. methods: {
  115. toUserCard() {
  116. uni.navigateTo({
  117. url: `/pages_im/pages/common/userCard/index?sourceID=${this.storeCurrentConversation.userID}&friend=true`
  118. });
  119. },
  120. invite2group() {
  121. const checkedMemberList = JSON.stringify([
  122. {
  123. userID: this.storeCurrentConversation.userID,
  124. faceURL: this.storeCurrentConversation.faceURL,
  125. nickname: this.storeCurrentConversation.showName
  126. }
  127. ]);
  128. uni.navigateTo({
  129. url: `/pages_im/pages/common/createGroup/index?checkedMemberList=${checkedMemberList}`
  130. });
  131. },
  132. changePin(isPinned) {
  133. this.switchLoading.pin = true;
  134. IMSDK.asyncApi(IMSDK.IMMethods.PinConversation, IMSDK.uuid(), {
  135. conversationID: this.storeCurrentConversation.conversationID,
  136. isPinned
  137. })
  138. .then(() => uni.$u.toast('操作成功'))
  139. .catch(() => uni.$u.toast('操作失败'))
  140. .finally(() => (this.switchLoading.pin = false));
  141. },
  142. changeOpt(notNomal, type) {
  143. this.switchLoading.opt = true;
  144. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationRecvMessageOpt, IMSDK.uuid(), {
  145. conversationID: this.storeCurrentConversation.conversationID,
  146. opt: notNomal ? type : MessageReceiveOptType.Nomal
  147. })
  148. .then(() => uni.$u.toast('操作成功'))
  149. .catch(() => uni.$u.toast('操作失败'))
  150. .finally(() => (this.switchLoading.opt = false));
  151. },
  152. changeReadLimit(isLimit) {
  153. this.switchLoading.readLimit = true;
  154. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationPrivateChat, IMSDK.uuid(), {
  155. conversationID: this.storeCurrentConversation.conversationID,
  156. isPrivate: isLimit
  157. })
  158. .then(() => uni.$u.toast('操作成功'))
  159. .catch(() => uni.$u.toast('操作失败'))
  160. .finally(() => (this.switchLoading.readLimit = false));
  161. },
  162. changeMsgDestruct(isLimit) {
  163. this.switchLoading.msgDestruct = true;
  164. IMSDK.asyncApi('setConversationIsMsgDestruct', IMSDK.uuid(), {
  165. conversationID: this.storeCurrentConversation.conversationID,
  166. isMsgDestruct: isLimit
  167. })
  168. .then(() => uni.$u.toast('操作成功'))
  169. .catch((err) => {
  170. console.log(err);
  171. uni.$u.toast('操作失败');
  172. })
  173. .finally(() => (this.switchLoading.msgDestruct = false));
  174. },
  175. confirmClear() {
  176. IMSDK.asyncApi(IMSDK.IMMethods.ClearConversationAndDeleteAllMsg, IMSDK.uuid(), this.storeCurrentConversation.conversationID)
  177. .then(() => {
  178. uni.$u.toast('操作成功');
  179. this.$store.commit('message/SET_HISTORY_MESSAGE_LIST', []);
  180. this.$store.commit('message/SET_PREVIEW_IMAGE_LIST', []);
  181. })
  182. .catch(() => uni.$u.toast('操作失败'))
  183. .finally(() => (this.showConfirm = false));
  184. },
  185. chooseReadLimitTime() {
  186. uni.showActionSheet({
  187. itemList: ['1天', '1小时', '5分钟', '30s'],
  188. success: ({ tapIndex }) => {
  189. let sec = 30;
  190. if (tapIndex === 0) {
  191. sec = 86400;
  192. }
  193. if (tapIndex === 1) {
  194. sec = 3600;
  195. }
  196. if (tapIndex === 2) {
  197. sec = 300;
  198. }
  199. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationBurnDuration, IMSDK.uuid(), {
  200. conversationID: this.storeCurrentConversation.conversationID,
  201. burnDuration: sec
  202. })
  203. .then((res) => {
  204. console.log(res);
  205. })
  206. .catch(() => uni.$u.toast('操作失败'));
  207. }
  208. });
  209. },
  210. chooseMsgDestructTime() {
  211. this.showMsgDestructTime = true;
  212. },
  213. confirmMsgDestructTime(e) {
  214. console.log('confirm', e.value, e.value[0], e.value[1]);
  215. let time = 86400;
  216. if (e.value[1] == '周') time *= 7;
  217. if (e.value[1] == '月') time *= 30;
  218. console.log(e.value[0] * time);
  219. IMSDK.asyncApi('setConversationMsgDestructTime', IMSDK.uuid(), {
  220. conversationID: this.storeCurrentConversation.conversationID,
  221. msgDestructTime: e.value[0] * time
  222. }).then((res) => {
  223. console.log(res);
  224. }).catch(() => uni.$u.toast('操作失败'));
  225. this.showMsgDestructTime = false;
  226. },
  227. toSetBg() {
  228. uni.$u.route('/pages_im/pages/conversation/setChatBackgroup/index');
  229. },
  230. toSetFontSize() {
  231. uni.$u.route('/pages_im/pages/conversation/setFontSize/index');
  232. },
  233. toFeedBack(){
  234. uni.$u.route('/pages/user/feedback?isFromIm=1');
  235. }
  236. }
  237. };
  238. </script>
  239. <style lang="scss" scoped>
  240. .single_settings_container {
  241. @include colBox(false);
  242. height: 100vh;
  243. background-color: #f6f6f6;
  244. .row_wrap {
  245. flex: 1;
  246. overflow-y: auto;
  247. }
  248. .setting_row {
  249. margin: 24rpx 24rpx 0 24rpx;
  250. background: #fff;
  251. border-radius: 6px;
  252. overflow: hidden;
  253. }
  254. .info_row {
  255. display: flex;
  256. align-items: center;
  257. padding: 44rpx;
  258. .user_info {
  259. @include colBox(false);
  260. margin-right: 36rpx;
  261. .user_name {
  262. margin-top: 20rpx;
  263. color: #666;
  264. }
  265. }
  266. }
  267. }
  268. </style>