ChatSetting.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view class='cu-list menu margin-top'>
  3. <!--只有在聊天列表的chat 才有置顶功能-->
  4. <view class='cu-item' v-if='chat'>
  5. <view class='content'>
  6. <text class='cuIcon-messagefill text-grey'></text>
  7. <text class='text-black'>聊天置顶</text>
  8. </view>
  9. <view class='action'>
  10. <switch @change='chatTopChange' :class="isTop?'checked':''" :checked='isTop?true:false'></switch>
  11. </view>
  12. </view>
  13. <view class='cu-item'>
  14. <view class='content'>
  15. <text class='cuIcon-settings text-grey'></text>
  16. <text class='text-black'>消息免打扰</text>
  17. </view>
  18. <view class='action'>
  19. <switch @change='messageTipsChange' :class="isTips?'checked':''" :checked='isTips?true:false'></switch>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script lang='ts' setup>
  25. import {computed, ref} from 'vue'
  26. import {storeToRefs} from 'pinia'
  27. import {useImmunityStore} from '@/store/immunityStore'
  28. import {useChatStore} from '@/store/chatStore'
  29. import {useUserStore} from '@/store/userStore'
  30. import ImmunityApi from '@/api/ImmunityApi'
  31. interface IProps{
  32. chatId:string
  33. }
  34. const props = defineProps<IProps>();
  35. const isTop = ref(false)
  36. const chatStore = useChatStore()
  37. const immunityStore = useImmunityStore()
  38. const { immunityList } = storeToRefs(immunityStore)
  39. const isTips = computed(() => {
  40. return immunityList.value.indexOf(props.chatId) > -1
  41. })
  42. const chat = chatStore.getChat(props.chatId)
  43. if (chat) {
  44. isTop.value = chat.top ?? false
  45. }
  46. const chatTopChange = () => {
  47. if(chat){
  48. isTop.value = !isTop.value
  49. if (isTop.value) {
  50. chatStore.topChat(props.chatId)
  51. } else {
  52. chatStore.cancelTop(props.chatId)
  53. }
  54. }
  55. }
  56. const messageTipsChange = (e: TouchEvent) => {
  57. const userId = useUserStore().getUser()?.id
  58. if (userId) {
  59. // @ts-ignore
  60. if (e.detail.value) {
  61. ImmunityApi.save(userId, props.chatId).then(() => {
  62. immunityStore.loadData()
  63. })
  64. } else {
  65. ImmunityApi.delete(userId, props.chatId).then(() => {
  66. immunityStore.loadData()
  67. })
  68. }
  69. }
  70. }
  71. </script>
  72. <style scoped>
  73. </style>