send-other.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
  3. <view>
  4. <cu-custom bgImage="/static/bg.png" :isBack="true">
  5. <template v-slot:content>
  6. <text class="text-black">消息转发</text>
  7. </template>
  8. </cu-custom>
  9. <scroll-view scroll-x style="margin: 30upx 20upx;white-space: nowrap;">
  10. <user-avatar style="width: 168upx" @tap="sendHandle(chat.id,chat.type)" v-for="(chat, index) in chatStore.chats" :key="index" :chat="chat"/>
  11. </scroll-view>
  12. <index-bar :index-map="map">
  13. <view v-for="(item,key) in map.keys()" :key="key">
  14. <view :class="'indexItem-' + item" :id="'indexes-' + item" :data-index="item">
  15. <view class="padding">{{ item }}</view>
  16. <view class="cu-list menu-avatar no-padding">
  17. <view class="cu-item" v-for="(item) in map.get(item)" :key="item.id"
  18. :data-target="'move-box-' + item.id" @tap="sendHandle(item.id,item.type)">
  19. <image class="cu-avatar radius lg" :src="item.avatar"></image>
  20. <view class="content">
  21. <view class="text-grey">{{ item.name }}</view>
  22. <view class="text-gray text-sm">
  23. {{ item.name }}
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </index-bar>
  31. </view>
  32. </template>
  33. <script setup lang="ts">
  34. import {ref} from "vue";
  35. import FriendApi from "@/api/FriendApi";
  36. import Tools from "@/utils/Tools";
  37. import CuCustom from '@/colorui/components/cu-custom.vue'
  38. import UserAvatar from '@/components/UserAvatar.vue'
  39. import {useChatStore} from "@/store/chatStore";
  40. import {useUserStore} from "@/store/userStore";
  41. import type Message from "@/mode/Message";
  42. import ChatType from "@/utils/ChatType";
  43. import type ChatSimple from "@/mode/ChatSimple";
  44. import type User from "@/mode/User";
  45. import GroupApi from "@/api/GroupApi";
  46. import type Group from "@/mode/Group";
  47. import IndexBar from '@/components/IndexBar.vue'
  48. import {useWsStore} from "@/store/WsStore";
  49. import MessageUtils from "@/utils/MessageUtils";
  50. import {useMessageStore} from "@/store/messageStore";
  51. import {storeToRefs} from "pinia";
  52. import {onLoad} from "@dcloudio/uni-app";
  53. import MessageType from "@/utils/MessageType";
  54. import Auth from "@/api/Auth";
  55. const fontValue=ref(Auth.getfontSize());
  56. const chatStore = useChatStore();
  57. const userStore = useUserStore();
  58. const messageStore = useMessageStore();
  59. const currentUser = userStore.getUser();
  60. const map = ref(new Map());
  61. const hidden = ref(true);
  62. const multiple = ref(false);
  63. const wsStore = useWsStore();
  64. const {checkList} = storeToRefs(useMessageStore())
  65. //可以转发的对象
  66. const items = ref<ChatSimple[]>([]);
  67. onLoad((opt) => {
  68. console.log(opt)
  69. console.log(opt?.multiple)
  70. console.log(typeof opt?.multiple)
  71. if (opt?.multiple === 'true') {
  72. multiple.value = true;
  73. }
  74. });
  75. const loadData = () => {
  76. FriendApi.friends().then((res) => {
  77. items.value = res.data.map((item: User) => {
  78. return {id: item.id, name: item.name, avatar: item.avatar, type: ChatType.FRIEND,}
  79. })
  80. return GroupApi.list()
  81. }).then((res) => {
  82. items.value.push(...res.data.map((item: Group) => {
  83. return {id: item.id, name: item.name, avatar: item.avatar, type: ChatType.GROUP,}
  84. }))
  85. map.value = Tools.listToMap(items.value);
  86. });
  87. };
  88. const sendHandle = (id: string, type: string) => {
  89. if (currentUser) {
  90. if (!multiple.value) {
  91. checkList.value.forEach((message: Message) => {
  92. let msg: Message = {
  93. messageType: message.messageType,
  94. chatId: id,
  95. fromId: currentUser.id,
  96. content: message.content,
  97. type: type,
  98. extend: message.extend
  99. };
  100. wsStore.sendMessage(msg);
  101. })
  102. messageStore.setCheckList([])
  103. messageStore.setShowMultipleCheck(false)
  104. MessageUtils.message('已经转发')
  105. uni.navigateBack()
  106. }else {
  107. const message0 = checkList.value[0]
  108. const fromId = message0?.fromId
  109. const toId = message0?.chatId
  110. let showName = '群聊'
  111. if(message0.type === ChatType.FRIEND && fromId && toId){
  112. showName = userStore.getMapUser(fromId)?.name + '和' + userStore.getMapUser(toId)?.name
  113. }
  114. //按照id排序checkList.value
  115. checkList.value.sort((a, b) => a!.id - b!.id)
  116. const message: Message = {
  117. messageType: MessageType.forward,
  118. content: `${showName}的聊天记录`,
  119. chatId: id,
  120. fromId: currentUser.id,
  121. type: type,
  122. mine: false,
  123. timestamp: new Date().getTime(),
  124. extend: {
  125. messageList: checkList.value
  126. }
  127. }
  128. wsStore.sendMessage(message)
  129. messageStore.setCheckList([])
  130. messageStore.setShowMultipleCheck(false)
  131. MessageUtils.message('已经转发')
  132. uni.navigateBack()
  133. }
  134. }
  135. };
  136. loadData();
  137. </script>
  138. <style scoped></style>