index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <script setup lang="ts">
  2. import { UserStatus } from '@/components/Im/UserStatus'
  3. import { messageType } from '@/constant/im'
  4. /* 组件 */
  5. import MessageList from './components/messageList/index.vue'
  6. import InputBox from './components/inputBox/index.vue'
  7. const { push, currentRoute } = useRouter() // 路由
  8. const { query } = useRoute() // 查询参数
  9. const { CHAT_TYPE } = messageType
  10. /* header 操作 */
  11. const drawer = ref(false) //抽屉显隐
  12. const handleDrawer = () => {
  13. drawer.value = !drawer.value
  14. }
  15. //删除好友
  16. const delTheFriend = () => {
  17. console.log(nowPickInfo.value)
  18. if (nowPickInfo.value?.id) {
  19. const targetId = nowPickInfo.value.id
  20. // EaseChatClient.deleteContact(targetId)
  21. // ElMessage({ type: 'success', center: true, message: '好友已删除~' })
  22. }
  23. }
  24. // 当前聊天对象信息
  25. const nowPickInfo = ref({
  26. id: '1',
  27. chatType: CHAT_TYPE.SINGLE,
  28. userInfo: {
  29. nickname: '好友1',
  30. userStatus: '1'
  31. },
  32. groupDetail: {
  33. name: '',
  34. affiliations_count: '',
  35. custom: ''
  36. }
  37. })
  38. //获取群组详情
  39. const groupDetail = computed(() => {
  40. return nowPickInfo.value.groupDetail
  41. })
  42. //获取其id对应的消息内容
  43. const messageData = computed(() => [
  44. {
  45. type: 'text'
  46. }
  47. ])
  48. //监听路由改变获取对应的getIdInfo
  49. const stopWatchRoute = watch(
  50. () => query,
  51. (routeVal) => {
  52. console.log('>>>>>>>>监听到路由参数变化', routeVal)
  53. if (routeVal) {
  54. // nowPickInfo.value = { ...routeVal }
  55. // loginState.value && getIdInfo(routeVal)
  56. }
  57. },
  58. {
  59. immediate: true
  60. }
  61. )
  62. //离开该路由销毁route监听
  63. onBeforeRouteLeave(() => {
  64. stopWatchRoute()
  65. })
  66. /* 消息相关 */
  67. const loadingHistoryMsg = ref(false) //是否正在加载中
  68. const isMoreHistoryMsg = ref(true) //加载文案展示为加载更多还是已无更多。
  69. const notScrollBottom = ref(false) //是否滚动置底
  70. //获取历史记录
  71. const fechHistoryMessage = (loadType) => {
  72. console.log(loadType)
  73. console.log('加载更多')
  74. }
  75. //控制消息滚动
  76. const scrollMessageList = (direction) => {
  77. console.log(direction)
  78. }
  79. //消息重新编辑
  80. const inputBox = ref(null)
  81. const reEditMessage = (msg) => (inputBox.value.textContent = msg)
  82. //消息引用
  83. const messageQuote = (msg) => inputBox.value.handleQuoteMessage(msg)
  84. </script>
  85. <template>
  86. <el-container class="app_container">
  87. <el-header class="chat_message_header">
  88. <template v-if="nowPickInfo.chatType === CHAT_TYPE.SINGLE">
  89. <div v-if="nowPickInfo.userInfo" class="chat_user_box">
  90. <span class="chat_user_name"> {{ nowPickInfo.userInfo.nickname || nowPickInfo.id }}</span>
  91. <UserStatus :userStatus="nowPickInfo.userInfo.userStatus" />
  92. </div>
  93. <div v-else> {{ nowPickInfo.id }}<span style="font-size: 10px">(非好友)</span> </div>
  94. </template>
  95. <!-- 单人展示删除拉黑 -->
  96. <span class="more" v-if="nowPickInfo.chatType === CHAT_TYPE.SINGLE">
  97. <el-dropdown placement="bottom-end" trigger="click">
  98. <svg
  99. width="18"
  100. height="4"
  101. viewBox="0 0 18 4"
  102. fill="none"
  103. xmlns="http://www.w3.org/2000/svg"
  104. >
  105. <circle cx="2" cy="2" r="2" fill="#333333" />
  106. <circle cx="9" cy="2" r="2" fill="#333333" />
  107. <circle cx="16" cy="2" r="2" fill="#333333" />
  108. </svg>
  109. <template #dropdown>
  110. <el-dropdown-menu>
  111. <el-dropdown-item @click="delTheFriend"> 删除好友 </el-dropdown-item>
  112. <!-- <el-dropdown-item @click="addFriendToBlackList">
  113. 加入黑名单
  114. </el-dropdown-item> -->
  115. </el-dropdown-menu>
  116. </template>
  117. </el-dropdown>
  118. </span>
  119. </el-header>
  120. <el-main class="chat_message_main">
  121. <el-scrollbar class="main_container" ref="messageContainer">
  122. <div class="innerRef">
  123. <div v-show="isMoreHistoryMsg" class="chat_message_tips">
  124. <div
  125. v-show="messageData?.length && messageData[0].type !== 'inform'"
  126. class="load_more_msg"
  127. >
  128. <el-link
  129. v-show="!loadingHistoryMsg"
  130. :disabled="!isMoreHistoryMsg"
  131. :underline="false"
  132. @click="fechHistoryMessage('loadFirst')"
  133. >
  134. 加载更多
  135. </el-link>
  136. <el-link v-show="loadingHistoryMsg" disabled>消息加载中...</el-link>
  137. </div>
  138. </div>
  139. <MessageList
  140. :nowPickInfo="nowPickInfo"
  141. :messageData="messageData"
  142. @scroll-message-list="scrollMessageList"
  143. @re-edit-message="reEditMessage"
  144. @message-quote="messageQuote"
  145. />
  146. </div>
  147. </el-scrollbar>
  148. </el-main>
  149. <el-footer class="chat_message_input_bar">
  150. <InputBox ref="inputBox" :nowPickInfo="nowPickInfo" />
  151. </el-footer>
  152. </el-container>
  153. </template>
  154. <style scoped lang="scss">
  155. @import './index.scss';
  156. </style>