index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/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. </view>
  56. <view class="setting_row" style="margin-bottom: 10vh">
  57. <setting-item @click="() => (showConfirm = true)" title="清空聊天记录" :border="false" />
  58. </view>
  59. <u-modal content="确定要清空聊天记录吗?" asyncClose :show="showConfirm" showCancelButton @confirm="confirmClear" @cancel="() => (showConfirm = false)"></u-modal>
  60. <u-picker :show="showMsgDestructTime" ref="uPicker" :columns="columns" @confirm="confirmMsgDestructTime" @cancel="() => (showMsgDestructTime = false)"></u-picker>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import { mapGetters } from 'vuex';
  66. import IMSDK, { MessageReceiveOptType } from 'openim-uniapp-polyfill';
  67. import CustomNavBar from '../../../components/CustomNavBar/index.vue';
  68. import MyAvatar from '../../../components/MyAvatar/index.vue';
  69. import SettingItem from '../../../components/SettingItem/index.vue';
  70. import SearchActionRow from './components/SearchActionRow.vue';
  71. export default {
  72. components: {
  73. CustomNavBar,
  74. MyAvatar,
  75. SettingItem,
  76. SearchActionRow
  77. },
  78. props: {},
  79. data() {
  80. return {
  81. switchLoading: {
  82. pin: false,
  83. opt: false,
  84. readLimit: false,
  85. msgDestruct: false
  86. },
  87. showConfirm: false,
  88. showMsgDestructTime: false,
  89. columns: [
  90. [1, 2, 3, 4, 5, 6, 7],
  91. ['天', '周', '月']
  92. ]
  93. };
  94. },
  95. computed: {
  96. ...mapGetters(['storeCurrentConversation']),
  97. parseTime() {
  98. return function (seconds) {
  99. const dayInSeconds = 86400;
  100. if (seconds <= 7 * dayInSeconds) {
  101. const days = Math.ceil(seconds / dayInSeconds);
  102. return `${days}天`;
  103. } else if (seconds <= 7 * 7 * dayInSeconds) {
  104. const weeks = Math.ceil(seconds / (7 * dayInSeconds));
  105. return `${weeks}周`;
  106. } else {
  107. const months = Math.ceil(seconds / (30 * dayInSeconds));
  108. return `${months}月`;
  109. }
  110. };
  111. }
  112. },
  113. methods: {
  114. toUserCard() {
  115. uni.navigateTo({
  116. url: `/pages_im/pages/common/userCard/index?sourceID=${this.storeCurrentConversation.userID}`
  117. });
  118. },
  119. invite2group() {
  120. const checkedMemberList = JSON.stringify([
  121. {
  122. userID: this.storeCurrentConversation.userID,
  123. faceURL: this.storeCurrentConversation.faceURL,
  124. nickname: this.storeCurrentConversation.showName
  125. }
  126. ]);
  127. uni.navigateTo({
  128. url: `/pages_im/pages/common/createGroup/index?checkedMemberList=${checkedMemberList}`
  129. });
  130. },
  131. changePin(isPinned) {
  132. this.switchLoading.pin = true;
  133. IMSDK.asyncApi(IMSDK.IMMethods.PinConversation, IMSDK.uuid(), {
  134. conversationID: this.storeCurrentConversation.conversationID,
  135. isPinned
  136. })
  137. .then(() => uni.$u.toast('操作成功'))
  138. .catch(() => uni.$u.toast('操作失败'))
  139. .finally(() => (this.switchLoading.pin = false));
  140. },
  141. changeOpt(notNomal, type) {
  142. this.switchLoading.opt = true;
  143. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationRecvMessageOpt, IMSDK.uuid(), {
  144. conversationID: this.storeCurrentConversation.conversationID,
  145. opt: notNomal ? type : MessageReceiveOptType.Nomal
  146. })
  147. .then(() => uni.$u.toast('操作成功'))
  148. .catch(() => uni.$u.toast('操作失败'))
  149. .finally(() => (this.switchLoading.opt = false));
  150. },
  151. changeReadLimit(isLimit) {
  152. this.switchLoading.readLimit = true;
  153. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationPrivateChat, IMSDK.uuid(), {
  154. conversationID: this.storeCurrentConversation.conversationID,
  155. isPrivate: isLimit
  156. })
  157. .then(() => uni.$u.toast('操作成功'))
  158. .catch(() => uni.$u.toast('操作失败'))
  159. .finally(() => (this.switchLoading.readLimit = false));
  160. },
  161. changeMsgDestruct(isLimit) {
  162. this.switchLoading.msgDestruct = true;
  163. IMSDK.asyncApi('setConversationIsMsgDestruct', IMSDK.uuid(), {
  164. conversationID: this.storeCurrentConversation.conversationID,
  165. isMsgDestruct: isLimit
  166. })
  167. .then(() => uni.$u.toast('操作成功'))
  168. .catch((err) => {
  169. console.log(err);
  170. uni.$u.toast('操作失败');
  171. })
  172. .finally(() => (this.switchLoading.msgDestruct = false));
  173. },
  174. confirmClear() {
  175. IMSDK.asyncApi(IMSDK.IMMethods.ClearConversationAndDeleteAllMsg, IMSDK.uuid(), this.storeCurrentConversation.conversationID)
  176. .then(() => {
  177. uni.$u.toast('操作成功');
  178. this.$store.commit('message/SET_HISTORY_MESSAGE_LIST', []);
  179. this.$store.commit('message/SET_PREVIEW_IMAGE_LIST', []);
  180. })
  181. .catch(() => uni.$u.toast('操作失败'))
  182. .finally(() => (this.showConfirm = false));
  183. },
  184. chooseReadLimitTime() {
  185. uni.showActionSheet({
  186. itemList: ['1天', '1小时', '5分钟', '30s'],
  187. success: ({ tapIndex }) => {
  188. let sec = 30;
  189. if (tapIndex === 0) {
  190. sec = 86400;
  191. }
  192. if (tapIndex === 1) {
  193. sec = 3600;
  194. }
  195. if (tapIndex === 2) {
  196. sec = 300;
  197. }
  198. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationBurnDuration, IMSDK.uuid(), {
  199. conversationID: this.storeCurrentConversation.conversationID,
  200. burnDuration: sec
  201. })
  202. .then((res) => {
  203. console.log(res);
  204. })
  205. .catch(() => uni.$u.toast('操作失败'));
  206. }
  207. });
  208. },
  209. chooseMsgDestructTime() {
  210. this.showMsgDestructTime = true;
  211. },
  212. confirmMsgDestructTime(e) {
  213. console.log('confirm', e.value, e.value[0], e.value[1]);
  214. let time = 86400;
  215. if (e.value[1] == '周') time *= 7;
  216. if (e.value[1] == '月') time *= 30;
  217. console.log(e.value[0] * time);
  218. IMSDK.asyncApi('setConversationMsgDestructTime', IMSDK.uuid(), {
  219. conversationID: this.storeCurrentConversation.conversationID,
  220. msgDestructTime: e.value[0] * time
  221. })
  222. .then((res) => {
  223. console.log(res);
  224. })
  225. .catch(() => uni.$u.toast('操作失败'));
  226. this.showMsgDestructTime = false;
  227. },
  228. toSetBg() {
  229. uni.$u.route('/pages_im/pages/conversation/setChatBackgroup/index');
  230. },
  231. toSetFontSize() {
  232. uni.$u.route('/pages_im/pages/conversation/setFontSize/index');
  233. }
  234. }
  235. };
  236. </script>
  237. <style lang="scss" scoped>
  238. .single_settings_container {
  239. @include colBox(false);
  240. height: 100vh;
  241. background-color: #f6f6f6;
  242. .row_wrap {
  243. flex: 1;
  244. overflow-y: auto;
  245. }
  246. .setting_row {
  247. margin: 24rpx 24rpx 0 24rpx;
  248. background: #fff;
  249. border-radius: 6px;
  250. overflow: hidden;
  251. }
  252. .info_row {
  253. display: flex;
  254. align-items: center;
  255. padding: 44rpx;
  256. .user_info {
  257. @include colBox(false);
  258. margin-right: 36rpx;
  259. .user_name {
  260. margin-top: 20rpx;
  261. color: #666;
  262. }
  263. }
  264. }
  265. }
  266. </style>