index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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"
  8. size="46" />
  9. </view>
  10. <image @click="invite2group" style="width: 46px; height: 46px"
  11. src="../../../static/images/single_setting_add.png" alt="" />
  12. </view>
  13. <!-- <view class="setting_row">
  14. <search-action-row />
  15. </view> -->
  16. <view class="setting_row">
  17. <!-- <setting-item
  18. title="消息免打扰"
  19. :loading="switchLoading.opt"
  20. @switch="changeOpt($event, 2)"
  21. :switchValue="storeCurrentConversation.recvMsgOpt === 2"
  22. is_switch
  23. /> -->
  24. <setting-item @click="handleHistory" title="历史记录"></setting-item>
  25. <setting-item title="置顶联系人" :loading="switchLoading.pin" @switch="changePin"
  26. :switchValue="storeCurrentConversation.isPinned" is_switch />
  27. <setting-item @click="toSetBg" title="设置聊天背景" />
  28. <setting-item @click="toSetFontSize" title="字体大小" />
  29. <!-- <setting-item @click="toFeedBack" title="举报" :border="false" /> -->
  30. </view>
  31. <view class="setting_row">
  32. <!-- <setting-item
  33. title="阅后即焚"
  34. :loading="switchLoading.readLimit"
  35. @switch="changeReadLimit"
  36. :switchValue="storeCurrentConversation.isPrivateChat"
  37. is_switch
  38. :border="false"
  39. />
  40. <setting-item v-if="storeCurrentConversation.isPrivateChat" title="时间设置" @click="chooseReadLimitTime" :border="false">
  41. <text style="color: #999">{{ storeCurrentConversation.burnDuration || 30 }}s</text>
  42. </setting-item>
  43. <setting-item
  44. title="定期销毁消息记录"
  45. :loading="switchLoading.readLimit"
  46. @switch="changeMsgDestruct"
  47. :switchValue="storeCurrentConversation.isMsgDestruct"
  48. is_switch
  49. :border="false"
  50. /> -->
  51. <setting-item v-if="storeCurrentConversation.isMsgDestruct" title="定期销毁时间设置"
  52. @click="chooseMsgDestructTime" :border="false">
  53. <text style="color: #999">{{ parseTime(storeCurrentConversation.msgDestructTime) }}</text>
  54. </setting-item>
  55. <!-- <setting-item title="好友消息设置" :border="false" /> -->
  56. </view>
  57. <view class="group_row" @click="() => (showConfirm = true)"> 清空聊天记录 </view>
  58. <u-modal content="确定要清空聊天记录吗?" asyncClose :show="showConfirm" showCancelButton @confirm="confirmClear"
  59. @cancel="() => (showConfirm = false)"></u-modal>
  60. <u-picker :show="showMsgDestructTime" ref="uPicker" :columns="columns" @confirm="confirmMsgDestructTime"
  61. @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. handleHistory() {
  116. uni.navigateTo({
  117. url: '/pages_im/pages/conversation/searchMessage/index'
  118. });
  119. },
  120. toUserCard() {
  121. uni.navigateTo({
  122. url: `/pages_im/pages/common/userCard/index?sourceID=${this.storeCurrentConversation.userID}`
  123. });
  124. },
  125. invite2group() {
  126. const checkedMemberList = JSON.stringify([
  127. {
  128. userID: this.storeCurrentConversation.userID,
  129. faceURL: this.storeCurrentConversation.faceURL,
  130. nickname: this.storeCurrentConversation.showName
  131. }
  132. ]);
  133. uni.navigateTo({
  134. url: `/pages_im/pages/common/createGroup/index?checkedMemberList=${checkedMemberList}`
  135. });
  136. },
  137. changePin(isPinned) {
  138. this.switchLoading.pin = true;
  139. IMSDK.asyncApi(IMSDK.IMMethods.PinConversation, IMSDK.uuid(), {
  140. conversationID: this.storeCurrentConversation.conversationID,
  141. isPinned
  142. })
  143. .then(() => uni.$u.toast('操作成功'))
  144. .catch(() => uni.$u.toast('操作失败'))
  145. .finally(() => (this.switchLoading.pin = false));
  146. },
  147. changeOpt(notNomal, type) {
  148. this.switchLoading.opt = true;
  149. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationRecvMessageOpt, IMSDK.uuid(), {
  150. conversationID: this.storeCurrentConversation.conversationID,
  151. opt: notNomal ? type : MessageReceiveOptType.Nomal
  152. })
  153. .then(() => uni.$u.toast('操作成功'))
  154. .catch(() => uni.$u.toast('操作失败'))
  155. .finally(() => (this.switchLoading.opt = false));
  156. },
  157. changeReadLimit(isLimit) {
  158. this.switchLoading.readLimit = true;
  159. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationPrivateChat, IMSDK.uuid(), {
  160. conversationID: this.storeCurrentConversation.conversationID,
  161. isPrivate: isLimit
  162. })
  163. .then(() => uni.$u.toast('操作成功'))
  164. .catch(() => uni.$u.toast('操作失败'))
  165. .finally(() => (this.switchLoading.readLimit = false));
  166. },
  167. changeMsgDestruct(isLimit) {
  168. this.switchLoading.msgDestruct = true;
  169. IMSDK.asyncApi('setConversationIsMsgDestruct', IMSDK.uuid(), {
  170. conversationID: this.storeCurrentConversation.conversationID,
  171. isMsgDestruct: isLimit
  172. })
  173. .then(() => uni.$u.toast('操作成功'))
  174. .catch((err) => {
  175. console.log(err);
  176. uni.$u.toast('操作失败');
  177. })
  178. .finally(() => (this.switchLoading.msgDestruct = false));
  179. },
  180. confirmClear() {
  181. IMSDK.asyncApi(IMSDK.IMMethods.ClearConversationAndDeleteAllMsg, IMSDK.uuid(), this.storeCurrentConversation.conversationID)
  182. .then(() => {
  183. uni.$u.toast('操作成功');
  184. this.$store.commit('message/SET_HISTORY_MESSAGE_LIST', []);
  185. this.$store.commit('message/SET_PREVIEW_IMAGE_LIST', []);
  186. })
  187. .catch(() => uni.$u.toast('操作失败'))
  188. .finally(() => (this.showConfirm = false));
  189. },
  190. chooseReadLimitTime() {
  191. uni.showActionSheet({
  192. itemList: ['1天', '1小时', '5分钟', '30s'],
  193. success: ({ tapIndex }) => {
  194. let sec = 30;
  195. if (tapIndex === 0) {
  196. sec = 86400;
  197. }
  198. if (tapIndex === 1) {
  199. sec = 3600;
  200. }
  201. if (tapIndex === 2) {
  202. sec = 300;
  203. }
  204. IMSDK.asyncApi(IMSDK.IMMethods.SetConversationBurnDuration, IMSDK.uuid(), {
  205. conversationID: this.storeCurrentConversation.conversationID,
  206. burnDuration: sec
  207. })
  208. .then((res) => {
  209. console.log(res);
  210. })
  211. .catch(() => uni.$u.toast('操作失败'));
  212. }
  213. });
  214. },
  215. chooseMsgDestructTime() {
  216. this.showMsgDestructTime = true;
  217. },
  218. confirmMsgDestructTime(e) {
  219. console.log('confirm', e.value, e.value[0], e.value[1]);
  220. let time = 86400;
  221. if (e.value[1] == '周') time *= 7;
  222. if (e.value[1] == '月') time *= 30;
  223. console.log(e.value[0] * time);
  224. IMSDK.asyncApi('setConversationMsgDestructTime', IMSDK.uuid(), {
  225. conversationID: this.storeCurrentConversation.conversationID,
  226. msgDestructTime: e.value[0] * time
  227. }).then((res) => {
  228. console.log(res);
  229. }).catch(() => uni.$u.toast('操作失败'));
  230. this.showMsgDestructTime = false;
  231. },
  232. toSetBg() {
  233. uni.$u.route('/pages_im/pages/conversation/setChatBackgroup/index');
  234. },
  235. toSetFontSize() {
  236. uni.$u.route('/pages_im/pages/conversation/setFontSize/index');
  237. },
  238. toFeedBack() {
  239. uni.$u.route('/pages/user/feedback?isFromIm=1');
  240. }
  241. }
  242. };
  243. </script>
  244. <style lang="scss" scoped>
  245. .single_settings_container {
  246. @include colBox(false);
  247. height: 100vh;
  248. background-color: #f6f6f6;
  249. .row_wrap {
  250. flex: 1;
  251. overflow-y: auto;
  252. }
  253. .setting_row {
  254. margin: 24rpx 24rpx 0 24rpx;
  255. background: #fff;
  256. border-radius: 6px;
  257. overflow: hidden;
  258. }
  259. .group_row {
  260. height: 44px;
  261. line-height: 44px;
  262. background-color: #fff;
  263. border-radius: 6px;
  264. text-align: center;
  265. margin: 24rpx;
  266. color: #D32414
  267. }
  268. .info_row {
  269. display: flex;
  270. align-items: center;
  271. padding: 24rpx;
  272. .user_info {
  273. @include colBox(false);
  274. margin-right: 36rpx;
  275. .user_name {
  276. margin-top: 20rpx;
  277. color: #666;
  278. }
  279. }
  280. }
  281. }
  282. </style>