index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <div class="w-full">
  3. <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  4. <van-sticky :offset-top="50">
  5. <div
  6. class="w-full text-xl font-semibold px-16 h-48 flex justify-start items-center bg-white"
  7. >
  8. <span
  9. @click="showPopover = true"
  10. v-if="showPopover"
  11. class="iconfont icon-plus text-[#FF9300]"
  12. style="font-size: 24px"
  13. ></span>
  14. <span v-else class="iconfont icon-plus text-black" style="font-size: 24px"></span>
  15. <van-popover
  16. v-model:show="showPopover"
  17. placement="bottom"
  18. theme="dark"
  19. offset="[5,20]"
  20. :actions="actionsList"
  21. @select="onSelect"
  22. >
  23. <template #reference>
  24. <span :class="`${showPopover ? 'text-[#FF9300]' : 'text-black-3'}`">添加</span>
  25. </template>
  26. </van-popover>
  27. </div>
  28. </van-sticky>
  29. <div
  30. @click="onChatPage('/profile/system-message', {})"
  31. class="w-full relative h-82 flex justify-start items-center px-16"
  32. >
  33. <van-badge v-if="messagesNumber > 0" v-bind="messageNumber(messagesNumber)" max="99">
  34. <div
  35. class="w-48 h-48 bg-[#0052D9] rounded-full overflow-hidden flex justify-center items-center"
  36. >
  37. <img
  38. class="w-24 h-24 shrink-0 object-cover"
  39. src="~/assets/img/chat/remind.svg"
  40. alt=""
  41. />
  42. </div>
  43. </van-badge>
  44. <div
  45. v-else
  46. class="w-48 h-48 bg-[#0052D9] rounded-full overflow-hidden flex justify-center items-center"
  47. >
  48. <img class="w-24 h-24 shrink-0 object-cover" src="~/assets/img/chat/user.svg" alt="" />
  49. </div>
  50. <div class="h-48 w-245 shrink-0 ml-12 flex flex-wrap items-end">
  51. <h1 class="line-clamp-1 w-full text-base text-black-3 font-semibold mb-4">系统消息</h1>
  52. <p class="line-clamp-1 h-20 text-sm text-black-6 leading-3xl">
  53. 你吃饭了么wwwwwdasdasdasdwwwwwwwwwwwwwwwwwwwwwwwssssssssssssssssssssssssssssss
  54. </p>
  55. </div>
  56. <div class="w-35 h-48 shrink-0">
  57. <p class="text-black/[0.6] text-sm text-end">02:06</p>
  58. </div>
  59. <div class="absolute bottom-0 right-0 w-[96%] h-1 border-b-[1px]"></div>
  60. </div>
  61. <div
  62. @click="onChatPage('/', {})"
  63. class="w-full relative h-82 flex justify-start items-center px-16"
  64. >
  65. <van-badge v-if="messagesNumber > 0" v-bind="messageNumber(messagesNumber)" max="99">
  66. <div
  67. class="w-48 h-48 bg-[#FF9300] rounded-full overflow-hidden flex justify-center items-center"
  68. >
  69. <img class="w-24 h-24 shrink-0 object-cover" src="~/assets/img/chat/user.svg" alt="" />
  70. </div>
  71. </van-badge>
  72. <div
  73. v-else
  74. class="w-48 h-48 bg-[#0052D9] rounded-full overflow-hidden flex justify-center items-center"
  75. >
  76. <img class="w-24 h-24 shrink-0 object-cover" src="~/assets/img/chat/user.svg" alt="" />
  77. </div>
  78. <div class="h-48 w-245 shrink-0 ml-12 flex flex-wrap items-end">
  79. <h1 class="line-clamp-1 w-full text-base text-black-3 font-semibold mb-4">新增粉丝</h1>
  80. <p class="line-clamp-1 h-20 text-sm text-black-6 leading-3xl">
  81. 你吃饭了么wwwwwdasdasdasdwwwwwwwwwwwwwwwwwwwwwwwssssssssssssssssssssssssssssss
  82. </p>
  83. </div>
  84. <div class="w-35 h-48 shrink-0">
  85. <p class="text-black/[0.6] text-sm text-end">02:06</p>
  86. </div>
  87. <div class="absolute bottom-0 right-0 w-[96%] h-1 border-b-[1px]"></div>
  88. </div>
  89. <div
  90. @click="onChatPage('/profile/interaction-message', {})"
  91. class="w-full relative h-82 flex justify-start items-center px-16"
  92. >
  93. <van-badge v-if="messagesNumber > 0" v-bind="messageNumber(messagesNumber)" max="99">
  94. <div
  95. class="w-48 h-48 bg-[#FF9300] rounded-full overflow-hidden flex justify-center items-center"
  96. >
  97. <img class="w-24 h-24 shrink-0 object-cover" src="~/assets/img/chat/user.svg" alt="" />
  98. </div>
  99. </van-badge>
  100. <div
  101. v-else
  102. class="w-48 h-48 bg-[#0052D9] rounded-full overflow-hidden flex justify-center items-center"
  103. >
  104. <img class="w-24 h-24 shrink-0 object-cover" src="~/assets/img/chat/user.svg" alt="" />
  105. </div>
  106. <div class="h-48 w-245 shrink-0 ml-12 flex flex-wrap items-end">
  107. <h1 class="line-clamp-1 w-full text-base text-black-3 font-semibold mb-4">互动消息</h1>
  108. <p class="line-clamp-1 h-20 text-sm text-black-6 leading-3xl">收藏了你的游记</p>
  109. </div>
  110. <div class="w-35 h-48 shrink-0">
  111. <p class="text-black/[0.6] text-sm text-end">02:06</p>
  112. </div>
  113. <div class="absolute bottom-0 right-0 w-[96%] h-1 border-b-[1px]"></div>
  114. </div>
  115. <!-- 置顶绘画列表 -->
  116. <div v-if="activeNames" class="w-full">
  117. <template v-for="(item, index) in pinnedList" :key="index">
  118. <ProfileNewsGroupChat
  119. :item-data="{ title: item }"
  120. @on-chat-page="
  121. onChatPage('/chat/group', { userId: userInfo.userId, groupId: '1877542109622431746' })
  122. "
  123. @on-no-bother="noBother(item)"
  124. @on-conv-delete="convDelete()"
  125. />
  126. </template>
  127. </div>
  128. <div
  129. v-if="pinnedList.length >= 7"
  130. @click="activeNames = !activeNames"
  131. class="flex justify-between border items-center h-20 w-full p-16 box-border"
  132. >
  133. <div class="shrink-0 flex items-center">
  134. <van-icon name="bars" size="16" class="mr-5" />
  135. <span class="text-sm">{{ collapseTitle }}</span>
  136. </div>
  137. <div class="w-16 h-16 shrink-0">
  138. <van-icon name="arrow" size="16" />
  139. <!-- <img class="w-full h-full object-cover" src="" alt="" /> -->
  140. </div>
  141. </div>
  142. <ProfileNewsGroupChat
  143. @on-chat-page="onChatPage('/chat/group', { userId: userInfo.userId, groupId: 111 })"
  144. @on-no-bother="noBother()"
  145. @on-conv-delete="convDelete()"
  146. />
  147. <ProfileNewsSingleChat
  148. @on-chat-page="onChatPage('/chat/single', { userId: userInfo.userId, singleId: '2' })"
  149. @on-no-bother="noBother()"
  150. @on-conv-delete="convDelete()"
  151. />
  152. </van-pull-refresh>
  153. </div>
  154. </template>
  155. <script setup>
  156. import comments from '~/assets/img/chat/comments-white.svg'
  157. import plaza from '~/assets/img/chat/guangchang.svg'
  158. import userAdd from '~/assets/img/chat/user-add.svg'
  159. const actionsList = [
  160. { text: '创建群聊', icon: comments },
  161. { text: '群聊广场', icon: plaza },
  162. { text: '加入群聊', icon: plaza },
  163. { text: '添加用户', icon: userAdd }
  164. ]
  165. const chatStore = useChatStore()
  166. const userInfoStore = useUserInfoStore()
  167. const { userInfo } = storeToRefs(userInfoStore)
  168. onMounted(() => {
  169. userInfoStore.getUserInfo()
  170. })
  171. useSeoMeta({
  172. title: '我的消息'
  173. })
  174. // 获取连接状态
  175. const isConnected = computed(() => chatStore.isConnected)
  176. // 连接 WebSocket
  177. const connectSocket = () => {
  178. chatStore.connect(`?userId=${userInfo.value.userId}`)
  179. }
  180. // 发送测试消息
  181. const sendTestMessage = () => {
  182. chatStore.sendMessage({ message: 'Hello WebSocket!' })
  183. }
  184. // 断开 WebSocket
  185. const disconnectSocket = () => {
  186. chatStore.disconnect()
  187. }
  188. // 消息历史
  189. const messages = computed(() => chatStore.wsService.value?.messages || [])
  190. const finished = ref(false)
  191. const error = ref(false)
  192. const loading = ref(false)
  193. const showPopover = ref(false)
  194. const messagesNumber = ref(10)
  195. // 置顶列表
  196. const pinnedList = ref([1, 2, 3, 4, 5, 6, 7])
  197. // 个置顶聊天
  198. const collapse_text = '折叠置顶聊天'
  199. const activeNames = ref(true)
  200. // collapse
  201. const collapseTitle = ref(collapse_text)
  202. // 刷新
  203. const refreshing = ref(false)
  204. // 下拉刷新
  205. const onRefresh = () => {
  206. refreshing.value = true
  207. // getVisaOrderList()
  208. }
  209. // 打扰和免打扰得
  210. const noBother = (parmas) => {
  211. if (parmas?.bother == false) {
  212. parmas.bother = true
  213. } else {
  214. parmas.bother = false
  215. }
  216. }
  217. // 会话的删除
  218. const convDelete = (parmas) => {}
  219. // 消息数量通知的展示 需要动态的展示
  220. const messageNumber = (content) => {
  221. let messageNumberObj = {}
  222. if (content <= 1) {
  223. messageNumberObj = {
  224. offset: [-5, 4],
  225. dot: true,
  226. content
  227. }
  228. }
  229. if (content > 1) {
  230. messageNumberObj = {
  231. offset: [-10, 7],
  232. content
  233. }
  234. }
  235. return messageNumberObj
  236. }
  237. // 跳转聊天页面
  238. const onChatPage = (path, query) => {
  239. navigateTo({
  240. path,
  241. query
  242. })
  243. }
  244. // 选中的是那个页面
  245. const onSelect = (action) => {
  246. if (action.text == '创建群聊') onChatPage('/chat/create-group', {})
  247. if (action.text == '群聊广场') onChatPage('/chat/group-square', {})
  248. if (action.text == '加入群聊') onChatPage('/chat/sweep', {})
  249. if (action.text == '添加用户') onChatPage('/chat/user-add', {})
  250. }
  251. async function getList() {
  252. try {
  253. let {
  254. data: { dataList }
  255. } = await request('/website/tourism/fans/getTourMemberList')
  256. } catch (error) {}
  257. }
  258. onMounted(() => {
  259. getList()
  260. })
  261. </script>
  262. <style lang="scss" scoped></style>